From f54590d7adac611db84b88cbcbf4f56c7542039c Mon Sep 17 00:00:00 2001 From: Clark Moody Date: Tue, 8 Dec 2020 18:47:01 -0600 Subject: Replace TitleBar string title with generic Content --- native/src/widget/pane_grid/title_bar.rs | 111 +++++++++++-------------------- 1 file changed, 38 insertions(+), 73 deletions(-) (limited to 'native/src/widget/pane_grid') diff --git a/native/src/widget/pane_grid/title_bar.rs b/native/src/widget/pane_grid/title_bar.rs index 475cb9ae..a73acff7 100644 --- a/native/src/widget/pane_grid/title_bar.rs +++ b/native/src/widget/pane_grid/title_bar.rs @@ -1,30 +1,31 @@ use crate::event::{self, Event}; use crate::layout; use crate::pane_grid; -use crate::{Clipboard, Element, Hasher, Layout, Point, Rectangle, Size}; +use crate::{Clipboard, Element, Hasher, Layout, Point, Size}; /// The title bar of a [`Pane`]. /// /// [`Pane`]: crate::widget::pane_grid::Pane #[allow(missing_debug_implementations)] pub struct TitleBar<'a, Message, Renderer: pane_grid::Renderer> { - title: String, - title_size: Option, + content: Element<'a, Message, Renderer>, controls: Option>, padding: u16, always_show_controls: bool, style: Renderer::Style, } -impl<'a, Message, Renderer> TitleBar<'a, Message, Renderer> +impl<'a, Message, Renderer: 'a> TitleBar<'a, Message, Renderer> where Renderer: pane_grid::Renderer, { - /// Creates a new [`TitleBar`] with the given title. - pub fn new(title: impl Into) -> Self { + /// Creates a new [`TitleBar`] with the given content. + pub fn new(content: E) -> Self + where + E: Into>, + { Self { - title: title.into(), - title_size: None, + content: content.into(), controls: None, padding: 0, always_show_controls: false, @@ -32,12 +33,6 @@ where } } - /// Sets the size of the title of the [`TitleBar`]. - pub fn title_size(mut self, size: u16) -> Self { - self.title_size = Some(size); - self - } - /// Sets the controls of the [`TitleBar`]. pub fn controls( mut self, @@ -91,48 +86,29 @@ where let mut children = layout.children(); let padded = children.next().unwrap(); - if let Some(controls) = &self.controls { - let mut children = padded.children(); - let title_layout = children.next().unwrap(); + let mut children = padded.children(); + let title_layout = children.next().unwrap(); + + let controls = if let Some(controls) = &self.controls { let controls_layout = children.next().unwrap(); - let (title_bounds, controls) = - if show_controls || self.always_show_controls { - (title_layout.bounds(), Some((controls, controls_layout))) - } else { - ( - Rectangle { - width: padded.bounds().width, - ..title_layout.bounds() - }, - None, - ) - }; - - renderer.draw_title_bar( - defaults, - layout.bounds(), - &self.style, - &self.title, - self.title_size.unwrap_or(renderer.default_size()), - Renderer::Font::default(), - title_bounds, - controls, - cursor_position, - ) + if show_controls || self.always_show_controls { + Some((controls, controls_layout)) + } else { + None + } } else { - renderer.draw_title_bar::<()>( - defaults, - layout.bounds(), - &self.style, - &self.title, - self.title_size.unwrap_or(renderer.default_size()), - Renderer::Font::default(), - padded.bounds(), - None, - cursor_position, - ) - } + None + }; + + renderer.draw_title_bar( + defaults, + layout.bounds(), + &self.style, + (&self.content, title_layout), + controls, + cursor_position, + ) } /// Returns whether the mouse cursor is over the pick area of the @@ -165,8 +141,7 @@ where pub(crate) fn hash_layout(&self, hasher: &mut Hasher) { use std::hash::Hash; - self.title.hash(hasher); - self.title_size.hash(hasher); + self.content.hash_layout(hasher); self.padding.hash(hasher); } @@ -179,15 +154,10 @@ where let limits = limits.pad(padding); let max_size = limits.max(); - let title_size = self.title_size.unwrap_or(renderer.default_size()); - let title_font = Renderer::Font::default(); - - let (title_width, title_height) = renderer.measure( - &self.title, - title_size, - title_font, - Size::new(f32::INFINITY, max_size.height), - ); + let title_layout = self + .content + .layout(renderer, &layout::Limits::new(Size::ZERO, max_size)); + let title_size = title_layout.size(); let mut node = if let Some(controls) = &self.controls { let mut controls_layout = controls @@ -196,16 +166,8 @@ where let controls_size = controls_layout.size(); let space_before_controls = max_size.width - controls_size.width; - let mut title_layout = layout::Node::new(Size::new( - title_width.min(space_before_controls), - title_height, - )); - - let title_size = title_layout.size(); let height = title_size.height.max(controls_size.height); - title_layout - .move_to(Point::new(0.0, (height - title_size.height) / 2.0)); controls_layout.move_to(Point::new(space_before_controls, 0.0)); layout::Node::with_children( @@ -213,7 +175,10 @@ where vec![title_layout, controls_layout], ) } else { - layout::Node::new(Size::new(max_size.width, title_height)) + layout::Node::with_children( + Size::new(max_size.width, title_size.height), + vec![title_layout], + ) }; node.move_to(Point::new(padding, padding)); -- cgit From e815c5bbd72f618ad890e1d3c5a67c811cd07108 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 22 Dec 2020 14:47:18 +0100 Subject: Remove unnecessary lifetime bound in `TitleBar` --- native/src/widget/pane_grid/title_bar.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'native/src/widget/pane_grid') diff --git a/native/src/widget/pane_grid/title_bar.rs b/native/src/widget/pane_grid/title_bar.rs index a73acff7..30e88e6f 100644 --- a/native/src/widget/pane_grid/title_bar.rs +++ b/native/src/widget/pane_grid/title_bar.rs @@ -15,7 +15,7 @@ pub struct TitleBar<'a, Message, Renderer: pane_grid::Renderer> { style: Renderer::Style, } -impl<'a, Message, Renderer: 'a> TitleBar<'a, Message, Renderer> +impl<'a, Message, Renderer> TitleBar<'a, Message, Renderer> where Renderer: pane_grid::Renderer, { -- cgit From a7bb7bb2eaaae5a016721788fcaf03c4c7413acd Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 1 Jan 2021 15:28:38 +0100 Subject: Implement split highlight on hover for `PaneGrid` --- native/src/widget/pane_grid/content.rs | 9 ++++++--- native/src/widget/pane_grid/title_bar.rs | 10 +++++++--- 2 files changed, 13 insertions(+), 6 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 c9981903..913cfe96 100644 --- a/native/src/widget/pane_grid/content.rs +++ b/native/src/widget/pane_grid/content.rs @@ -12,7 +12,7 @@ use crate::{Clipboard, Element, Hasher, Layout, Point, Size}; pub struct Content<'a, Message, Renderer: pane_grid::Renderer> { title_bar: Option>, body: Element<'a, Message, Renderer>, - style: Renderer::Style, + style: ::Style, } impl<'a, Message, Renderer> Content<'a, Message, Renderer> @@ -24,7 +24,7 @@ where Self { title_bar: None, body: body.into(), - style: Renderer::Style::default(), + style: Default::default(), } } @@ -38,7 +38,10 @@ where } /// Sets the style of the [`Content`]. - pub fn style(mut self, style: impl Into) -> Self { + pub fn style( + mut self, + style: impl Into<::Style>, + ) -> Self { self.style = style.into(); self } diff --git a/native/src/widget/pane_grid/title_bar.rs b/native/src/widget/pane_grid/title_bar.rs index 30e88e6f..efaecf9e 100644 --- a/native/src/widget/pane_grid/title_bar.rs +++ b/native/src/widget/pane_grid/title_bar.rs @@ -1,3 +1,4 @@ +use crate::container; use crate::event::{self, Event}; use crate::layout; use crate::pane_grid; @@ -12,7 +13,7 @@ pub struct TitleBar<'a, Message, Renderer: pane_grid::Renderer> { controls: Option>, padding: u16, always_show_controls: bool, - style: Renderer::Style, + style: ::Style, } impl<'a, Message, Renderer> TitleBar<'a, Message, Renderer> @@ -29,7 +30,7 @@ where controls: None, padding: 0, always_show_controls: false, - style: Renderer::Style::default(), + style: Default::default(), } } @@ -49,7 +50,10 @@ where } /// Sets the style of the [`TitleBar`]. - pub fn style(mut self, style: impl Into) -> Self { + pub fn style( + mut self, + style: impl Into<::Style>, + ) -> Self { self.style = style.into(); self } -- cgit From e7344d03b467e87b3e50fa8d7ecd74994b46a4e6 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 7 Jan 2021 21:07:44 +0100 Subject: Use `BTreeMap` for splits and regions in `pane_grid` This preserves ordering between calls to update and draw logic. --- native/src/widget/pane_grid/node.rs | 14 +++++++------- native/src/widget/pane_grid/pane.rs | 2 +- native/src/widget/pane_grid/split.rs | 2 +- native/src/widget/pane_grid/state.rs | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) (limited to 'native/src/widget/pane_grid') diff --git a/native/src/widget/pane_grid/node.rs b/native/src/widget/pane_grid/node.rs index 319936fc..84714e00 100644 --- a/native/src/widget/pane_grid/node.rs +++ b/native/src/widget/pane_grid/node.rs @@ -3,7 +3,7 @@ use crate::{ Rectangle, Size, }; -use std::collections::HashMap; +use std::collections::BTreeMap; /// A layout node of a [`PaneGrid`]. /// @@ -59,8 +59,8 @@ impl Node { &self, spacing: f32, size: Size, - ) -> HashMap { - let mut regions = HashMap::new(); + ) -> BTreeMap { + let mut regions = BTreeMap::new(); self.compute_regions( spacing, @@ -83,8 +83,8 @@ impl Node { &self, spacing: f32, size: Size, - ) -> HashMap { - let mut splits = HashMap::new(); + ) -> BTreeMap { + let mut splits = BTreeMap::new(); self.compute_splits( spacing, @@ -191,7 +191,7 @@ impl Node { &self, spacing: f32, current: &Rectangle, - regions: &mut HashMap, + regions: &mut BTreeMap, ) { match self { Node::Split { @@ -212,7 +212,7 @@ impl Node { &self, spacing: f32, current: &Rectangle, - splits: &mut HashMap, + splits: &mut BTreeMap, ) { match self { Node::Split { diff --git a/native/src/widget/pane_grid/pane.rs b/native/src/widget/pane_grid/pane.rs index 39d9f3ef..d6fbab83 100644 --- a/native/src/widget/pane_grid/pane.rs +++ b/native/src/widget/pane_grid/pane.rs @@ -1,5 +1,5 @@ /// A rectangular region in a [`PaneGrid`] used to display widgets. /// /// [`PaneGrid`]: crate::widget::PaneGrid -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct Pane(pub(super) usize); diff --git a/native/src/widget/pane_grid/split.rs b/native/src/widget/pane_grid/split.rs index 16975abc..8132272a 100644 --- a/native/src/widget/pane_grid/split.rs +++ b/native/src/widget/pane_grid/split.rs @@ -1,5 +1,5 @@ /// A divider that splits a region in a [`PaneGrid`] into two different panes. /// /// [`PaneGrid`]: crate::widget::PaneGrid -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct Split(pub(super) usize); diff --git a/native/src/widget/pane_grid/state.rs b/native/src/widget/pane_grid/state.rs index 666e1ca0..fb96f89f 100644 --- a/native/src/widget/pane_grid/state.rs +++ b/native/src/widget/pane_grid/state.rs @@ -3,7 +3,7 @@ use crate::{ Hasher, Point, Rectangle, Size, }; -use std::collections::HashMap; +use std::collections::{BTreeMap, HashMap}; /// The state of a [`PaneGrid`]. /// @@ -257,7 +257,7 @@ impl Internal { &self, spacing: f32, size: Size, - ) -> HashMap { + ) -> BTreeMap { self.layout.pane_regions(spacing, size) } @@ -265,7 +265,7 @@ impl Internal { &self, spacing: f32, size: Size, - ) -> HashMap { + ) -> BTreeMap { self.layout.split_regions(spacing, size) } -- cgit From f52f8c1337f42cf9483abb40784129f4effbe48e Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 27 Feb 2021 03:36:46 +0100 Subject: Fix `viewport` argument in `PaneGrid` draw calls --- native/src/widget/pane_grid/content.rs | 5 ++++- native/src/widget/pane_grid/title_bar.rs | 4 +++- 2 files changed, 7 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 913cfe96..421da47b 100644 --- a/native/src/widget/pane_grid/content.rs +++ b/native/src/widget/pane_grid/content.rs @@ -3,7 +3,7 @@ use crate::event::{self, Event}; use crate::layout; use crate::overlay; use crate::pane_grid::{self, TitleBar}; -use crate::{Clipboard, Element, Hasher, Layout, Point, Size}; +use crate::{Clipboard, Element, Hasher, Layout, Point, Rectangle, Size}; /// The content of a [`Pane`]. /// @@ -60,6 +60,7 @@ where defaults: &Renderer::Defaults, layout: Layout<'_>, cursor_position: Point, + viewport: &Rectangle, ) -> Renderer::Output { if let Some(title_bar) = &self.title_bar { let mut children = layout.children(); @@ -73,6 +74,7 @@ where Some((title_bar, title_bar_layout)), (&self.body, body_layout), cursor_position, + viewport, ) } else { renderer.draw_pane( @@ -82,6 +84,7 @@ where None, (&self.body, layout), cursor_position, + viewport, ) } } diff --git a/native/src/widget/pane_grid/title_bar.rs b/native/src/widget/pane_grid/title_bar.rs index efaecf9e..9fbd2797 100644 --- a/native/src/widget/pane_grid/title_bar.rs +++ b/native/src/widget/pane_grid/title_bar.rs @@ -2,7 +2,7 @@ use crate::container; use crate::event::{self, Event}; use crate::layout; use crate::pane_grid; -use crate::{Clipboard, Element, Hasher, Layout, Point, Size}; +use crate::{Clipboard, Element, Hasher, Layout, Point, Rectangle, Size}; /// The title bar of a [`Pane`]. /// @@ -85,6 +85,7 @@ where defaults: &Renderer::Defaults, layout: Layout<'_>, cursor_position: Point, + viewport: &Rectangle, show_controls: bool, ) -> Renderer::Output { let mut children = layout.children(); @@ -112,6 +113,7 @@ where (&self.content, title_layout), controls, cursor_position, + viewport, ) } -- cgit From bbca5c4bde6f9e6e54cca6cb216d38dfd3864e74 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 9 Mar 2021 04:49:17 +0100 Subject: Call `hash_layout` for `controls` in `pane_grid::TitleBar` --- native/src/widget/pane_grid/title_bar.rs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'native/src/widget/pane_grid') diff --git a/native/src/widget/pane_grid/title_bar.rs b/native/src/widget/pane_grid/title_bar.rs index efaecf9e..2f9659e8 100644 --- a/native/src/widget/pane_grid/title_bar.rs +++ b/native/src/widget/pane_grid/title_bar.rs @@ -147,6 +147,10 @@ where self.content.hash_layout(hasher); self.padding.hash(hasher); + + if let Some(controls) = &self.controls { + controls.hash_layout(hasher); + } } pub(crate) fn layout( -- cgit From 21971e0037c2ddcb96fd48ea96332445de4137bb Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 10 Mar 2021 01:59:02 +0100 Subject: Make `Clipboard` argument in `Widget` trait mutable --- native/src/widget/pane_grid/content.rs | 8 ++++---- native/src/widget/pane_grid/title_bar.rs | 6 +++--- 2 files changed, 7 insertions(+), 7 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 913cfe96..a5493fe2 100644 --- a/native/src/widget/pane_grid/content.rs +++ b/native/src/widget/pane_grid/content.rs @@ -143,9 +143,9 @@ where event: Event, layout: Layout<'_>, cursor_position: Point, - messages: &mut Vec, renderer: &Renderer, - clipboard: Option<&dyn Clipboard>, + clipboard: &mut dyn Clipboard, + messages: &mut Vec, ) -> event::Status { let mut event_status = event::Status::Ignored; @@ -156,9 +156,9 @@ where event.clone(), children.next().unwrap(), cursor_position, - messages, renderer, clipboard, + messages, ); children.next().unwrap() @@ -170,9 +170,9 @@ where event, body_layout, cursor_position, - messages, renderer, clipboard, + messages, ); event_status.merge(body_status) diff --git a/native/src/widget/pane_grid/title_bar.rs b/native/src/widget/pane_grid/title_bar.rs index 2f9659e8..ff689ddb 100644 --- a/native/src/widget/pane_grid/title_bar.rs +++ b/native/src/widget/pane_grid/title_bar.rs @@ -199,9 +199,9 @@ where event: Event, layout: Layout<'_>, cursor_position: Point, - messages: &mut Vec, renderer: &Renderer, - clipboard: Option<&dyn Clipboard>, + clipboard: &mut dyn Clipboard, + messages: &mut Vec, ) -> event::Status { if let Some(controls) = &mut self.controls { let mut children = layout.children(); @@ -215,9 +215,9 @@ where event, controls_layout, cursor_position, - messages, renderer, clipboard, + messages, ) } else { event::Status::Ignored -- cgit From d4c5f3ee950262c578c7b9b2a4aab60d3c5edaed Mon Sep 17 00:00:00 2001 From: Clark Moody Date: Mon, 24 May 2021 16:37:47 -0500 Subject: Enable event handling within the title elements Shrink the pick area to avoid both the controls and the title elements. Handle events and merge title area event status with control events. --- native/src/widget/pane_grid/title_bar.rs | 33 ++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) (limited to 'native/src/widget/pane_grid') diff --git a/native/src/widget/pane_grid/title_bar.rs b/native/src/widget/pane_grid/title_bar.rs index a1e5107e..8e42ce38 100644 --- a/native/src/widget/pane_grid/title_bar.rs +++ b/native/src/widget/pane_grid/title_bar.rs @@ -129,15 +129,16 @@ where if layout.bounds().contains(cursor_position) { let mut children = layout.children(); let padded = children.next().unwrap(); + let mut children = padded.children(); + let title_layout = children.next().unwrap(); if self.controls.is_some() { - let mut children = padded.children(); - let _ = children.next().unwrap(); let controls_layout = children.next().unwrap(); !controls_layout.bounds().contains(cursor_position) + && !title_layout.bounds().contains(cursor_position) } else { - true + !title_layout.bounds().contains(cursor_position) } } else { false @@ -205,16 +206,17 @@ where clipboard: &mut dyn Clipboard, messages: &mut Vec, ) -> event::Status { - if let Some(controls) = &mut self.controls { - let mut children = layout.children(); - let padded = children.next().unwrap(); + let mut children = layout.children(); + let padded = children.next().unwrap(); - let mut children = padded.children(); - let _ = children.next(); + let mut children = padded.children(); + let title_layout = children.next().unwrap(); + + let control_status = if let Some(controls) = &mut self.controls { let controls_layout = children.next().unwrap(); controls.on_event( - event, + event.clone(), controls_layout, cursor_position, renderer, @@ -223,6 +225,17 @@ where ) } else { event::Status::Ignored - } + }; + + let title_status = self.content.on_event( + event, + title_layout, + cursor_position, + renderer, + clipboard, + messages, + ); + + control_status.merge(title_status) } } -- cgit From fe0a27c56d9d75fb521e69352259f1d737402a20 Mon Sep 17 00:00:00 2001 From: Ben LeFevre Date: Mon, 23 Nov 2020 17:19:21 +0000 Subject: Add support for asymmetrical padding --- native/src/widget/pane_grid/title_bar.rs | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'native/src/widget/pane_grid') diff --git a/native/src/widget/pane_grid/title_bar.rs b/native/src/widget/pane_grid/title_bar.rs index 8e42ce38..8f32992a 100644 --- a/native/src/widget/pane_grid/title_bar.rs +++ b/native/src/widget/pane_grid/title_bar.rs @@ -2,7 +2,9 @@ use crate::container; use crate::event::{self, Event}; use crate::layout; use crate::pane_grid; -use crate::{Clipboard, Element, Hasher, Layout, Point, Rectangle, Size}; +use crate::{ + Clipboard, Element, Hasher, Layout, Padding, Point, Rectangle, Size, +}; /// The title bar of a [`Pane`]. /// @@ -11,7 +13,7 @@ use crate::{Clipboard, Element, Hasher, Layout, Point, Rectangle, Size}; pub struct TitleBar<'a, Message, Renderer: pane_grid::Renderer> { content: Element<'a, Message, Renderer>, controls: Option>, - padding: u16, + padding: Padding, always_show_controls: bool, style: ::Style, } @@ -28,7 +30,7 @@ where Self { content: content.into(), controls: None, - padding: 0, + padding: Padding::ZERO, always_show_controls: false, style: Default::default(), } @@ -43,9 +45,14 @@ where self } - /// Sets the padding of the [`TitleBar`]. - pub fn padding(mut self, units: u16) -> Self { - self.padding = units; + /// Sets the [`Padding`] of the [`TitleBar`]. + ///```ignore + /// TitleBar::new(/*...*/).padding(20); // 20px on all sides + /// TitleBar::new(/*...*/).padding([10, 20]); // top/bottom, left/right + /// TitleBar::new(/*...*/).padding([5, 10, 15, 20]); // top, right, bottom, left + /// ``` + pub fn padding>(mut self, padding: P) -> Self { + self.padding = padding.into(); self } @@ -161,8 +168,7 @@ where renderer: &Renderer, limits: &layout::Limits, ) -> layout::Node { - let padding = f32::from(self.padding); - let limits = limits.pad(padding); + let limits = limits.pad(self.padding); let max_size = limits.max(); let title_layout = self @@ -192,9 +198,12 @@ where ) }; - node.move_to(Point::new(padding, padding)); + node.move_to(Point::new( + self.padding.left.into(), + self.padding.top.into(), + )); - layout::Node::with_children(node.size().pad(padding), vec![node]) + layout::Node::with_children(node.size().pad(self.padding), vec![node]) } pub(crate) fn on_event( -- cgit From 8a3b71df8b619571ce0a972826cb5a3987b66b3d Mon Sep 17 00:00:00 2001 From: Héctor Ramón Date: Tue, 1 Jun 2021 19:45:47 +0700 Subject: Replace ignored doc-tests with additional documentation for `Padding` --- native/src/widget/pane_grid/title_bar.rs | 5 ----- 1 file changed, 5 deletions(-) (limited to 'native/src/widget/pane_grid') diff --git a/native/src/widget/pane_grid/title_bar.rs b/native/src/widget/pane_grid/title_bar.rs index 8f32992a..d9d85dbb 100644 --- a/native/src/widget/pane_grid/title_bar.rs +++ b/native/src/widget/pane_grid/title_bar.rs @@ -46,11 +46,6 @@ where } /// Sets the [`Padding`] of the [`TitleBar`]. - ///```ignore - /// TitleBar::new(/*...*/).padding(20); // 20px on all sides - /// TitleBar::new(/*...*/).padding([10, 20]); // top/bottom, left/right - /// TitleBar::new(/*...*/).padding([5, 10, 15, 20]); // top, right, bottom, left - /// ``` pub fn padding>(mut self, padding: P) -> Self { self.padding = padding.into(); self -- cgit From 27b42ca6b6585477fda0a5d07ec09bd74e501a1a Mon Sep 17 00:00:00 2001 From: Clark Moody Date: Thu, 17 Jun 2021 14:50:28 -0500 Subject: Allow overlay from pane grid title bar --- native/src/widget/pane_grid/content.rs | 16 ++++++++-------- native/src/widget/pane_grid/title_bar.rs | 8 ++++++++ 2 files changed, 16 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 f028ec25..188c47e3 100644 --- a/native/src/widget/pane_grid/content.rs +++ b/native/src/widget/pane_grid/content.rs @@ -193,18 +193,18 @@ where &mut self, layout: Layout<'_>, ) -> Option> { - let body_layout = if self.title_bar.is_some() { + if let Some(title_bar) = self.title_bar.as_mut() { let mut children = layout.children(); + let title_bar_layout = children.next().unwrap(); - // Overlays only allowed in the pane body, for now at least. - let _title_bar_layout = children.next(); + if let Some(overlay) = title_bar.overlay(title_bar_layout) { + return Some(overlay); + } - children.next()? + self.body.overlay(children.next()?) } else { - layout - }; - - self.body.overlay(body_layout) + self.body.overlay(layout) + } } } diff --git a/native/src/widget/pane_grid/title_bar.rs b/native/src/widget/pane_grid/title_bar.rs index d9d85dbb..efdc1e54 100644 --- a/native/src/widget/pane_grid/title_bar.rs +++ b/native/src/widget/pane_grid/title_bar.rs @@ -1,6 +1,7 @@ use crate::container; use crate::event::{self, Event}; use crate::layout; +use crate::overlay; use crate::pane_grid; use crate::{ Clipboard, Element, Hasher, Layout, Padding, Point, Rectangle, Size, @@ -242,4 +243,11 @@ where control_status.merge(title_status) } + + pub(crate) fn overlay( + &mut self, + layout: Layout<'_>, + ) -> Option> { + self.content.overlay(layout) + } } -- cgit From 15c17a72502e15393f6430424eaad576581f2e38 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 22 Jun 2021 11:29:06 +0200 Subject: Use `match` statement in `Content::overlay` ... to improve readability a bit. --- native/src/widget/pane_grid/content.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 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 188c47e3..b0110393 100644 --- a/native/src/widget/pane_grid/content.rs +++ b/native/src/widget/pane_grid/content.rs @@ -195,13 +195,12 @@ where ) -> Option> { if let Some(title_bar) = self.title_bar.as_mut() { let mut children = layout.children(); - let title_bar_layout = children.next().unwrap(); + let title_bar_layout = children.next()?; - if let Some(overlay) = title_bar.overlay(title_bar_layout) { - return Some(overlay); + match title_bar.overlay(title_bar_layout) { + Some(overlay) => Some(overlay), + None => self.body.overlay(children.next()?), } - - self.body.overlay(children.next()?) } else { self.body.overlay(layout) } -- cgit From 2993e9b46674d976443abe1380c0e2b54f934a8e Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 15 Jul 2021 16:43:52 +0200 Subject: Fix implementation of `Widget::overlay` for `pane_grid::TitleBar` --- native/src/widget/pane_grid/title_bar.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'native/src/widget/pane_grid') diff --git a/native/src/widget/pane_grid/title_bar.rs b/native/src/widget/pane_grid/title_bar.rs index efdc1e54..48d24c41 100644 --- a/native/src/widget/pane_grid/title_bar.rs +++ b/native/src/widget/pane_grid/title_bar.rs @@ -248,6 +248,22 @@ where &mut self, layout: Layout<'_>, ) -> Option> { - self.content.overlay(layout) + let mut children = layout.children(); + let padded = children.next().unwrap(); + + let mut children = padded.children(); + let title_layout = children.next().unwrap(); + + let Self { + content, controls, .. + } = self; + + content.overlay(title_layout).or_else(move || { + controls.as_mut().and_then(|controls| { + let controls_layout = children.next().unwrap(); + + controls.overlay(controls_layout) + }) + }) } } -- cgit From 4dc1bba5cdc68a7ff3fd3547bd06ff2aa6a7985d Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 15 Jul 2021 16:49:19 +0200 Subject: Remove unnecesary use of `Option::unwrap` ... in `overlay` implementation for `pane_grid::TitleBar` --- native/src/widget/pane_grid/title_bar.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'native/src/widget/pane_grid') diff --git a/native/src/widget/pane_grid/title_bar.rs b/native/src/widget/pane_grid/title_bar.rs index 48d24c41..070010f8 100644 --- a/native/src/widget/pane_grid/title_bar.rs +++ b/native/src/widget/pane_grid/title_bar.rs @@ -249,10 +249,10 @@ where layout: Layout<'_>, ) -> Option> { let mut children = layout.children(); - let padded = children.next().unwrap(); + let padded = children.next()?; let mut children = padded.children(); - let title_layout = children.next().unwrap(); + let title_layout = children.next()?; let Self { content, controls, .. @@ -260,7 +260,7 @@ where content.overlay(title_layout).or_else(move || { controls.as_mut().and_then(|controls| { - let controls_layout = children.next().unwrap(); + let controls_layout = children.next()?; controls.overlay(controls_layout) }) -- cgit