Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Response::paint_debug_info() to make it easy to visualize a widget's id and state #4056

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions crates/egui/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,30 @@ impl Response {
pub fn context_menu(&self, add_contents: impl FnOnce(&mut Ui)) -> Option<InnerResponse<()>> {
menu::context_menu(self, add_contents)
}

/// Draw a debug rectangle over the response displaying the response's id and whether it is
/// enabled and/or hovered.
///
/// This function is intended for debugging purpose and can be useful, for example, in case of
/// widget id instability.
///
/// Color code:
/// - Blue: Enabled but not hovered
/// - Green: Enabled and hovered
/// - Red: Disabled
pub fn paint_debug_info(&self) {
self.ctx.debug_painter().debug_rect(
self.rect,
if self.hovered {
crate::Color32::DARK_GREEN
} else if self.enabled {
crate::Color32::BLUE
} else {
crate::Color32::RED
},
format!("{:?}", self.id),
);
}
}

impl Response {
Expand Down
Loading