diff --git a/egui/src/containers/window.rs b/egui/src/containers/window.rs index e50c2553..f7eb650c 100644 --- a/egui/src/containers/window.rs +++ b/egui/src/containers/window.rs @@ -12,6 +12,7 @@ pub struct Window<'open> { pub frame: Option, pub resize: Resize, pub scroll: Option, + pub collapsible: bool, } impl<'open> Window<'open> { @@ -36,6 +37,7 @@ impl<'open> Window<'open> { .always_show_scroll(false) .max_height(f32::INFINITY), ), // As large as we can be + collapsible: true, } } @@ -109,6 +111,12 @@ impl<'open> Window<'open> { 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. pub fn auto_sized(mut self) -> Self { self.resize = self.resize.auto_sized(); @@ -145,6 +153,7 @@ impl<'open> Window<'open> { frame, resize, scroll, + collapsible, } = self; if matches!(open, Some(false)) { @@ -219,6 +228,7 @@ impl<'open> Window<'open> { show_close_button, collapsing_id, &mut collapsing, + collapsible, ); let content_rect = collapsing @@ -245,6 +255,7 @@ impl<'open> Window<'open> { content_rect, open, &mut collapsing, + collapsible, ); area_content_ui @@ -540,6 +551,7 @@ fn show_title_bar( show_close_button: bool, collapsing_id: Id, collapsing: &mut collapsing_header::State, + collapsible: bool, ) -> TitleBar { let title_bar_and_rect = ui.inner_layout(Layout::horizontal(Align::Center), |ui| { 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 button_size = ui.style().start_icon_width; - { + if collapsible { // TODO: make clickable radius larger ui.allocate_space(vec2(0.0, 0.0)); // HACK: will add left spacing @@ -598,6 +610,7 @@ impl TitleBar { content_rect: Option, open: Option<&mut bool>, collapsing: &mut collapsing_header::State, + collapsible: bool, ) { if let Some(content_rect) = content_rect { // Now we know how large we got to be: @@ -630,6 +643,7 @@ impl TitleBar { if ui .interact(self.rect, title_bar_id, Sense::click()) .double_clicked + && collapsible { collapsing.toggle(ui); }