[bench] benchmark demo app when everything is open
This commit is contained in:
parent
f30b354f77
commit
9874921d06
5 changed files with 37 additions and 11 deletions
|
@ -10,7 +10,21 @@ pub fn criterion_benchmark(c: &mut Criterion) {
|
||||||
let mut ctx = egui::Context::new();
|
let mut ctx = egui::Context::new();
|
||||||
let mut demo_app = egui::demos::DemoApp::default();
|
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(|| {
|
b.iter(|| {
|
||||||
let mut ui = ctx.begin_frame(raw_input.clone());
|
let mut ui = ctx.begin_frame(raw_input.clone());
|
||||||
demo_app.ui(&mut ui, &Default::default());
|
demo_app.ui(&mut ui, &Default::default());
|
||||||
|
|
|
@ -36,11 +36,15 @@ impl State {
|
||||||
|
|
||||||
// Helper
|
// Helper
|
||||||
pub fn is_open(ctx: &Context, id: Id) -> Option<bool> {
|
pub fn is_open(ctx: &Context, id: Id) -> Option<bool> {
|
||||||
|
if ctx.memory().all_collpasing_are_open {
|
||||||
|
Some(true)
|
||||||
|
} else {
|
||||||
ctx.memory()
|
ctx.memory()
|
||||||
.collapsing_headers
|
.collapsing_headers
|
||||||
.get(&id)
|
.get(&id)
|
||||||
.map(|state| state.open)
|
.map(|state| state.open)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn toggle(&mut self, ui: &Ui) {
|
pub fn toggle(&mut self, ui: &Ui) {
|
||||||
self.open = !self.open;
|
self.open = !self.open;
|
||||||
|
@ -49,7 +53,7 @@ impl State {
|
||||||
|
|
||||||
/// 0 for closed, 1 for open, with tweening
|
/// 0 for closed, 1 for open, with tweening
|
||||||
pub fn openness(&self, ctx: &Context, id: Id) -> f32 {
|
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
|
/// 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);
|
child_ui.force_set_min_rect(min_rect);
|
||||||
r
|
r
|
||||||
}))
|
}))
|
||||||
} else if self.open {
|
} else if self.open || ui.memory().all_collpasing_are_open {
|
||||||
let ret_rect = ui.add_custom(add_contents);
|
let ret_rect = ui.add_custom(add_contents);
|
||||||
let full_size = ret_rect.1.size();
|
let full_size = ret_rect.1.size();
|
||||||
self.open_height = Some(full_size.y);
|
self.open_height = Some(full_size.y);
|
||||||
|
|
|
@ -192,7 +192,7 @@ impl<'open> Window<'open> {
|
||||||
collapsible,
|
collapsible,
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
if matches!(open, Some(false)) {
|
if matches!(open, Some(false)) && !ctx.memory().all_windows_are_open {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,10 +201,11 @@ impl<'open> Window<'open> {
|
||||||
let resize_id = window_id.with("resize");
|
let resize_id = window_id.with("resize");
|
||||||
let collapsing_id = window_id.with("collapsing");
|
let collapsing_id = window_id.with("collapsing");
|
||||||
|
|
||||||
|
let is_maximized =
|
||||||
|
collapsing_header::State::is_open(ctx, collapsing_id).unwrap_or_default();
|
||||||
let possible = PossibleInteractions {
|
let possible = PossibleInteractions {
|
||||||
movable: area.is_movable(),
|
movable: area.is_movable(),
|
||||||
resizable: resize.is_resizable()
|
resizable: resize.is_resizable() && is_maximized,
|
||||||
&& collapsing_header::State::is_open(ctx, collapsing_id).unwrap_or_default(),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let area = area.movable(false); // We move it manually
|
let area = area.movable(false); // We move it manually
|
||||||
|
|
|
@ -49,6 +49,13 @@ pub struct Memory {
|
||||||
/// Could be a combo box, color picker, menu etc.
|
/// Could be a combo box, color picker, menu etc.
|
||||||
#[cfg_attr(feature = "serde", serde(skip))]
|
#[cfg_attr(feature = "serde", serde(skip))]
|
||||||
popup: Option<Id>,
|
popup: Option<Id>,
|
||||||
|
|
||||||
|
/// 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.
|
/// Say there is a button in a scroll area.
|
||||||
|
|
|
@ -93,7 +93,7 @@ fn menu_impl<'c>(
|
||||||
bar_state.open_menu = Some(menu_id);
|
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)
|
let area = Area::new(menu_id)
|
||||||
.order(Order::Foreground)
|
.order(Order::Foreground)
|
||||||
.fixed_pos(button_response.rect.left_bottom());
|
.fixed_pos(button_response.rect.left_bottom());
|
||||||
|
|
Loading…
Reference in a new issue