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') 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') 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') 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') 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') 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') 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 18fb74f20092b2703a90afdb01f39754445998da Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 9 Nov 2022 04:05:31 +0100 Subject: Introduce `Custom` variants for every style in the built-in `Theme` --- native/src/widget/pane_grid/content.rs | 2 +- native/src/widget/pane_grid/title_bar.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'native/src/widget/pane_grid') diff --git a/native/src/widget/pane_grid/content.rs b/native/src/widget/pane_grid/content.rs index c236d820..405dc0b2 100644 --- a/native/src/widget/pane_grid/content.rs +++ b/native/src/widget/pane_grid/content.rs @@ -103,7 +103,7 @@ where let bounds = layout.bounds(); { - let style = theme.appearance(self.style); + let style = theme.appearance(&self.style); container::draw_background(renderer, &style, bounds); } diff --git a/native/src/widget/pane_grid/title_bar.rs b/native/src/widget/pane_grid/title_bar.rs index eb85f924..783a14c3 100644 --- a/native/src/widget/pane_grid/title_bar.rs +++ b/native/src/widget/pane_grid/title_bar.rs @@ -129,7 +129,7 @@ where use container::StyleSheet; let bounds = layout.bounds(); - let style = theme.appearance(self.style); + let style = theme.appearance(&self.style); let inherited_style = renderer::Style { text_color: style.text_color.unwrap_or(inherited_style.text_color), }; -- 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/content.rs | 2 +- native/src/widget/pane_grid/state.rs | 4 +++- native/src/widget/pane_grid/title_bar.rs | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) (limited to 'native/src/widget/pane_grid') diff --git a/native/src/widget/pane_grid/content.rs b/native/src/widget/pane_grid/content.rs index 405dc0b2..7e6c8148 100644 --- a/native/src/widget/pane_grid/content.rs +++ b/native/src/widget/pane_grid/content.rs @@ -87,7 +87,7 @@ where /// Draws the [`Content`] with the provided [`Renderer`] and [`Layout`]. /// - /// [`Renderer`]: iced_native::Renderer + /// [`Renderer`]: crate::Renderer pub fn draw( &self, tree: &Tree, 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, } diff --git a/native/src/widget/pane_grid/title_bar.rs b/native/src/widget/pane_grid/title_bar.rs index 783a14c3..1b70e51b 100644 --- a/native/src/widget/pane_grid/title_bar.rs +++ b/native/src/widget/pane_grid/title_bar.rs @@ -114,7 +114,7 @@ where /// Draws the [`TitleBar`] with the provided [`Renderer`] and [`Layout`]. /// - /// [`Renderer`]: iced_native::Renderer + /// [`Renderer`]: crate::Renderer pub fn draw( &self, tree: &Tree, -- cgit From b0678f4c75d9913b2a1f11392f94f69af7db2efd Mon Sep 17 00:00:00 2001 From: Ryan Scheidter Date: Sun, 13 Nov 2022 14:21:27 -0600 Subject: Implement `Widget::operate` for `PaneGrid` --- native/src/widget/pane_grid/content.rs | 29 ++++++++++++++++++++++- native/src/widget/pane_grid/title_bar.rs | 40 +++++++++++++++++++++++++++++++- 2 files changed, 67 insertions(+), 2 deletions(-) (limited to 'native/src/widget/pane_grid') diff --git a/native/src/widget/pane_grid/content.rs b/native/src/widget/pane_grid/content.rs index 7e6c8148..5e843cff 100644 --- a/native/src/widget/pane_grid/content.rs +++ b/native/src/widget/pane_grid/content.rs @@ -5,7 +5,7 @@ use crate::overlay; use crate::renderer; use crate::widget::container; use crate::widget::pane_grid::{Draggable, TitleBar}; -use crate::widget::Tree; +use crate::widget::{self, Tree}; use crate::{Clipboard, Element, Layout, Point, Rectangle, Shell, Size}; /// The content of a [`Pane`]. @@ -183,6 +183,33 @@ where } } + pub(crate) fn operate( + &self, + tree: &mut Tree, + layout: Layout<'_>, + operation: &mut dyn widget::Operation, + ) { + let body_layout = if let Some(title_bar) = &self.title_bar { + let mut children = layout.children(); + + title_bar.operate( + &mut tree.children[1], + children.next().unwrap(), + operation, + ); + + children.next().unwrap() + } else { + layout + }; + + self.body.as_widget().operate( + &mut tree.children[0], + body_layout, + operation, + ); + } + pub(crate) fn on_event( &mut self, tree: &mut Tree, diff --git a/native/src/widget/pane_grid/title_bar.rs b/native/src/widget/pane_grid/title_bar.rs index 1b70e51b..115f6270 100644 --- a/native/src/widget/pane_grid/title_bar.rs +++ b/native/src/widget/pane_grid/title_bar.rs @@ -4,7 +4,7 @@ use crate::mouse; use crate::overlay; use crate::renderer; use crate::widget::container; -use crate::widget::Tree; +use crate::widget::{self, Tree}; use crate::{ Clipboard, Element, Layout, Padding, Point, Rectangle, Shell, Size, }; @@ -257,6 +257,44 @@ where layout::Node::with_children(node.size().pad(self.padding), vec![node]) } + pub(crate) fn operate( + &self, + tree: &mut Tree, + layout: Layout<'_>, + operation: &mut dyn widget::Operation, + ) { + let mut children = layout.children(); + let padded = children.next().unwrap(); + + let mut children = padded.children(); + let title_layout = children.next().unwrap(); + let mut show_title = true; + + if let Some(controls) = &self.controls { + let controls_layout = children.next().unwrap(); + + if title_layout.bounds().width + controls_layout.bounds().width + > padded.bounds().width + { + show_title = false; + } + + controls.as_widget().operate( + &mut tree.children[1], + controls_layout, + operation, + ) + }; + + if show_title { + self.content.as_widget().operate( + &mut tree.children[0], + title_layout, + operation, + ) + } + } + pub(crate) fn on_event( &mut self, tree: &mut Tree, -- cgit From f1ada7a803998ac3fb2c1bedc6d6650264f3e603 Mon Sep 17 00:00:00 2001 From: tarkah Date: Sat, 19 Nov 2022 12:25:59 -0800 Subject: Allow &mut self in overlay --- native/src/widget/pane_grid/content.rs | 8 ++++---- native/src/widget/pane_grid/title_bar.rs | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'native/src/widget/pane_grid') diff --git a/native/src/widget/pane_grid/content.rs b/native/src/widget/pane_grid/content.rs index 5e843cff..5f269d1f 100644 --- a/native/src/widget/pane_grid/content.rs +++ b/native/src/widget/pane_grid/content.rs @@ -305,12 +305,12 @@ where } pub(crate) fn overlay<'b>( - &'b self, + &'b mut self, tree: &'b mut Tree, layout: Layout<'_>, renderer: &Renderer, ) -> Option> { - if let Some(title_bar) = self.title_bar.as_ref() { + if let Some(title_bar) = self.title_bar.as_mut() { let mut children = layout.children(); let title_bar_layout = children.next()?; @@ -321,14 +321,14 @@ where match title_bar.overlay(title_bar_state, title_bar_layout, renderer) { Some(overlay) => Some(overlay), - None => self.body.as_widget().overlay( + None => self.body.as_widget_mut().overlay( body_state, children.next()?, renderer, ), } } else { - self.body.as_widget().overlay( + self.body.as_widget_mut().overlay( &mut tree.children[0], layout, renderer, diff --git a/native/src/widget/pane_grid/title_bar.rs b/native/src/widget/pane_grid/title_bar.rs index 115f6270..28e4670f 100644 --- a/native/src/widget/pane_grid/title_bar.rs +++ b/native/src/widget/pane_grid/title_bar.rs @@ -395,7 +395,7 @@ where } pub(crate) fn overlay<'b>( - &'b self, + &'b mut self, tree: &'b mut Tree, layout: Layout<'_>, renderer: &Renderer, @@ -415,13 +415,13 @@ where let controls_state = states.next().unwrap(); content - .as_widget() + .as_widget_mut() .overlay(title_state, title_layout, renderer) .or_else(move || { - controls.as_ref().and_then(|controls| { + controls.as_mut().and_then(|controls| { let controls_layout = children.next()?; - controls.as_widget().overlay( + controls.as_widget_mut().overlay( controls_state, controls_layout, renderer, -- cgit