Add focused method to pane_grid::State

This commit is contained in:
Héctor Ramón Jiménez 2020-07-22 02:58:14 +02:00
parent 021b173ef3
commit 35b1b8b0e7

View File

@ -122,6 +122,14 @@ impl<T> State<T> {
&self.internal.layout &self.internal.layout
} }
/// Returns the focused [`Pane`] of the [`State`], if there is one.
///
/// [`Pane`]: struct.Pane.html
/// [`State`]: struct.State.html
pub fn focused(&self) -> Option<Pane> {
self.internal.focused_pane()
}
/// Returns the active [`Pane`] of the [`State`], if there is one. /// Returns the active [`Pane`] of the [`State`], if there is one.
/// ///
/// A [`Pane`] is active if it is focused and is __not__ being dragged. /// A [`Pane`] is active if it is focused and is __not__ being dragged.
@ -351,6 +359,14 @@ impl Internal {
self.action self.action
} }
pub fn focused_pane(&self) -> Option<Pane> {
match self.action {
Action::Idle { focus } => focus,
Action::Dragging { pane, .. } => Some(pane),
Action::Resizing { focus, .. } => focus,
}
}
pub fn active_pane(&self) -> Option<Pane> { pub fn active_pane(&self) -> Option<Pane> {
match self.action { match self.action {
Action::Idle { focus } => focus, Action::Idle { focus } => focus,