[demo] Improve introspection UI of areas
This commit is contained in:
parent
3416f3b91f
commit
f86cb4a923
2 changed files with 53 additions and 26 deletions
|
@ -599,12 +599,14 @@ impl Context {
|
||||||
ui.advance_cursor(16.0);
|
ui.advance_cursor(16.0);
|
||||||
|
|
||||||
CollapsingHeader::new("Input")
|
CollapsingHeader::new("Input")
|
||||||
.default_open(true)
|
.default_open(false)
|
||||||
.show(ui, |ui| ui.input().clone().ui(ui));
|
.show(ui, |ui| ui.input().clone().ui(ui));
|
||||||
|
|
||||||
ui.collapsing("Paint stats", |ui| {
|
CollapsingHeader::new("Paint stats")
|
||||||
self.paint_stats.lock().ui(ui);
|
.default_open(true)
|
||||||
});
|
.show(ui, |ui| {
|
||||||
|
self.paint_stats.lock().ui(ui);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn memory_ui(&self, ui: &mut crate::Ui) {
|
pub fn memory_ui(&self, ui: &mut crate::Ui) {
|
||||||
|
@ -625,6 +627,29 @@ impl Context {
|
||||||
self.memory().areas = Default::default();
|
self.memory().areas = Default::default();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
ui.indent("areas", |ui| {
|
||||||
|
let layers_ids: Vec<LayerId> = 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.horizontal(|ui| {
|
||||||
ui.label(format!(
|
ui.label(format!(
|
||||||
|
|
|
@ -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<Id, area::State>,
|
|
||||||
/// Top is last
|
|
||||||
order: Vec<LayerId>,
|
|
||||||
visible_last_frame: HashSet<LayerId>,
|
|
||||||
visible_current_frame: HashSet<LayerId>,
|
|
||||||
|
|
||||||
/// 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<LayerId>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Memory {
|
impl Memory {
|
||||||
pub(crate) fn begin_frame(&mut self, prev_input: &crate::input::InputState) {
|
pub(crate) fn begin_frame(&mut self, prev_input: &crate::input::InputState) {
|
||||||
self.interaction.begin_frame(prev_input);
|
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<Id, area::State>,
|
||||||
|
/// Top is last
|
||||||
|
order: Vec<LayerId>,
|
||||||
|
visible_last_frame: HashSet<LayerId>,
|
||||||
|
visible_current_frame: HashSet<LayerId>,
|
||||||
|
|
||||||
|
/// 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<LayerId>,
|
||||||
|
}
|
||||||
|
|
||||||
impl Areas {
|
impl Areas {
|
||||||
pub(crate) fn count(&self) -> usize {
|
pub(crate) fn count(&self) -> usize {
|
||||||
self.areas.len()
|
self.areas.len()
|
||||||
|
@ -211,8 +213,8 @@ impl Areas {
|
||||||
|
|
||||||
pub(crate) fn set_state(&mut self, layer_id: LayerId, state: area::State) {
|
pub(crate) fn set_state(&mut self, layer_id: LayerId, state: area::State) {
|
||||||
self.visible_current_frame.insert(layer_id);
|
self.visible_current_frame.insert(layer_id);
|
||||||
let did_insert = self.areas.insert(layer_id.id, state).is_none();
|
self.areas.insert(layer_id.id, state);
|
||||||
if did_insert {
|
if self.order.iter().find(|x| **x == layer_id).is_none() {
|
||||||
self.order.push(layer_id);
|
self.order.push(layer_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue