diff options
author | 2020-07-27 01:17:02 -0700 | |
---|---|---|
committer | 2020-07-27 01:17:02 -0700 | |
commit | 7977e970ca3db7740c175db2269e47b2c8b93b1f (patch) | |
tree | a232f3d05c5ee2e846ec9bf1447c4fa0e64d2555 /native | |
parent | 9b778006ce7a56b129cc779b5bad31931d5faf12 (diff) | |
download | iced-7977e970ca3db7740c175db2269e47b2c8b93b1f.tar.gz iced-7977e970ca3db7740c175db2269e47b2c8b93b1f.tar.bz2 iced-7977e970ca3db7740c175db2269e47b2c8b93b1f.zip |
Added method to TitleBar, allowing controls to be show statically instead of only on mouseover
Diffstat (limited to 'native')
-rw-r--r-- | native/src/widget/pane_grid/title_bar.rs | 36 |
1 files 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<u16>, + always_show_controls: bool, controls: Option<Element<'a, Message, Renderer>>, 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, |