diff options
author | 2020-07-08 11:44:40 +0200 | |
---|---|---|
committer | 2020-07-08 11:44:40 +0200 | |
commit | f3dfaa2c43bad16fc91660b2b73cb9173549e7ec (patch) | |
tree | 353365f4dd1e3136bc651ac8c1572f62fff1304b /native/src/widget/pane_grid | |
parent | 072ec69d53d2708d8fd1693151bcec7305efccf8 (diff) | |
parent | 5c4f5ae5ecb36703a95cafb2cd58692529c9466d (diff) | |
download | iced-f3dfaa2c43bad16fc91660b2b73cb9173549e7ec.tar.gz iced-f3dfaa2c43bad16fc91660b2b73cb9173549e7ec.tar.bz2 iced-f3dfaa2c43bad16fc91660b2b73cb9173549e7ec.zip |
Merge branch 'master' into feature/pane-grid-titlebar
Diffstat (limited to 'native/src/widget/pane_grid')
-rw-r--r-- | native/src/widget/pane_grid/node.rs | 28 | ||||
-rw-r--r-- | native/src/widget/pane_grid/state.rs | 21 |
2 files changed, 41 insertions, 8 deletions
diff --git a/native/src/widget/pane_grid/node.rs b/native/src/widget/pane_grid/node.rs index b13c5e26..cbfd8a43 100644 --- a/native/src/widget/pane_grid/node.rs +++ b/native/src/widget/pane_grid/node.rs @@ -43,12 +43,36 @@ pub enum Node { } impl Node { + /// Returns an iterator over each [`Split`] in this [`Node`]. + /// + /// [`Split`]: struct.Split.html + /// [`Node`]: enum.Node.html + pub fn splits(&self) -> impl Iterator<Item = &Split> { + let mut unvisited_nodes = vec![self]; + + std::iter::from_fn(move || { + while let Some(node) = unvisited_nodes.pop() { + match node { + Node::Split { id, a, b, .. } => { + unvisited_nodes.push(a); + unvisited_nodes.push(b); + + return Some(id); + } + _ => {} + } + } + + None + }) + } + /// Returns the rectangular region for each [`Pane`] in the [`Node`] given /// the spacing between panes and the total available space. /// /// [`Pane`]: struct.Pane.html /// [`Node`]: enum.Node.html - pub fn regions( + pub fn pane_regions( &self, spacing: f32, size: Size, @@ -75,7 +99,7 @@ impl Node { /// /// [`Split`]: struct.Split.html /// [`Node`]: enum.Node.html - pub fn splits( + pub fn split_regions( &self, spacing: f32, size: Size, diff --git a/native/src/widget/pane_grid/state.rs b/native/src/widget/pane_grid/state.rs index a8431dec..3f0accc1 100644 --- a/native/src/widget/pane_grid/state.rs +++ b/native/src/widget/pane_grid/state.rs @@ -157,8 +157,10 @@ impl<T> State<T> { /// [`Pane`]: struct.Pane.html /// [`State::active`]: struct.State.html#method.active pub fn adjacent(&self, pane: &Pane, direction: Direction) -> Option<Pane> { - let regions = - self.internal.layout.regions(0.0, Size::new(4096.0, 4096.0)); + let regions = self + .internal + .layout + .pane_regions(0.0, Size::new(4096.0, 4096.0)); let current_region = regions.get(pane)?; @@ -194,6 +196,13 @@ impl<T> State<T> { self.internal.focus(pane); } + /// Unfocuses the current focused [`Pane`]. + /// + /// [`Pane`]: struct.Pane.html + pub fn unfocus(&mut self) { + self.internal.unfocus(); + } + /// Splits the given [`Pane`] into two in the given [`Axis`] and /// initializing the new [`Pane`] with the provided internal state. /// @@ -366,20 +375,20 @@ impl Internal { } } - pub fn regions( + pub fn pane_regions( &self, spacing: f32, size: Size, ) -> HashMap<Pane, Rectangle> { - self.layout.regions(spacing, size) + self.layout.pane_regions(spacing, size) } - pub fn splits( + pub fn split_regions( &self, spacing: f32, size: Size, ) -> HashMap<Split, (Axis, Rectangle, f32)> { - self.layout.splits(spacing, size) + self.layout.split_regions(spacing, size) } pub fn focus(&mut self, pane: &Pane) { |