Skip to content

Commit

Permalink
window starting collapsed state (#2539)
Browse files Browse the repository at this point in the history
  • Loading branch information
joffreybesos authored Jan 7, 2023
1 parent e70204d commit f7ed135
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion crates/egui/src/containers/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub struct Window<'open> {
resize: Resize,
scroll: ScrollArea,
collapsible: bool,
default_open: bool,
with_title_bar: bool,
}

Expand All @@ -51,6 +52,7 @@ impl<'open> Window<'open> {
.default_size([340.0, 420.0]), // Default inner size of a window
scroll: ScrollArea::neither(),
collapsible: true,
default_open: true,
with_title_bar: true,
}
}
Expand Down Expand Up @@ -162,6 +164,12 @@ impl<'open> Window<'open> {
self
}

/// Set initial collapsed state of the window
pub fn default_open(mut self, default_open: bool) -> Self {
self.default_open = default_open;
self
}

/// Set initial size of the window.
pub fn default_size(mut self, default_size: impl Into<Vec2>) -> Self {
self.resize = self.resize.default_size(default_size);
Expand Down Expand Up @@ -275,6 +283,7 @@ impl<'open> Window<'open> {
resize,
scroll,
collapsible,
default_open,
with_title_bar,
} = self;

Expand All @@ -291,7 +300,7 @@ impl<'open> Window<'open> {
let area_layer_id = area.layer();
let resize_id = area_id.with("resize");
let mut collapsing =
CollapsingState::load_with_default_open(ctx, area_id.with("collapsing"), true);
CollapsingState::load_with_default_open(ctx, area_id.with("collapsing"), default_open);

let is_collapsed = with_title_bar && !collapsing.is_open();
let possible = PossibleInteractions::new(&area, &resize, is_collapsed);
Expand Down

0 comments on commit f7ed135

Please sign in to comment.