Improve area introspection panel
This commit is contained in:
parent
56913a9ae9
commit
1a177f7ecd
4 changed files with 55 additions and 11 deletions
|
@ -722,6 +722,7 @@ impl Context {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Top-most layer at the given position.
|
||||||
pub fn layer_id_at(&self, pos: Pos2) -> Option<LayerId> {
|
pub fn layer_id_at(&self, pos: Pos2) -> Option<LayerId> {
|
||||||
let resize_grab_radius_side = self.style().interaction.resize_grab_radius_side;
|
let resize_grab_radius_side = self.style().interaction.resize_grab_radius_side;
|
||||||
self.memory().layer_id_at(pos, 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?");
|
.on_hover_text("Is egui currently listening for text input?");
|
||||||
ui.label(format!(
|
ui.label(format!(
|
||||||
"keyboard focus widget: {}",
|
"Keyboard focus widget: {}",
|
||||||
self.memory()
|
self.memory()
|
||||||
.interaction
|
.interaction
|
||||||
.focus
|
.focus
|
||||||
|
@ -833,6 +834,22 @@ impl Context {
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
))
|
))
|
||||||
.on_hover_text("Is egui currently listening for text input?");
|
.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.add_space(16.0);
|
||||||
|
|
||||||
ui.label(format!(
|
ui.label(format!(
|
||||||
|
@ -864,7 +881,7 @@ impl Context {
|
||||||
|
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.label(format!(
|
ui.label(format!(
|
||||||
"{} areas (window positions)",
|
"{} areas (panels, windows, popups, …)",
|
||||||
self.memory().areas.count()
|
self.memory().areas.count()
|
||||||
));
|
));
|
||||||
if ui.button("Reset").clicked() {
|
if ui.button("Reset").clicked() {
|
||||||
|
@ -872,18 +889,20 @@ impl Context {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
ui.indent("areas", |ui| {
|
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();
|
let layers_ids: Vec<LayerId> = self.memory().areas.order().to_vec();
|
||||||
for layer_id in layers_ids {
|
for layer_id in layers_ids {
|
||||||
let area = self.memory().areas.get(layer_id.id).cloned();
|
let area = self.memory().areas.get(layer_id.id).cloned();
|
||||||
if let Some(area) = area {
|
if let Some(area) = area {
|
||||||
let is_visible = self.memory().areas.is_visible(&layer_id);
|
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
|
if ui
|
||||||
.label(format!(
|
.add(Label::new(text).monospace().sense(Sense::click()))
|
||||||
"{:?} {:?} {}",
|
|
||||||
layer_id.order,
|
|
||||||
area.rect(),
|
|
||||||
if is_visible { "" } else { "(INVISIBLE)" }
|
|
||||||
))
|
|
||||||
.hovered
|
.hovered
|
||||||
&& is_visible
|
&& is_visible
|
||||||
{
|
{
|
||||||
|
|
|
@ -57,7 +57,8 @@ impl Id {
|
||||||
Id(hasher.finish())
|
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)
|
format!("{:04X}", self.0 as u16)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,18 @@ impl Order {
|
||||||
Self::Tooltip => false,
|
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.
|
/// An identifier for a paint layer.
|
||||||
|
@ -82,6 +94,15 @@ impl LayerId {
|
||||||
pub fn allow_interaction(&self) -> bool {
|
pub fn allow_interaction(&self) -> bool {
|
||||||
self.order.allow_interaction()
|
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`].
|
/// A unique identifier of a specific [`Shape`] in a [`PaintList`].
|
||||||
|
|
|
@ -291,6 +291,7 @@ impl Memory {
|
||||||
self.drag_value.end_frame(input);
|
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> {
|
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)
|
self.areas.layer_id_at(pos, resize_interact_radius_side)
|
||||||
}
|
}
|
||||||
|
@ -435,7 +436,7 @@ impl Memory {
|
||||||
#[cfg_attr(feature = "persistence", serde(default))]
|
#[cfg_attr(feature = "persistence", serde(default))]
|
||||||
pub struct Areas {
|
pub struct Areas {
|
||||||
areas: HashMap<Id, area::State>,
|
areas: HashMap<Id, area::State>,
|
||||||
/// Top is last
|
/// Back-to-front. Top is last.
|
||||||
order: Vec<LayerId>,
|
order: Vec<LayerId>,
|
||||||
visible_last_frame: HashSet<LayerId>,
|
visible_last_frame: HashSet<LayerId>,
|
||||||
visible_current_frame: HashSet<LayerId>,
|
visible_current_frame: HashSet<LayerId>,
|
||||||
|
@ -457,6 +458,7 @@ impl Areas {
|
||||||
self.areas.get(&id)
|
self.areas.get(&id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Back-to-front. Top is last.
|
||||||
pub(crate) fn order(&self) -> &[LayerId] {
|
pub(crate) fn order(&self) -> &[LayerId] {
|
||||||
&self.order
|
&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> {
|
pub fn layer_id_at(&self, pos: Pos2, resize_interact_radius_side: f32) -> Option<LayerId> {
|
||||||
for layer in self.order.iter().rev() {
|
for layer in self.order.iter().rev() {
|
||||||
if self.is_visible(layer) {
|
if self.is_visible(layer) {
|
||||||
if let Some(state) = self.areas.get(&layer.id) {
|
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 {
|
if state.interactable {
|
||||||
// Allow us to resize by dragging just outside the window:
|
// Allow us to resize by dragging just outside the window:
|
||||||
rect = rect.expand(resize_interact_radius_side);
|
rect = rect.expand(resize_interact_radius_side);
|
||||||
|
|
Loading…
Reference in a new issue