summaryrefslogtreecommitdiffstats
path: root/native/src/widget/pane_grid/node.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector0193@gmail.com>2020-07-01 22:44:37 +0200
committerLibravatar GitHub <noreply@github.com>2020-07-01 22:44:37 +0200
commit99a50d6b2ff2c54c276d3a142071bd77ac38e4f0 (patch)
tree0f8eca7533cf6eef8fdf0661fe2c0c4fe83f9243 /native/src/widget/pane_grid/node.rs
parent79aa225001dda0efc7b9d8301641a4806f259960 (diff)
parente50c61f7ff8c7bd559afb66025eaded78ca423bb (diff)
downloadiced-99a50d6b2ff2c54c276d3a142071bd77ac38e4f0.tar.gz
iced-99a50d6b2ff2c54c276d3a142071bd77ac38e4f0.tar.bz2
iced-99a50d6b2ff2c54c276d3a142071bd77ac38e4f0.zip
Merge pull request #431 from hecrj/feature/pane-grid-splits
Splits iterator for `PaneGrid` and minor improvements
Diffstat (limited to 'native/src/widget/pane_grid/node.rs')
-rw-r--r--native/src/widget/pane_grid/node.rs28
1 files changed, 26 insertions, 2 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,