From 9874921d062d725eae0094ed4c4ec44b417acbd1 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sat, 10 Oct 2020 06:57:56 +0200 Subject: [PATCH] [bench] benchmark demo app when everything is open --- egui/benches/benchmark.rs | 16 +++++++++++++++- egui/src/containers/collapsing_header.rs | 16 ++++++++++------ egui/src/containers/window.rs | 7 ++++--- egui/src/memory.rs | 7 +++++++ egui/src/menu.rs | 2 +- 5 files changed, 37 insertions(+), 11 deletions(-) diff --git a/egui/benches/benchmark.rs b/egui/benches/benchmark.rs index c295e020..7213be20 100644 --- a/egui/benches/benchmark.rs +++ b/egui/benches/benchmark.rs @@ -10,7 +10,21 @@ pub fn criterion_benchmark(c: &mut Criterion) { let mut ctx = egui::Context::new(); let mut demo_app = egui::demos::DemoApp::default(); - c.bench_function("demo_app", |b| { + c.bench_function("demo_app_minimal", |b| { + b.iter(|| { + let mut ui = ctx.begin_frame(raw_input.clone()); + demo_app.ui(&mut ui, &Default::default()); + ctx.end_frame() + }) + }); + } + + { + let mut ctx = egui::Context::new(); + ctx.memory().all_collpasing_are_open = true; // expand the demo window with everything + let mut demo_app = egui::demos::DemoApp::default(); + + c.bench_function("demo_app_full", |b| { b.iter(|| { let mut ui = ctx.begin_frame(raw_input.clone()); demo_app.ui(&mut ui, &Default::default()); diff --git a/egui/src/containers/collapsing_header.rs b/egui/src/containers/collapsing_header.rs index cc958972..54aa1375 100644 --- a/egui/src/containers/collapsing_header.rs +++ b/egui/src/containers/collapsing_header.rs @@ -36,10 +36,14 @@ impl State { // Helper pub fn is_open(ctx: &Context, id: Id) -> Option { - ctx.memory() - .collapsing_headers - .get(&id) - .map(|state| state.open) + if ctx.memory().all_collpasing_are_open { + Some(true) + } else { + ctx.memory() + .collapsing_headers + .get(&id) + .map(|state| state.open) + } } pub fn toggle(&mut self, ui: &Ui) { @@ -49,7 +53,7 @@ impl State { /// 0 for closed, 1 for open, with tweening pub fn openness(&self, ctx: &Context, id: Id) -> f32 { - ctx.animate_bool(id, self.open) + ctx.animate_bool(id, self.open || ctx.memory().all_collpasing_are_open) } /// Show contents if we are open, with a nice animation between closed and open @@ -91,7 +95,7 @@ impl State { child_ui.force_set_min_rect(min_rect); r })) - } else if self.open { + } else if self.open || ui.memory().all_collpasing_are_open { let ret_rect = ui.add_custom(add_contents); let full_size = ret_rect.1.size(); self.open_height = Some(full_size.y); diff --git a/egui/src/containers/window.rs b/egui/src/containers/window.rs index ed89ec4e..d155eba8 100644 --- a/egui/src/containers/window.rs +++ b/egui/src/containers/window.rs @@ -192,7 +192,7 @@ impl<'open> Window<'open> { collapsible, } = self; - if matches!(open, Some(false)) { + if matches!(open, Some(false)) && !ctx.memory().all_windows_are_open { return None; } @@ -201,10 +201,11 @@ impl<'open> Window<'open> { let resize_id = window_id.with("resize"); let collapsing_id = window_id.with("collapsing"); + let is_maximized = + collapsing_header::State::is_open(ctx, collapsing_id).unwrap_or_default(); let possible = PossibleInteractions { movable: area.is_movable(), - resizable: resize.is_resizable() - && collapsing_header::State::is_open(ctx, collapsing_id).unwrap_or_default(), + resizable: resize.is_resizable() && is_maximized, }; let area = area.movable(false); // We move it manually diff --git a/egui/src/memory.rs b/egui/src/memory.rs index 017120ba..b1182c1a 100644 --- a/egui/src/memory.rs +++ b/egui/src/memory.rs @@ -49,6 +49,13 @@ pub struct Memory { /// Could be a combo box, color picker, menu etc. #[cfg_attr(feature = "serde", serde(skip))] popup: Option, + + /// Useful for debugging, benchmarking etc. + pub all_collpasing_are_open: bool, + /// Useful for debugging, benchmarking etc. + pub all_menues_are_open: bool, + /// Useful for debugging, benchmarking etc. + pub all_windows_are_open: bool, } /// Say there is a button in a scroll area. diff --git a/egui/src/menu.rs b/egui/src/menu.rs index 5defb1af..626d9f40 100644 --- a/egui/src/menu.rs +++ b/egui/src/menu.rs @@ -93,7 +93,7 @@ fn menu_impl<'c>( bar_state.open_menu = Some(menu_id); } - if bar_state.open_menu == Some(menu_id) { + if bar_state.open_menu == Some(menu_id) || ui.memory().all_menues_are_open { let area = Area::new(menu_id) .order(Order::Foreground) .fixed_pos(button_response.rect.left_bottom());