Skip to content

Commit

Permalink
Add Options::debug_paint_interactive_widgets (#4018)
Browse files Browse the repository at this point in the history
This paints the rects of all interactive widgets on each layer.


![image](https://github.com/emilk/egui/assets/1148717/3584c4fb-06ce-43d4-bd7c-c5baf927ddf1)
  • Loading branch information
emilk authored Feb 10, 2024
1 parent 0bf3056 commit 132d0ec
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
21 changes: 21 additions & 0 deletions crates/egui/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
Expand Down
7 changes: 7 additions & 0 deletions crates/egui/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
}
}
}
Expand All @@ -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 _;
Expand All @@ -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::*;
Expand Down

0 comments on commit 132d0ec

Please sign in to comment.