From 5c8ec4504b6541cdc588b91a6b2c7100b4a7cc77 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 14 Mar 2020 05:26:59 +0100 Subject: Create module boundaries for `pane_grid` logic --- native/src/widget/pane_grid/state.rs | 227 +++++++++++++++++++++++++++++++++++ 1 file changed, 227 insertions(+) create mode 100644 native/src/widget/pane_grid/state.rs (limited to 'native/src/widget/pane_grid/state.rs') diff --git a/native/src/widget/pane_grid/state.rs b/native/src/widget/pane_grid/state.rs new file mode 100644 index 00000000..130c7e34 --- /dev/null +++ b/native/src/widget/pane_grid/state.rs @@ -0,0 +1,227 @@ +use crate::{ + input::keyboard, + pane_grid::{node::Node, Direction, Pane, Split}, + Hasher, Point, Rectangle, Size, +}; + +use std::collections::HashMap; + +#[derive(Debug)] +pub struct State { + pub(super) panes: HashMap, + pub(super) internal: Internal, + pub(super) modifiers: keyboard::ModifiersState, +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum Focus { + Idle, + Dragging, +} + +impl State { + pub fn new(first_pane_state: T) -> (Self, Pane) { + let first_pane = Pane(0); + + let mut panes = HashMap::new(); + let _ = panes.insert(first_pane, first_pane_state); + + ( + State { + panes, + internal: Internal { + layout: Node::Pane(first_pane), + last_pane: 0, + focused_pane: FocusedPane::None, + }, + modifiers: keyboard::ModifiersState::default(), + }, + first_pane, + ) + } + + pub fn len(&self) -> usize { + self.panes.len() + } + + pub fn get_mut(&mut self, pane: &Pane) -> Option<&mut T> { + self.panes.get_mut(pane) + } + + pub fn iter(&self) -> impl Iterator { + self.panes.iter() + } + + pub fn iter_mut(&mut self) -> impl Iterator { + self.panes.iter_mut() + } + + pub fn focused_pane(&self) -> Option { + match self.internal.focused_pane { + FocusedPane::Some { + pane, + focus: Focus::Idle, + } => Some(pane), + FocusedPane::Some { + focus: Focus::Dragging, + .. + } => None, + FocusedPane::None => None, + } + } + + pub fn adjacent_pane( + &self, + pane: &Pane, + direction: Direction, + ) -> Option { + let regions = + self.internal.layout.regions(0.0, Size::new(4096.0, 4096.0)); + + let current_region = regions.get(pane)?; + + let target = match direction { + Direction::Left => { + Point::new(current_region.x - 1.0, current_region.y + 1.0) + } + Direction::Right => Point::new( + current_region.x + current_region.width + 1.0, + current_region.y + 1.0, + ), + Direction::Up => { + Point::new(current_region.x + 1.0, current_region.y - 1.0) + } + Direction::Down => Point::new( + current_region.x + 1.0, + current_region.y + current_region.height + 1.0, + ), + }; + + let mut colliding_regions = + regions.iter().filter(|(_, region)| region.contains(target)); + + let (pane, _) = colliding_regions.next()?; + + Some(*pane) + } + + pub fn focus(&mut self, pane: &Pane) { + self.internal.focus(pane); + } + + pub fn split_vertically(&mut self, pane: &Pane, state: T) -> Option { + self.split(Split::Vertical, pane, state) + } + + pub fn split_horizontally( + &mut self, + pane: &Pane, + state: T, + ) -> Option { + self.split(Split::Horizontal, pane, state) + } + + pub fn split( + &mut self, + kind: Split, + pane: &Pane, + state: T, + ) -> Option { + let node = self.internal.layout.find(pane)?; + + let new_pane = { + self.internal.last_pane = self.internal.last_pane.checked_add(1)?; + + Pane(self.internal.last_pane) + }; + + node.split(kind, new_pane); + + let _ = self.panes.insert(new_pane, state); + self.focus(&new_pane); + + Some(new_pane) + } + + pub fn swap(&mut self, a: &Pane, b: &Pane) { + self.internal.layout.update(&|node| match node { + Node::Split { .. } => {} + Node::Pane(pane) => { + if pane == a { + *node = Node::Pane(*b); + } else if pane == b { + *node = Node::Pane(*a); + } + } + }); + } + + pub fn close(&mut self, pane: &Pane) -> Option { + if let Some(sibling) = self.internal.layout.remove(pane) { + self.focus(&sibling); + self.panes.remove(pane) + } else { + None + } + } +} + +#[derive(Debug)] +pub struct Internal { + layout: Node, + last_pane: usize, + focused_pane: FocusedPane, +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum FocusedPane { + None, + Some { pane: Pane, focus: Focus }, +} + +impl Internal { + pub fn focused(&self) -> FocusedPane { + self.focused_pane + } + pub fn dragged(&self) -> Option { + match self.focused_pane { + FocusedPane::Some { + pane, + focus: Focus::Dragging, + } => Some(pane), + _ => None, + } + } + + pub fn regions( + &self, + spacing: f32, + size: Size, + ) -> HashMap { + self.layout.regions(spacing, size) + } + + pub fn focus(&mut self, pane: &Pane) { + self.focused_pane = FocusedPane::Some { + pane: *pane, + focus: Focus::Idle, + }; + } + + pub fn drag(&mut self, pane: &Pane) { + self.focused_pane = FocusedPane::Some { + pane: *pane, + focus: Focus::Dragging, + }; + } + + pub fn unfocus(&mut self) { + self.focused_pane = FocusedPane::None; + } + + pub fn hash_layout(&self, hasher: &mut Hasher) { + use std::hash::Hash; + + self.layout.hash(hasher); + } +} -- cgit From 00c2b55b569ea2ff2fc9de9bbf02475c6ede7e42 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 14 Mar 2020 06:26:09 +0100 Subject: Replace `FocusedPane` with `Action` in `pane_grid` --- native/src/widget/pane_grid/state.rs | 80 +++++++++++++++++------------------- 1 file changed, 38 insertions(+), 42 deletions(-) (limited to 'native/src/widget/pane_grid/state.rs') diff --git a/native/src/widget/pane_grid/state.rs b/native/src/widget/pane_grid/state.rs index 130c7e34..61576a29 100644 --- a/native/src/widget/pane_grid/state.rs +++ b/native/src/widget/pane_grid/state.rs @@ -31,8 +31,8 @@ impl State { panes, internal: Internal { layout: Node::Pane(first_pane), - last_pane: 0, - focused_pane: FocusedPane::None, + last_id: 0, + action: Action::Idle { focus: None }, }, modifiers: keyboard::ModifiersState::default(), }, @@ -56,25 +56,14 @@ impl State { self.panes.iter_mut() } - pub fn focused_pane(&self) -> Option { - match self.internal.focused_pane { - FocusedPane::Some { - pane, - focus: Focus::Idle, - } => Some(pane), - FocusedPane::Some { - focus: Focus::Dragging, - .. - } => None, - FocusedPane::None => None, + pub fn active(&self) -> Option { + match self.internal.action { + Action::Idle { focus } => focus, + _ => None, } } - pub fn adjacent_pane( - &self, - pane: &Pane, - direction: Direction, - ) -> Option { + pub fn adjacent(&self, pane: &Pane, direction: Direction) -> Option { let regions = self.internal.layout.regions(0.0, Size::new(4096.0, 4096.0)); @@ -130,12 +119,18 @@ impl State { let node = self.internal.layout.find(pane)?; let new_pane = { - self.internal.last_pane = self.internal.last_pane.checked_add(1)?; + self.internal.last_id = self.internal.last_id.checked_add(1)?; + + Pane(self.internal.last_id) + }; + + let split_id = { + self.internal.last_id = self.internal.last_id.checked_add(1)?; - Pane(self.internal.last_pane) + self.internal.last_id }; - node.split(kind, new_pane); + node.split(split_id, kind, new_pane); let _ = self.panes.insert(new_pane, state); self.focus(&new_pane); @@ -169,26 +164,33 @@ impl State { #[derive(Debug)] pub struct Internal { layout: Node, - last_pane: usize, - focused_pane: FocusedPane, + last_id: usize, + action: Action, } #[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub enum FocusedPane { - None, - Some { pane: Pane, focus: Focus }, +pub enum Action { + Idle { focus: Option }, + Dragging { pane: Pane }, +} + +impl Action { + pub fn focus(&self) -> Option<(Pane, Focus)> { + match self { + Action::Idle { focus } => focus.map(|pane| (pane, Focus::Idle)), + Action::Dragging { pane } => Some((*pane, Focus::Dragging)), + } + } } impl Internal { - pub fn focused(&self) -> FocusedPane { - self.focused_pane + pub fn action(&self) -> Action { + self.action } + pub fn dragged(&self) -> Option { - match self.focused_pane { - FocusedPane::Some { - pane, - focus: Focus::Dragging, - } => Some(pane), + match self.action { + Action::Dragging { pane } => Some(pane), _ => None, } } @@ -202,21 +204,15 @@ impl Internal { } pub fn focus(&mut self, pane: &Pane) { - self.focused_pane = FocusedPane::Some { - pane: *pane, - focus: Focus::Idle, - }; + self.action = Action::Idle { focus: Some(*pane) }; } pub fn drag(&mut self, pane: &Pane) { - self.focused_pane = FocusedPane::Some { - pane: *pane, - focus: Focus::Dragging, - }; + self.action = Action::Dragging { pane: *pane }; } pub fn unfocus(&mut self) { - self.focused_pane = FocusedPane::None; + self.action = Action::Idle { focus: None }; } pub fn hash_layout(&self, hasher: &mut Hasher) { -- cgit From a79603e4ca5e0cee46a737ef0b1af5c69ddb49b6 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 14 Mar 2020 06:32:56 +0100 Subject: Rename `Split` to `Axis` --- native/src/widget/pane_grid/state.rs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'native/src/widget/pane_grid/state.rs') diff --git a/native/src/widget/pane_grid/state.rs b/native/src/widget/pane_grid/state.rs index 61576a29..dc66e32a 100644 --- a/native/src/widget/pane_grid/state.rs +++ b/native/src/widget/pane_grid/state.rs @@ -1,6 +1,6 @@ use crate::{ input::keyboard, - pane_grid::{node::Node, Direction, Pane, Split}, + pane_grid::{node::Node, Axis, Direction, Pane}, Hasher, Point, Rectangle, Size, }; @@ -99,7 +99,7 @@ impl State { } pub fn split_vertically(&mut self, pane: &Pane, state: T) -> Option { - self.split(Split::Vertical, pane, state) + self.split(Axis::Vertical, pane, state) } pub fn split_horizontally( @@ -107,15 +107,10 @@ impl State { pane: &Pane, state: T, ) -> Option { - self.split(Split::Horizontal, pane, state) + self.split(Axis::Horizontal, pane, state) } - pub fn split( - &mut self, - kind: Split, - pane: &Pane, - state: T, - ) -> Option { + pub fn split(&mut self, axis: Axis, pane: &Pane, state: T) -> Option { let node = self.internal.layout.find(pane)?; let new_pane = { @@ -130,7 +125,7 @@ impl State { self.internal.last_id }; - node.split(split_id, kind, new_pane); + node.split(split_id, axis, new_pane); let _ = self.panes.insert(new_pane, state); self.focus(&new_pane); -- cgit From b55746b1e1d8a5ff759c86f52063fa6ce0c02a29 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 14 Mar 2020 06:33:17 +0100 Subject: Remove `PaneGrid::split_*` helpers We can use the `split` method directly instead. --- native/src/widget/pane_grid/state.rs | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'native/src/widget/pane_grid/state.rs') diff --git a/native/src/widget/pane_grid/state.rs b/native/src/widget/pane_grid/state.rs index dc66e32a..f46252c7 100644 --- a/native/src/widget/pane_grid/state.rs +++ b/native/src/widget/pane_grid/state.rs @@ -98,18 +98,6 @@ impl State { self.internal.focus(pane); } - pub fn split_vertically(&mut self, pane: &Pane, state: T) -> Option { - self.split(Axis::Vertical, pane, state) - } - - pub fn split_horizontally( - &mut self, - pane: &Pane, - state: T, - ) -> Option { - self.split(Axis::Horizontal, pane, state) - } - pub fn split(&mut self, axis: Axis, pane: &Pane, state: T) -> Option { let node = self.internal.layout.find(pane)?; -- cgit From db441a64b18487f3f64bb4f99192548d7fac6893 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 14 Mar 2020 06:35:43 +0100 Subject: Reintroduce `pane_grid::Split` as an identifier --- native/src/widget/pane_grid/state.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'native/src/widget/pane_grid/state.rs') diff --git a/native/src/widget/pane_grid/state.rs b/native/src/widget/pane_grid/state.rs index f46252c7..b0e571f0 100644 --- a/native/src/widget/pane_grid/state.rs +++ b/native/src/widget/pane_grid/state.rs @@ -1,6 +1,6 @@ use crate::{ input::keyboard, - pane_grid::{node::Node, Axis, Direction, Pane}, + pane_grid::{node::Node, Axis, Direction, Pane, Split}, Hasher, Point, Rectangle, Size, }; @@ -107,13 +107,13 @@ impl State { Pane(self.internal.last_id) }; - let split_id = { + let new_split = { self.internal.last_id = self.internal.last_id.checked_add(1)?; - self.internal.last_id + Split(self.internal.last_id) }; - node.split(split_id, axis, new_pane); + node.split(new_split, axis, new_pane); let _ = self.panes.insert(new_pane, state); self.focus(&new_pane); -- cgit From f08cb4ad565799689d07bacc190fbe0436a63648 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 14 Mar 2020 08:10:50 +0100 Subject: Implement mouse-based pane resizing for `PaneGrid` --- native/src/widget/pane_grid/state.rs | 65 +++++++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 5 deletions(-) (limited to 'native/src/widget/pane_grid/state.rs') diff --git a/native/src/widget/pane_grid/state.rs b/native/src/widget/pane_grid/state.rs index b0e571f0..456ad78a 100644 --- a/native/src/widget/pane_grid/state.rs +++ b/native/src/widget/pane_grid/state.rs @@ -134,6 +134,10 @@ impl State { }); } + pub fn resize(&mut self, split: &Split, percentage: f32) { + let _ = self.internal.layout.resize(split, percentage); + } + pub fn close(&mut self, pane: &Pane) -> Option { if let Some(sibling) = self.internal.layout.remove(pane) { self.focus(&sibling); @@ -153,14 +157,25 @@ pub struct Internal { #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Action { - Idle { focus: Option }, - Dragging { pane: Pane }, + Idle { + focus: Option, + }, + Dragging { + pane: Pane, + }, + Resizing { + split: Split, + axis: Axis, + focus: Option, + }, } impl Action { pub fn focus(&self) -> Option<(Pane, Focus)> { match self { - Action::Idle { focus } => focus.map(|pane| (pane, Focus::Idle)), + Action::Idle { focus } | Action::Resizing { focus, .. } => { + focus.map(|pane| (pane, Focus::Idle)) + } Action::Dragging { pane } => Some((*pane, Focus::Dragging)), } } @@ -171,13 +186,20 @@ impl Internal { self.action } - pub fn dragged(&self) -> Option { + pub fn picked_pane(&self) -> Option { match self.action { Action::Dragging { pane } => Some(pane), _ => None, } } + pub fn picked_split(&self) -> Option<(Split, Axis)> { + match self.action { + Action::Resizing { split, axis, .. } => Some((split, axis)), + _ => None, + } + } + pub fn regions( &self, spacing: f32, @@ -186,14 +208,47 @@ impl Internal { self.layout.regions(spacing, size) } + pub fn splits( + &self, + spacing: f32, + size: Size, + ) -> HashMap { + self.layout.splits(spacing, size) + } + pub fn focus(&mut self, pane: &Pane) { self.action = Action::Idle { focus: Some(*pane) }; } - pub fn drag(&mut self, pane: &Pane) { + pub fn pick_pane(&mut self, pane: &Pane) { self.action = Action::Dragging { pane: *pane }; } + pub fn pick_split(&mut self, split: &Split, axis: Axis) { + // TODO: Obtain `axis` from layout itself. Maybe we should implement + // `Node::find_split` + if self.picked_pane().is_some() { + return; + } + + let focus = self.action.focus().map(|(pane, _)| pane); + + self.action = Action::Resizing { + split: *split, + axis, + focus, + }; + } + + pub fn drop_split(&mut self) { + match self.action { + Action::Resizing { focus, .. } => { + self.action = Action::Idle { focus }; + } + _ => {} + } + } + pub fn unfocus(&mut self) { self.action = Action::Idle { focus: None }; } -- cgit From a280dcda23c3c3432f12776b2fe69c4ed39cd99a Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 17 Mar 2020 06:53:57 +0100 Subject: Add `PaneGrid::on_key_press` for hotkey logic --- native/src/widget/pane_grid/state.rs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'native/src/widget/pane_grid/state.rs') diff --git a/native/src/widget/pane_grid/state.rs b/native/src/widget/pane_grid/state.rs index 456ad78a..9103dcd0 100644 --- a/native/src/widget/pane_grid/state.rs +++ b/native/src/widget/pane_grid/state.rs @@ -186,6 +186,13 @@ impl Internal { self.action } + pub fn idle_pane(&self) -> Option { + match self.action { + Action::Idle { focus } => focus, + _ => None, + } + } + pub fn picked_pane(&self) -> Option { match self.action { Action::Dragging { pane } => Some(pane), -- cgit From bd74c4e577de01b48064c7a01541ca2ad6d9ae16 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 19 Mar 2020 09:30:54 +0100 Subject: Write documentation for `pane_grid` --- native/src/widget/pane_grid/state.rs | 104 ++++++++++++++++++++++++++++++++++- 1 file changed, 102 insertions(+), 2 deletions(-) (limited to 'native/src/widget/pane_grid/state.rs') diff --git a/native/src/widget/pane_grid/state.rs b/native/src/widget/pane_grid/state.rs index 9103dcd0..6c80cacc 100644 --- a/native/src/widget/pane_grid/state.rs +++ b/native/src/widget/pane_grid/state.rs @@ -6,6 +6,20 @@ use crate::{ use std::collections::HashMap; +/// The state of a [`PaneGrid`]. +/// +/// It keeps track of the state of each [`Pane`] and the position of each +/// [`Split`]. +/// +/// The [`State`] needs to own any mutable contents a [`Pane`] may need. This is +/// why this struct is generic over the type `T`. Values of this type are +/// provided to the view function of [`PaneGrid::new`] for displaying each +/// [`Pane`]. +/// +/// [`PaneGrid`]: struct.PaneGrid.html +/// [`PaneGrid::new`]: struct.PaneGrid.html#method.new +/// [`State`]: struct.State.html +/// [`Pane`]: struct.Pane.html #[derive(Debug)] pub struct State { pub(super) panes: HashMap, @@ -13,13 +27,28 @@ pub struct State { pub(super) modifiers: keyboard::ModifiersState, } +/// The current focus of a [`Pane`]. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Focus { + /// The [`Pane`] is just focused. + /// + /// [`Pane`]: struct.Pane.html Idle, + + /// The [`Pane`] is being dragged. + /// + /// [`Pane`]: struct.Pane.html Dragging, } impl State { + /// Creates a new [`State`], initializing the first pane with the provided + /// state. + /// + /// Alongside the [`State`], it returns the first [`Pane`] identifier. + /// + /// [`State`]: struct.State.html + /// [`Pane`]: struct.Pane.html pub fn new(first_pane_state: T) -> (Self, Pane) { let first_pane = Pane(0); @@ -40,22 +69,42 @@ impl State { ) } + /// Returns the total amount of panes in the [`State`]. + /// + /// [`State`]: struct.State.html pub fn len(&self) -> usize { self.panes.len() } + /// Returns the internal state of the given [`Pane`], if it exists. + /// + /// [`Pane`]: struct.Pane.html pub fn get_mut(&mut self, pane: &Pane) -> Option<&mut T> { self.panes.get_mut(pane) } + /// Returns an iterator over all the panes of the [`State`], alongside its + /// internal state. + /// + /// [`State`]: struct.State.html pub fn iter(&self) -> impl Iterator { self.panes.iter() } + /// Returns a mutable iterator over all the panes of the [`State`], + /// alongside its internal state. + /// + /// [`State`]: struct.State.html pub fn iter_mut(&mut self) -> impl Iterator { self.panes.iter_mut() } + /// Returns the active [`Pane`] of the [`State`], if there is one. + /// + /// A [`Pane`] is active if it is focused and is __not__ being dragged. + /// + /// [`Pane`]: struct.Pane.html + /// [`State`]: struct.State.html pub fn active(&self) -> Option { match self.internal.action { Action::Idle { focus } => focus, @@ -63,6 +112,27 @@ impl State { } } + /// Returns the adjacent [`Pane`] of another [`Pane`] in the given + /// direction, if there is one. + /// + /// ## Example + /// You can combine this with [`State::active`] to find the pane that is + /// adjacent to the current active one, and then swap them. For instance: + /// + /// ``` + /// # use iced_native::pane_grid; + /// # + /// # let (mut state, _) = pane_grid::State::new(()); + /// # + /// if let Some(active) = state.active() { + /// if let Some(adjacent) = state.adjacent(&active, pane_grid::Direction::Right) { + /// state.swap(&active, &adjacent); + /// } + /// } + /// ``` + /// + /// [`Pane`]: struct.Pane.html + /// [`State::active`]: struct.State.html#method.active pub fn adjacent(&self, pane: &Pane, direction: Direction) -> Option { let regions = self.internal.layout.regions(0.0, Size::new(4096.0, 4096.0)); @@ -94,10 +164,18 @@ impl State { Some(*pane) } + /// Focuses the given [`Pane`]. + /// + /// [`Pane`]: struct.Pane.html pub fn focus(&mut self, pane: &Pane) { self.internal.focus(pane); } + /// Splits the given [`Pane`] into two in the given [`Axis`] and + /// initializing the new [`Pane`] with the provided internal state. + /// + /// [`Pane`]: struct.Pane.html + /// [`Axis`]: enum.Axis.html pub fn split(&mut self, axis: Axis, pane: &Pane, state: T) -> Option { let node = self.internal.layout.find(pane)?; @@ -121,6 +199,14 @@ impl State { Some(new_pane) } + /// Swaps the position of the provided panes in the [`State`]. + /// + /// If you want to swap panes on drag and drop in your [`PaneGrid`], you + /// will need to call this method when handling a [`DragEvent`]. + /// + /// [`State`]: struct.State.html + /// [`PaneGrid`]: struct.PaneGrid.html + /// [`DragEvent`]: struct.DragEvent.html pub fn swap(&mut self, a: &Pane, b: &Pane) { self.internal.layout.update(&|node| match node { Node::Split { .. } => {} @@ -134,10 +220,24 @@ impl State { }); } - pub fn resize(&mut self, split: &Split, percentage: f32) { - let _ = self.internal.layout.resize(split, percentage); + /// Resizes two panes by setting the position of the provided [`Split`]. + /// + /// The ratio is a value in [0, 1], representing the exact position of a + /// [`Split`] between two panes. + /// + /// If you want to enable resize interactions in your [`PaneGrid`], you will + /// need to call this method when handling a [`ResizeEvent`]. + /// + /// [`Split`]: struct.Split.html + /// [`PaneGrid`]: struct.PaneGrid.html + /// [`ResizeEvent`]: struct.ResizeEvent.html + pub fn resize(&mut self, split: &Split, ratio: f32) { + let _ = self.internal.layout.resize(split, ratio); } + /// Closes the given [`Pane`] and returns its internal state, if it exists. + /// + /// [`Pane`]: struct.Pane.html pub fn close(&mut self, pane: &Pane) -> Option { if let Some(sibling) = self.internal.layout.remove(pane) { self.focus(&sibling); -- cgit From 420275793e04b41254bacdaedd8ca60fb2ffe63f Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 19 Mar 2020 09:43:36 +0100 Subject: Fix minor documentation issues in `pane_grid` --- native/src/widget/pane_grid/state.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'native/src/widget/pane_grid/state.rs') diff --git a/native/src/widget/pane_grid/state.rs b/native/src/widget/pane_grid/state.rs index 6c80cacc..0e528d90 100644 --- a/native/src/widget/pane_grid/state.rs +++ b/native/src/widget/pane_grid/state.rs @@ -18,8 +18,9 @@ use std::collections::HashMap; /// /// [`PaneGrid`]: struct.PaneGrid.html /// [`PaneGrid::new`]: struct.PaneGrid.html#method.new -/// [`State`]: struct.State.html /// [`Pane`]: struct.Pane.html +/// [`Split`]: struct.Split.html +/// [`State`]: struct.State.html #[derive(Debug)] pub struct State { pub(super) panes: HashMap, @@ -28,6 +29,8 @@ pub struct State { } /// The current focus of a [`Pane`]. +/// +/// [`Pane`]: struct.Pane.html #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Focus { /// The [`Pane`] is just focused. -- cgit From cfc2b55e05a3dc20eae71088d0475f82e34ea36b Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 20 Mar 2020 11:54:42 +0100 Subject: Rename `Internal::idle_pane` to `active_pane` --- native/src/widget/pane_grid/state.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'native/src/widget/pane_grid/state.rs') diff --git a/native/src/widget/pane_grid/state.rs b/native/src/widget/pane_grid/state.rs index 0e528d90..0a8b8419 100644 --- a/native/src/widget/pane_grid/state.rs +++ b/native/src/widget/pane_grid/state.rs @@ -109,10 +109,7 @@ impl State { /// [`Pane`]: struct.Pane.html /// [`State`]: struct.State.html pub fn active(&self) -> Option { - match self.internal.action { - Action::Idle { focus } => focus, - _ => None, - } + self.internal.active_pane() } /// Returns the adjacent [`Pane`] of another [`Pane`] in the given @@ -289,7 +286,7 @@ impl Internal { self.action } - pub fn idle_pane(&self) -> Option { + pub fn active_pane(&self) -> Option { match self.action { Action::Idle { focus } => focus, _ => None, -- cgit