window starting collapsed state (#2539)

This commit is contained in:
joffreybesos 2023-01-08 06:48:49 +11:00 committed by GitHub
parent e70204d726
commit f7ed135192
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -30,6 +30,7 @@ pub struct Window<'open> {
resize: Resize, resize: Resize,
scroll: ScrollArea, scroll: ScrollArea,
collapsible: bool, collapsible: bool,
default_open: bool,
with_title_bar: bool, with_title_bar: bool,
} }
@ -51,6 +52,7 @@ impl<'open> Window<'open> {
.default_size([340.0, 420.0]), // Default inner size of a window .default_size([340.0, 420.0]), // Default inner size of a window
scroll: ScrollArea::neither(), scroll: ScrollArea::neither(),
collapsible: true, collapsible: true,
default_open: true,
with_title_bar: true, with_title_bar: true,
} }
} }
@ -162,6 +164,12 @@ impl<'open> Window<'open> {
self 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. /// Set initial size of the window.
pub fn default_size(mut self, default_size: impl Into<Vec2>) -> Self { pub fn default_size(mut self, default_size: impl Into<Vec2>) -> Self {
self.resize = self.resize.default_size(default_size); self.resize = self.resize.default_size(default_size);
@ -275,6 +283,7 @@ impl<'open> Window<'open> {
resize, resize,
scroll, scroll,
collapsible, collapsible,
default_open,
with_title_bar, with_title_bar,
} = self; } = self;
@ -291,7 +300,7 @@ impl<'open> Window<'open> {
let area_layer_id = area.layer(); let area_layer_id = area.layer();
let resize_id = area_id.with("resize"); let resize_id = area_id.with("resize");
let mut collapsing = 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 is_collapsed = with_title_bar && !collapsing.is_open();
let possible = PossibleInteractions::new(&area, &resize, is_collapsed); let possible = PossibleInteractions::new(&area, &resize, is_collapsed);