Added method to TitleBar, allowing controls to be show statically instead of only on mouseover
This commit is contained in:
parent
9b778006ce
commit
7977e970ca
@ -9,6 +9,7 @@ use crate::{Clipboard, Element, Event, Layout, Point, Rectangle, Size};
|
|||||||
pub struct TitleBar<'a, Message, Renderer: pane_grid::Renderer> {
|
pub struct TitleBar<'a, Message, Renderer: pane_grid::Renderer> {
|
||||||
title: String,
|
title: String,
|
||||||
title_size: Option<u16>,
|
title_size: Option<u16>,
|
||||||
|
always_show_controls: bool,
|
||||||
controls: Option<Element<'a, Message, Renderer>>,
|
controls: Option<Element<'a, Message, Renderer>>,
|
||||||
padding: u16,
|
padding: u16,
|
||||||
style: Renderer::Style,
|
style: Renderer::Style,
|
||||||
@ -27,6 +28,7 @@ where
|
|||||||
title_size: None,
|
title_size: None,
|
||||||
controls: None,
|
controls: None,
|
||||||
padding: 0,
|
padding: 0,
|
||||||
|
always_show_controls: false,
|
||||||
style: Renderer::Style::default(),
|
style: Renderer::Style::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -65,6 +67,17 @@ where
|
|||||||
self.style = style.into();
|
self.style = style.into();
|
||||||
self
|
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>
|
impl<'a, Message, Renderer> TitleBar<'a, Message, Renderer>
|
||||||
@ -92,17 +105,18 @@ where
|
|||||||
let title_layout = children.next().unwrap();
|
let title_layout = children.next().unwrap();
|
||||||
let controls_layout = children.next().unwrap();
|
let controls_layout = children.next().unwrap();
|
||||||
|
|
||||||
let (title_bounds, controls) = if show_controls {
|
let (title_bounds, controls) =
|
||||||
(title_layout.bounds(), Some((controls, controls_layout)))
|
if show_controls || self.always_show_controls {
|
||||||
} else {
|
(title_layout.bounds(), Some((controls, controls_layout)))
|
||||||
(
|
} else {
|
||||||
Rectangle {
|
(
|
||||||
width: padded.bounds().width,
|
Rectangle {
|
||||||
..title_layout.bounds()
|
width: padded.bounds().width,
|
||||||
},
|
..title_layout.bounds()
|
||||||
None,
|
},
|
||||||
)
|
None,
|
||||||
};
|
)
|
||||||
|
};
|
||||||
|
|
||||||
renderer.draw_title_bar(
|
renderer.draw_title_bar(
|
||||||
defaults,
|
defaults,
|
||||||
|
Loading…
Reference in New Issue
Block a user