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

When debugging widget rects on hover, show width and height #4762

Merged
merged 3 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
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
13 changes: 8 additions & 5 deletions crates/egui/src/painter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,14 @@ impl Painter {
let galley = self.layout_no_wrap(text.to_string(), FontId::monospace(12.0), color);
let rect = anchor.anchor_size(pos, galley.size());
let frame_rect = rect.expand(2.0);
self.add(Shape::rect_filled(
frame_rect,
0.0,
Color32::from_black_alpha(150),
));

let is_text_bright = color.is_additive() || epaint::Rgba::from(color).intensity() > 0.5;
let bg_color = if is_text_bright {
Color32::from_black_alpha(150)
} else {
Color32::from_white_alpha(150)
};
self.add(Shape::rect_filled(frame_rect, 0.0, bg_color));
self.galley(rect.min, galley, color);
frame_rect
}
Expand Down
23 changes: 21 additions & 2 deletions crates/egui/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2621,13 +2621,32 @@ fn register_rect(ui: &Ui, rect: Rect) {

// Paint rectangle around widget:
{
// Print width and height:
let text_color = if ui.visuals().dark_mode {
Color32::WHITE
} else {
Color32::BLACK
};
painter.debug_text(
rect.left_center() + 2.0 * Vec2::LEFT,
Align2::RIGHT_CENTER,
text_color,
format!("H: {:.1}", rect.height()),
);
painter.debug_text(
rect.center_top(),
Align2::CENTER_BOTTOM,
text_color,
format!("W: {:.1}", rect.width()),
);

// Paint rect:
let rect_fg_color = if is_clicking {
Color32::WHITE
} else {
Color32::LIGHT_BLUE
};
let rect_bg_color = Color32::BLUE.gamma_multiply(0.5);

painter.rect(rect, 0.0, rect_bg_color, (1.0, rect_fg_color));
}

Expand Down Expand Up @@ -2655,7 +2674,7 @@ fn register_rect(ui: &Ui, rect: Rect) {
let screen_rect = ui.ctx().screen_rect();
let y = if galley.size().y <= rect.top() {
// Above
rect.top() - galley.size().y
rect.top() - galley.size().y - 16.0
} else {
// Below
rect.bottom()
Expand Down
Loading