summaryrefslogtreecommitdiffstats
path: root/native/src/widget/pane_grid/state.rs
diff options
context:
space:
mode:
authorLibravatar Cory Forsstrom <cforsstrom18@gmail.com>2022-11-02 16:49:18 -0700
committerLibravatar Cory Forsstrom <cforsstrom18@gmail.com>2022-11-02 17:05:40 -0700
commitb761ab5e1d4ceaae6ac12c28f45dfcd84c76c329 (patch)
tree78341388255434e41d4071d4940939343f471877 /native/src/widget/pane_grid/state.rs
parent1c00adad615f7c2909d175c696765dbe081bde33 (diff)
downloadiced-b761ab5e1d4ceaae6ac12c28f45dfcd84c76c329.tar.gz
iced-b761ab5e1d4ceaae6ac12c28f45dfcd84c76c329.tar.bz2
iced-b761ab5e1d4ceaae6ac12c28f45dfcd84c76c329.zip
Add maximize / restore to PaneGrid
Diffstat (limited to 'native/src/widget/pane_grid/state.rs')
-rw-r--r--native/src/widget/pane_grid/state.rs54
1 files changed, 31 insertions, 23 deletions
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<T> {
///
/// [`PaneGrid`]: crate::widget::PaneGrid
pub internal: Internal,
+
+ /// The maximized [`Pane`] of the [`PaneGrid`]
+ pub(super) maximized: Option<Pane>,
}
impl<T> State<T> {
@@ -52,7 +55,11 @@ impl<T> State<T> {
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<T> State<T> {
/// 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<Pane, Rectangle> {
- 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<Split, (Axis, Rectangle, f32)> {
- self.layout.split_regions(spacing, size)
+ /// The layout [`Node`] of the [`Internal`] state
+ pub fn layout(&self) -> &Node {
+ &self.layout
}
}