Add collapsible
to Window (#15)
This lets the user decide whether the Window can be collapsed or not. The default is `true` (window is collapsible), but calling `window.collapsible(false)` will hide the collapsing triangle icon and prevent the window from being collapsed by clicking on the title.
This commit is contained in:
parent
40af177157
commit
e26150e46f
1 changed files with 15 additions and 1 deletions
|
@ -12,6 +12,7 @@ pub struct Window<'open> {
|
||||||
pub frame: Option<Frame>,
|
pub frame: Option<Frame>,
|
||||||
pub resize: Resize,
|
pub resize: Resize,
|
||||||
pub scroll: Option<ScrollArea>,
|
pub scroll: Option<ScrollArea>,
|
||||||
|
pub collapsible: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'open> Window<'open> {
|
impl<'open> Window<'open> {
|
||||||
|
@ -36,6 +37,7 @@ impl<'open> Window<'open> {
|
||||||
.always_show_scroll(false)
|
.always_show_scroll(false)
|
||||||
.max_height(f32::INFINITY),
|
.max_height(f32::INFINITY),
|
||||||
), // As large as we can be
|
), // As large as we can be
|
||||||
|
collapsible: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,6 +111,12 @@ impl<'open> Window<'open> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Can the window be collapsed by clicking on its title?
|
||||||
|
pub fn collapsible(mut self, collapsible: bool) -> Self {
|
||||||
|
self.collapsible = collapsible;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Not resizable, just takes the size of its contents.
|
/// Not resizable, just takes the size of its contents.
|
||||||
pub fn auto_sized(mut self) -> Self {
|
pub fn auto_sized(mut self) -> Self {
|
||||||
self.resize = self.resize.auto_sized();
|
self.resize = self.resize.auto_sized();
|
||||||
|
@ -145,6 +153,7 @@ impl<'open> Window<'open> {
|
||||||
frame,
|
frame,
|
||||||
resize,
|
resize,
|
||||||
scroll,
|
scroll,
|
||||||
|
collapsible,
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
if matches!(open, Some(false)) {
|
if matches!(open, Some(false)) {
|
||||||
|
@ -219,6 +228,7 @@ impl<'open> Window<'open> {
|
||||||
show_close_button,
|
show_close_button,
|
||||||
collapsing_id,
|
collapsing_id,
|
||||||
&mut collapsing,
|
&mut collapsing,
|
||||||
|
collapsible,
|
||||||
);
|
);
|
||||||
|
|
||||||
let content_rect = collapsing
|
let content_rect = collapsing
|
||||||
|
@ -245,6 +255,7 @@ impl<'open> Window<'open> {
|
||||||
content_rect,
|
content_rect,
|
||||||
open,
|
open,
|
||||||
&mut collapsing,
|
&mut collapsing,
|
||||||
|
collapsible,
|
||||||
);
|
);
|
||||||
|
|
||||||
area_content_ui
|
area_content_ui
|
||||||
|
@ -540,6 +551,7 @@ fn show_title_bar(
|
||||||
show_close_button: bool,
|
show_close_button: bool,
|
||||||
collapsing_id: Id,
|
collapsing_id: Id,
|
||||||
collapsing: &mut collapsing_header::State,
|
collapsing: &mut collapsing_header::State,
|
||||||
|
collapsible: bool,
|
||||||
) -> TitleBar {
|
) -> TitleBar {
|
||||||
let title_bar_and_rect = ui.inner_layout(Layout::horizontal(Align::Center), |ui| {
|
let title_bar_and_rect = ui.inner_layout(Layout::horizontal(Align::Center), |ui| {
|
||||||
ui.set_desired_height(title_label.font_height(ui.fonts()));
|
ui.set_desired_height(title_label.font_height(ui.fonts()));
|
||||||
|
@ -547,7 +559,7 @@ fn show_title_bar(
|
||||||
let item_spacing = ui.style().item_spacing;
|
let item_spacing = ui.style().item_spacing;
|
||||||
let button_size = ui.style().start_icon_width;
|
let button_size = ui.style().start_icon_width;
|
||||||
|
|
||||||
{
|
if collapsible {
|
||||||
// TODO: make clickable radius larger
|
// TODO: make clickable radius larger
|
||||||
ui.allocate_space(vec2(0.0, 0.0)); // HACK: will add left spacing
|
ui.allocate_space(vec2(0.0, 0.0)); // HACK: will add left spacing
|
||||||
|
|
||||||
|
@ -598,6 +610,7 @@ impl TitleBar {
|
||||||
content_rect: Option<Rect>,
|
content_rect: Option<Rect>,
|
||||||
open: Option<&mut bool>,
|
open: Option<&mut bool>,
|
||||||
collapsing: &mut collapsing_header::State,
|
collapsing: &mut collapsing_header::State,
|
||||||
|
collapsible: bool,
|
||||||
) {
|
) {
|
||||||
if let Some(content_rect) = content_rect {
|
if let Some(content_rect) = content_rect {
|
||||||
// Now we know how large we got to be:
|
// Now we know how large we got to be:
|
||||||
|
@ -630,6 +643,7 @@ impl TitleBar {
|
||||||
if ui
|
if ui
|
||||||
.interact(self.rect, title_bar_id, Sense::click())
|
.interact(self.rect, title_bar_id, Sense::click())
|
||||||
.double_clicked
|
.double_clicked
|
||||||
|
&& collapsible
|
||||||
{
|
{
|
||||||
collapsing.toggle(ui);
|
collapsing.toggle(ui);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue