Browse Source

Improve area introspection panel

pull/669/head
Emil Ernerfeldt 3 years ago
parent
commit
1a177f7ecd
  1. 35
      egui/src/context.rs
  2. 3
      egui/src/id.rs
  3. 21
      egui/src/layers.rs
  4. 7
      egui/src/memory.rs

35
egui/src/context.rs

@ -722,6 +722,7 @@ impl Context {
}
}
/// Top-most layer at the given position.
pub fn layer_id_at(&self, pos: Pos2) -> Option<LayerId> {
let resize_grab_radius_side = self.style().interaction.resize_grab_radius_side;
self.memory().layer_id_at(pos, resize_grab_radius_side)
@ -823,7 +824,7 @@ impl Context {
))
.on_hover_text("Is egui currently listening for text input?");
ui.label(format!(
"keyboard focus widget: {}",
"Keyboard focus widget: {}",
self.memory()
.interaction
.focus
@ -833,6 +834,22 @@ impl Context {
.unwrap_or_default()
))
.on_hover_text("Is egui currently listening for text input?");
let pointer_pos = self
.input()
.pointer
.hover_pos()
.map_or_else(String::new, |pos| format!("{:?}", pos));
ui.label(format!("Pointer pos: {}", pointer_pos));
let top_layer = self
.input()
.pointer
.hover_pos()
.and_then(|pos| self.layer_id_at(pos))
.map_or_else(String::new, |layer| layer.short_debug_format());
ui.label(format!("Top layer under mouse: {}", top_layer));
ui.add_space(16.0);
ui.label(format!(
@ -864,7 +881,7 @@ impl Context {
ui.horizontal(|ui| {
ui.label(format!(
"{} areas (window positions)",
"{} areas (panels, windows, popups, …)",
self.memory().areas.count()
));
if ui.button("Reset").clicked() {
@ -872,18 +889,20 @@ impl Context {
}
});
ui.indent("areas", |ui| {
ui.label("Visible areas, ordered back to front.");
ui.label("Hover to highlight");
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 !is_visible {
continue;
}
let text = format!("{} - {:?}", layer_id.short_debug_format(), area.rect(),);
// TODO: `Sense::hover_highlight()`
if ui
.label(format!(
"{:?} {:?} {}",
layer_id.order,
area.rect(),
if is_visible { "" } else { "(INVISIBLE)" }
))
.add(Label::new(text).monospace().sense(Sense::click()))
.hovered
&& is_visible
{

3
egui/src/id.rs

@ -57,7 +57,8 @@ impl Id {
Id(hasher.finish())
}
pub(crate) fn short_debug_format(&self) -> String {
/// Short and readable summary
pub fn short_debug_format(&self) -> String {
format!("{:04X}", self.0 as u16)
}

21
egui/src/layers.rs

@ -48,6 +48,18 @@ impl Order {
Self::Tooltip => false,
}
}
/// Short and readable summary
pub fn short_debug_format(&self) -> &'static str {
match self {
Self::Background => "backg",
Self::PanelResizeLine => "panel",
Self::Middle => "middl",
Self::Foreground => "foreg",
Self::Tooltip => "toolt",
Self::Debug => "debug",
}
}
}
/// An identifier for a paint layer.
@ -82,6 +94,15 @@ impl LayerId {
pub fn allow_interaction(&self) -> bool {
self.order.allow_interaction()
}
/// Short and readable summary
pub fn short_debug_format(&self) -> String {
format!(
"{} {}",
self.order.short_debug_format(),
self.id.short_debug_format()
)
}
}
/// A unique identifier of a specific [`Shape`] in a [`PaintList`].

7
egui/src/memory.rs

@ -291,6 +291,7 @@ impl Memory {
self.drag_value.end_frame(input);
}
/// Top-most layer at the given position.
pub fn layer_id_at(&self, pos: Pos2, resize_interact_radius_side: f32) -> Option<LayerId> {
self.areas.layer_id_at(pos, resize_interact_radius_side)
}
@ -435,7 +436,7 @@ impl Memory {
#[cfg_attr(feature = "persistence", serde(default))]
pub struct Areas {
areas: HashMap<Id, area::State>,
/// Top is last
/// Back-to-front. Top is last.
order: Vec<LayerId>,
visible_last_frame: HashSet<LayerId>,
visible_current_frame: HashSet<LayerId>,
@ -457,6 +458,7 @@ impl Areas {
self.areas.get(&id)
}
/// Back-to-front. Top is last.
pub(crate) fn order(&self) -> &[LayerId] {
&self.order
}
@ -469,11 +471,12 @@ impl Areas {
}
}
/// Top-most layer at the given position.
pub fn layer_id_at(&self, pos: Pos2, resize_interact_radius_side: f32) -> Option<LayerId> {
for layer in self.order.iter().rev() {
if self.is_visible(layer) {
if let Some(state) = self.areas.get(&layer.id) {
let mut rect = Rect::from_min_size(state.pos, state.size);
let mut rect = state.rect();
if state.interactable {
// Allow us to resize by dragging just outside the window:
rect = rect.expand(resize_interact_radius_side);

Loading…
Cancel
Save