Added method to TitleBar, allowing controls to be show statically instead of only on mouseover

This commit is contained in:
mobile-bungalow 2020-07-27 01:17:02 -07:00
parent 9b778006ce
commit 7977e970ca

View File

@ -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,7 +105,8 @@ where
let title_layout = children.next().unwrap();
let controls_layout = children.next().unwrap();
let (title_bounds, controls) = if show_controls {
let (title_bounds, controls) =
if show_controls || self.always_show_controls {
(title_layout.bounds(), Some((controls, controls_layout)))
} else {
(