mirror of
https://github.com/emilk/egui.git
synced 2026-09-02 06:40:06 -04:00
Add Options::debug_paint_interactive_widgets (#4018)
This paints the rects of all interactive widgets on each layer. 
This commit is contained in:
@@ -1842,6 +1842,27 @@ impl Context {
|
|||||||
|
|
||||||
self.read(|ctx| ctx.plugins.clone()).on_end_frame(self);
|
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())
|
self.write(|ctx| ctx.end_frame())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -214,6 +214,9 @@ pub struct Options {
|
|||||||
///
|
///
|
||||||
/// By default this is `true` in debug builds.
|
/// By default this is `true` in debug builds.
|
||||||
pub warn_on_id_clash: bool,
|
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 {
|
impl Default for Options {
|
||||||
@@ -227,6 +230,7 @@ impl Default for Options {
|
|||||||
screen_reader: false,
|
screen_reader: false,
|
||||||
preload_font_glyphs: true,
|
preload_font_glyphs: true,
|
||||||
warn_on_id_clash: cfg!(debug_assertions),
|
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
|
screen_reader: _, // needs to come from the integration
|
||||||
preload_font_glyphs: _,
|
preload_font_glyphs: _,
|
||||||
warn_on_id_clash,
|
warn_on_id_clash,
|
||||||
|
debug_paint_interactive_widgets,
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
use crate::Widget as _;
|
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(warn_on_id_clash, "Warn if two widgets have the same Id");
|
||||||
|
|
||||||
|
ui.checkbox(debug_paint_interactive_widgets, "Debug interactive widgets");
|
||||||
});
|
});
|
||||||
|
|
||||||
use crate::containers::*;
|
use crate::containers::*;
|
||||||
|
|||||||
Reference in New Issue
Block a user