From 7977e970ca3db7740c175db2269e47b2c8b93b1f Mon Sep 17 00:00:00 2001 From: mobile-bungalow Date: Mon, 27 Jul 2020 01:17:02 -0700 Subject: [PATCH 1/4] Added method to TitleBar, allowing controls to be show statically instead of only on mouseover --- native/src/widget/pane_grid/title_bar.rs | 36 ++++++++++++++++-------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/native/src/widget/pane_grid/title_bar.rs b/native/src/widget/pane_grid/title_bar.rs index c74c9e20..31b23a64 100644 --- a/native/src/widget/pane_grid/title_bar.rs +++ b/native/src/widget/pane_grid/title_bar.rs @@ -9,6 +9,7 @@ use crate::{Clipboard, Element, Event, Layout, Point, Rectangle, Size}; pub struct TitleBar<'a, Message, Renderer: pane_grid::Renderer> { title: String, title_size: Option, + always_show_controls: bool, controls: Option>, padding: u16, style: Renderer::Style, @@ -27,6 +28,7 @@ where title_size: None, controls: None, padding: 0, + always_show_controls: false, style: Renderer::Style::default(), } } @@ -65,6 +67,17 @@ where self.style = style.into(); self } + + /// Sets whether or not the [`controls`] attached to this + /// panes [`TitleBar`] are always visible. By default, the controls + /// are only visible on hover. + /// + /// [`TitleBar`]: struct.TitleBar.html + /// [`controls`]: struct.TitleBar.html#method.controls + pub fn always_show_controls(mut self) -> Self { + self.always_show_controls = true; + self + } } impl<'a, Message, Renderer> TitleBar<'a, Message, Renderer> @@ -92,17 +105,18 @@ where let title_layout = children.next().unwrap(); let controls_layout = children.next().unwrap(); - let (title_bounds, controls) = if show_controls { - (title_layout.bounds(), Some((controls, controls_layout))) - } else { - ( - Rectangle { - width: padded.bounds().width, - ..title_layout.bounds() - }, - None, - ) - }; + 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, From 174565715e18b8f6cd29f8816a4f2f931d4a322f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Fri, 31 Jul 2020 04:23:55 +0200 Subject: [PATCH 2/4] Fix typo in `TitleBar::new` --- native/src/widget/pane_grid/title_bar.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/src/widget/pane_grid/title_bar.rs b/native/src/widget/pane_grid/title_bar.rs index 31b23a64..d0d5271d 100644 --- a/native/src/widget/pane_grid/title_bar.rs +++ b/native/src/widget/pane_grid/title_bar.rs @@ -19,7 +19,7 @@ impl<'a, Message, Renderer> TitleBar<'a, Message, Renderer> where Renderer: pane_grid::Renderer, { - /// Cretes a new [`TitleBar`] with the given title. + /// Creates a new [`TitleBar`] with the given title. /// /// [`TitleBar`]: struct.TitleBar.html pub fn new(title: impl Into) -> Self { From ab0da5dad0af3a16e266b74480ce2b12506332fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Fri, 31 Jul 2020 06:43:27 +0200 Subject: [PATCH 3/4] Move `always_show_controls` after `padding` --- native/src/widget/pane_grid/title_bar.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/src/widget/pane_grid/title_bar.rs b/native/src/widget/pane_grid/title_bar.rs index d0d5271d..3851a184 100644 --- a/native/src/widget/pane_grid/title_bar.rs +++ b/native/src/widget/pane_grid/title_bar.rs @@ -9,9 +9,9 @@ use crate::{Clipboard, Element, Event, Layout, Point, Rectangle, Size}; pub struct TitleBar<'a, Message, Renderer: pane_grid::Renderer> { title: String, title_size: Option, - always_show_controls: bool, controls: Option>, padding: u16, + always_show_controls: bool, style: Renderer::Style, } From ac74f354244bf6ecccd8b694dfe08c50cc2ec909 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Fri, 31 Jul 2020 06:43:51 +0200 Subject: [PATCH 4/4] Clarify `TitleBar::always_show_controls` docs a bit --- native/src/widget/pane_grid/title_bar.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/native/src/widget/pane_grid/title_bar.rs b/native/src/widget/pane_grid/title_bar.rs index 3851a184..1d4a32e9 100644 --- a/native/src/widget/pane_grid/title_bar.rs +++ b/native/src/widget/pane_grid/title_bar.rs @@ -68,12 +68,15 @@ where self } - /// Sets whether or not the [`controls`] attached to this - /// panes [`TitleBar`] are always visible. By default, the controls - /// are only visible on hover. + /// Sets whether or not the [`controls`] attached to this [`TitleBar`] are + /// always visible. + /// + /// By default, the controls are only visible when the [`Pane`] of this + /// [`TitleBar`] is hovered. /// /// [`TitleBar`]: struct.TitleBar.html /// [`controls`]: struct.TitleBar.html#method.controls + /// [`Pane`]: struct.Pane.html pub fn always_show_controls(mut self) -> Self { self.always_show_controls = true; self