From f86cb4a92343577a3bcf605d501b3a2af8623d56 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sat, 24 Oct 2020 10:31:38 +0200 Subject: [PATCH] [demo] Improve introspection UI of areas --- egui/src/context.rs | 33 ++++++++++++++++++++++++++++---- egui/src/memory.rs | 46 +++++++++++++++++++++++---------------------- 2 files changed, 53 insertions(+), 26 deletions(-) diff --git a/egui/src/context.rs b/egui/src/context.rs index 3d6d162b..06f8bae5 100644 --- a/egui/src/context.rs +++ b/egui/src/context.rs @@ -599,12 +599,14 @@ impl Context { ui.advance_cursor(16.0); CollapsingHeader::new("Input") - .default_open(true) + .default_open(false) .show(ui, |ui| ui.input().clone().ui(ui)); - ui.collapsing("Paint stats", |ui| { - self.paint_stats.lock().ui(ui); - }); + CollapsingHeader::new("Paint stats") + .default_open(true) + .show(ui, |ui| { + self.paint_stats.lock().ui(ui); + }); } pub fn memory_ui(&self, ui: &mut crate::Ui) { @@ -625,6 +627,29 @@ impl Context { self.memory().areas = Default::default(); } }); + ui.indent("areas", |ui| { + let layers_ids: Vec = self.memory().areas.order().to_vec(); + for layer_id in layers_ids { + let area = self.memory().areas.get(layer_id.id).cloned(); + if let Some(area) = area { + let is_visible = self.memory().areas.is_visible(&layer_id); + if ui + .label(format!( + "{:?} {:?} {}", + layer_id.order, + area.rect(), + if is_visible { "" } else { "(INVISIBLE)" } + )) + .hovered + && is_visible + { + ui.ctx() + .debug_painter() + .debug_rect(area.rect(), color::RED, ""); + } + } + } + }); ui.horizontal(|ui| { ui.label(format!( diff --git a/egui/src/memory.rs b/egui/src/memory.rs index 6c5cefeb..900d6f12 100644 --- a/egui/src/memory.rs +++ b/egui/src/memory.rs @@ -113,26 +113,6 @@ impl Interaction { } } -/// Keeps track of `Area`s, which are free-floating `Ui`s. -/// These `Area`s can be in any `Order`. -#[derive(Clone, Debug, Default)] -#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] -#[cfg_attr(feature = "serde", serde(default))] -pub struct Areas { - areas: HashMap, - /// Top is last - order: Vec, - visible_last_frame: HashSet, - visible_current_frame: HashSet, - - /// When an area want to be on top, it is put in here. - /// At the end of the frame, this is used to reorder the layers. - /// This means if several layers want to be on top, they will keep their relative order. - /// So if you close three windows and then reopen them all in one frame, - /// they will all be sent to the top, but keep their previous internal order. - wants_to_be_on_top: HashSet, -} - impl Memory { pub(crate) fn begin_frame(&mut self, prev_input: &crate::input::InputState) { self.interaction.begin_frame(prev_input); @@ -196,6 +176,28 @@ impl Memory { } } +// ---------------------------------------------------------------------------- + +/// Keeps track of `Area`s, which are free-floating `Ui`s. +/// These `Area`s can be in any `Order`. +#[derive(Clone, Debug, Default)] +#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] +#[cfg_attr(feature = "serde", serde(default))] +pub struct Areas { + areas: HashMap, + /// Top is last + order: Vec, + visible_last_frame: HashSet, + visible_current_frame: HashSet, + + /// When an area want to be on top, it is put in here. + /// At the end of the frame, this is used to reorder the layers. + /// This means if several layers want to be on top, they will keep their relative order. + /// So if you close three windows and then reopen them all in one frame, + /// they will all be sent to the top, but keep their previous internal order. + wants_to_be_on_top: HashSet, +} + impl Areas { pub(crate) fn count(&self) -> usize { self.areas.len() @@ -211,8 +213,8 @@ impl Areas { pub(crate) fn set_state(&mut self, layer_id: LayerId, state: area::State) { self.visible_current_frame.insert(layer_id); - let did_insert = self.areas.insert(layer_id.id, state).is_none(); - if did_insert { + self.areas.insert(layer_id.id, state); + if self.order.iter().find(|x| **x == layer_id).is_none() { self.order.push(layer_id); } }