Add `Options::debug_paint_interactive_widgets` (#4018)

This paints the rects of all interactive widgets on each layer.


![image](https://github.com/emilk/egui/assets/1148717/3584c4fb-06ce-43d4-bd7c-c5baf927ddf1)
This commit is contained in:
Emil Ernerfeldt 2024-02-10 13:20:01 +01:00 committed by GitHub
parent 0bf3056bd7
commit 132d0ec430
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 28 additions and 0 deletions

View File

@ -1842,6 +1842,27 @@ impl Context {
self.read(|ctx| ctx.plugins.clone()).on_end_frame(self);
if self.options(|o| o.debug_paint_interactive_widgets) {
let rects = self.write(|ctx| ctx.viewport().layer_rects_this_frame.clone());
for (layer_id, rects) in rects.by_layer {
let painter = Painter::new(self.clone(), layer_id, Rect::EVERYTHING);
for rect in rects {
if rect.sense.interactive() {
let (color, text) = if rect.sense.click && rect.sense.drag {
(Color32::from_rgb(0x88, 0, 0x88), "click+drag")
} else if rect.sense.click {
(Color32::from_rgb(0x88, 0, 0), "click")
} else if rect.sense.drag {
(Color32::from_rgb(0, 0, 0x88), "drag")
} else {
(Color32::from_rgb(0, 0, 0x88), "hover")
};
painter.debug_rect(rect.rect, color, text);
}
}
}
}
self.write(|ctx| ctx.end_frame())
}
}

View File

@ -214,6 +214,9 @@ pub struct Options {
///
/// By default this is `true` in debug builds.
pub warn_on_id_clash: bool,
/// If true, paint all interactive widgets in the order they were added to each layer.
pub debug_paint_interactive_widgets: bool,
}
impl Default for Options {
@ -227,6 +230,7 @@ impl Default for Options {
screen_reader: false,
preload_font_glyphs: true,
warn_on_id_clash: cfg!(debug_assertions),
debug_paint_interactive_widgets: false,
}
}
}
@ -243,6 +247,7 @@ impl Options {
screen_reader: _, // needs to come from the integration
preload_font_glyphs: _,
warn_on_id_clash,
debug_paint_interactive_widgets,
} = self;
use crate::Widget as _;
@ -261,6 +266,8 @@ impl Options {
);
ui.checkbox(warn_on_id_clash, "Warn if two widgets have the same Id");
ui.checkbox(debug_paint_interactive_widgets, "Debug interactive widgets");
});
use crate::containers::*;