From b761ab5e1d4ceaae6ac12c28f45dfcd84c76c329 Mon Sep 17 00:00:00 2001 From: Cory Forsstrom Date: Wed, 2 Nov 2022 16:49:18 -0700 Subject: Add maximize / restore to PaneGrid --- native/src/widget/pane_grid/state.rs | 54 +++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 23 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 cdca6267..92d26f5a 100644 --- a/native/src/widget/pane_grid/state.rs +++ b/native/src/widget/pane_grid/state.rs @@ -4,9 +4,9 @@ use crate::widget::pane_grid::{ Axis, Configuration, Direction, Node, Pane, Split, }; -use crate::{Point, Rectangle, Size}; +use crate::{Point, Size}; -use std::collections::{BTreeMap, HashMap}; +use std::collections::HashMap; /// The state of a [`PaneGrid`]. /// @@ -31,6 +31,9 @@ pub struct State { /// /// [`PaneGrid`]: crate::widget::PaneGrid pub internal: Internal, + + /// The maximized [`Pane`] of the [`PaneGrid`] + pub(super) maximized: Option, } impl State { @@ -52,7 +55,11 @@ impl State { let internal = Internal::from_configuration(&mut panes, config.into(), 0); - State { panes, internal } + State { + panes, + internal, + maximized: None, + } } /// Returns the total amount of panes in the [`State`]. @@ -194,12 +201,28 @@ impl State { /// Closes the given [`Pane`] and returns its internal state and its closest /// sibling, if it exists. pub fn close(&mut self, pane: &Pane) -> Option<(T, Pane)> { + if self.maximized == Some(*pane) { + let _ = self.maximized.take(); + } + if let Some(sibling) = self.internal.layout.remove(pane) { self.panes.remove(pane).map(|state| (state, sibling)) } else { None } } + + /// Maximize the given [`Pane`]. Only this pane will be rendered by the + /// [`PaneGrid`] until [`Self::restore()`] is called. + pub fn maximize(&mut self, pane: &Pane) { + self.maximized = Some(*pane); + } + + /// Restore the currently maximized [`Pane`] to it's normal size. All panes + /// will be rendered by the [`PaneGrid`] + pub fn restore(&mut self) { + let _ = self.maximized.take(); + } } /// The internal state of a [`PaneGrid`]. @@ -226,11 +249,13 @@ impl Internal { let Internal { layout: a, last_id: next_id, + .. } = Self::from_configuration(panes, *a, next_id); let Internal { layout: b, last_id: next_id, + .. } = Self::from_configuration(panes, *b, next_id); ( @@ -304,25 +329,8 @@ impl Action { } impl Internal { - /// Calculates the current [`Pane`] regions from the [`PaneGrid`] layout. - /// - /// [`PaneGrid`]: crate::widget::PaneGrid - pub fn pane_regions( - &self, - spacing: f32, - size: Size, - ) -> BTreeMap { - self.layout.pane_regions(spacing, size) - } - - /// Calculates the current [`Split`] regions from the [`PaneGrid`] layout. - /// - /// [`PaneGrid`]: crate::widget::PaneGrid - pub fn split_regions( - &self, - spacing: f32, - size: Size, - ) -> BTreeMap { - self.layout.split_regions(spacing, size) + /// The layout [`Node`] of the [`Internal`] state + pub fn layout(&self) -> &Node { + &self.layout } } -- cgit From 988515d57f8c67a22ca0554f3e1327b26e5c6ecf Mon Sep 17 00:00:00 2001 From: tarkah Date: Wed, 2 Nov 2022 19:25:27 -0700 Subject: Add state::Scoped & rename Elements as Contents --- native/src/widget/pane_grid/state.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 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 92d26f5a..b5bebc2e 100644 --- a/native/src/widget/pane_grid/state.rs +++ b/native/src/widget/pane_grid/state.rs @@ -281,6 +281,15 @@ impl Internal { } } +/// The scoped internal state of the [`PaneGrid`] +#[derive(Debug)] +pub enum Scoped<'a> { + /// The state when all panes are visible + All(&'a Internal), + /// The state when a pane is maximized + Maximized(Node), +} + /// The current action of a [`PaneGrid`]. /// /// [`PaneGrid`]: crate::widget::PaneGrid @@ -328,9 +337,12 @@ impl Action { } } -impl Internal { - /// The layout [`Node`] of the [`Internal`] state +impl<'a> Scoped<'a> { + /// The layout [`Node`] of the [`Scope`] state pub fn layout(&self) -> &Node { - &self.layout + match self { + Scoped::All(Internal { layout, .. }) => layout, + Scoped::Maximized(layout) => layout, + } } } -- cgit From 2f6c71d99a2c739c8b86bdf9d024e83ae994042d Mon Sep 17 00:00:00 2001 From: tarkah Date: Wed, 2 Nov 2022 19:54:49 -0700 Subject: Fix doc links --- native/src/widget/pane_grid/state.rs | 10 ++++++++-- 1 file changed, 8 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 b5bebc2e..70a2aa88 100644 --- a/native/src/widget/pane_grid/state.rs +++ b/native/src/widget/pane_grid/state.rs @@ -214,12 +214,16 @@ impl State { /// Maximize the given [`Pane`]. Only this pane will be rendered by the /// [`PaneGrid`] until [`Self::restore()`] is called. + /// + /// [`PaneGrid`]: crate::widget::PaneGrid pub fn maximize(&mut self, pane: &Pane) { self.maximized = Some(*pane); } /// Restore the currently maximized [`Pane`] to it's normal size. All panes - /// will be rendered by the [`PaneGrid`] + /// will be rendered by the [`PaneGrid`]. + /// + /// [`PaneGrid`]: crate::widget::PaneGrid pub fn restore(&mut self) { let _ = self.maximized.take(); } @@ -282,6 +286,8 @@ impl Internal { } /// The scoped internal state of the [`PaneGrid`] +/// +/// [`PaneGrid`]: crate::widget::PaneGrid #[derive(Debug)] pub enum Scoped<'a> { /// The state when all panes are visible @@ -338,7 +344,7 @@ impl Action { } impl<'a> Scoped<'a> { - /// The layout [`Node`] of the [`Scope`] state + /// The layout [`Node`] of the [`Scoped`] state pub fn layout(&self) -> &Node { match self { Scoped::All(Internal { layout, .. }) => layout, -- cgit From 951fbc83ff8878be03eb6c8c43f2a28d0f0f0d4c Mon Sep 17 00:00:00 2001 From: Cory Forsstrom Date: Thu, 3 Nov 2022 08:02:20 -0700 Subject: Remove maximized when split occurs --- native/src/widget/pane_grid/state.rs | 1 + 1 file changed, 1 insertion(+) (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 70a2aa88..882a45f2 100644 --- a/native/src/widget/pane_grid/state.rs +++ b/native/src/widget/pane_grid/state.rs @@ -160,6 +160,7 @@ impl State { node.split(new_split, axis, new_pane); let _ = self.panes.insert(new_pane, state); + let _ = self.maximized.take(); Some((new_pane, new_split)) } -- cgit From 853ff4bcf4eff24808c680f9a35bfc0013cb779d Mon Sep 17 00:00:00 2001 From: Cory Forsstrom Date: Thu, 3 Nov 2022 11:32:36 -0700 Subject: Add pub method for getting maximized value --- 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 882a45f2..c9e9433d 100644 --- a/native/src/widget/pane_grid/state.rs +++ b/native/src/widget/pane_grid/state.rs @@ -228,6 +228,13 @@ impl State { pub fn restore(&mut self) { let _ = self.maximized.take(); } + + /// Returns the maximized [`Pane`] of the [`PaneGrid`]. + /// + /// [`PaneGrid`]: crate::widget::PaneGrid + pub fn maximized(&self) -> Option { + self.maximized + } } /// The internal state of a [`PaneGrid`]. -- cgit From 7de9d2475dbf4ed93c4248580514901f82a0fc0e Mon Sep 17 00:00:00 2001 From: Cory Forsstrom Date: Tue, 8 Nov 2022 08:49:26 -0800 Subject: Couple layout & content to avoid desync --- native/src/widget/pane_grid/state.rs | 20 +++----------------- 1 file changed, 3 insertions(+), 17 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 c9e9433d..58397444 100644 --- a/native/src/widget/pane_grid/state.rs +++ b/native/src/widget/pane_grid/state.rs @@ -293,17 +293,6 @@ impl Internal { } } -/// The scoped internal state of the [`PaneGrid`] -/// -/// [`PaneGrid`]: crate::widget::PaneGrid -#[derive(Debug)] -pub enum Scoped<'a> { - /// The state when all panes are visible - All(&'a Internal), - /// The state when a pane is maximized - Maximized(Node), -} - /// The current action of a [`PaneGrid`]. /// /// [`PaneGrid`]: crate::widget::PaneGrid @@ -351,12 +340,9 @@ impl Action { } } -impl<'a> Scoped<'a> { - /// The layout [`Node`] of the [`Scoped`] state +impl Internal { + /// The layout [`Node`] of the [`Internal`] state pub fn layout(&self) -> &Node { - match self { - Scoped::All(Internal { layout, .. }) => layout, - Scoped::Maximized(layout) => layout, - } + &self.layout } } -- cgit From 1480ab20306e463b69b2229dcd5e81d4c66b2a64 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 10 Nov 2022 00:10:53 +0100 Subject: Fix broken documentation links --- native/src/widget/pane_grid/state.rs | 4 +++- 1 file changed, 3 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 58397444..c4ae0a0e 100644 --- a/native/src/widget/pane_grid/state.rs +++ b/native/src/widget/pane_grid/state.rs @@ -32,7 +32,9 @@ pub struct State { /// [`PaneGrid`]: crate::widget::PaneGrid pub internal: Internal, - /// The maximized [`Pane`] of the [`PaneGrid`] + /// The maximized [`Pane`] of the [`PaneGrid`]. + /// + /// [`PaneGrid`]: crate::widget::PaneGrid pub(super) maximized: Option, } -- cgit