Improve ability to inspect why a widget is as wide as it is
This commit is contained in:
parent
633b19ee99
commit
56715a1dcd
2 changed files with 31 additions and 10 deletions
|
@ -138,7 +138,10 @@ pub struct Visuals {
|
|||
|
||||
// -----------------------------------------------
|
||||
// Debug rendering:
|
||||
pub debug_widget_rects: bool,
|
||||
/// Show which widgets make their parent wider
|
||||
pub debug_expand_width: bool,
|
||||
/// Show which widgets make their parent higher
|
||||
pub debug_expand_height: bool,
|
||||
pub debug_resize: bool,
|
||||
}
|
||||
|
||||
|
@ -260,7 +263,8 @@ impl Default for Visuals {
|
|||
resize_corner_size: 12.0,
|
||||
text_cursor_width: 2.0,
|
||||
clip_rect_margin: 3.0,
|
||||
debug_widget_rects: false,
|
||||
debug_expand_width: false,
|
||||
debug_expand_height: false,
|
||||
debug_resize: false,
|
||||
}
|
||||
}
|
||||
|
@ -443,7 +447,8 @@ impl Visuals {
|
|||
resize_corner_size,
|
||||
text_cursor_width,
|
||||
clip_rect_margin,
|
||||
debug_widget_rects,
|
||||
debug_expand_width,
|
||||
debug_expand_height,
|
||||
debug_resize,
|
||||
} = self;
|
||||
|
||||
|
@ -454,7 +459,15 @@ impl Visuals {
|
|||
ui.add(Slider::f32(text_cursor_width, 0.0..=2.0).text("text_cursor_width"));
|
||||
ui.add(Slider::f32(clip_rect_margin, 0.0..=20.0).text("clip_rect_margin"));
|
||||
|
||||
ui.checkbox(debug_widget_rects, "Paint debug rectangles around widgets");
|
||||
ui.label("DEBUG:");
|
||||
ui.checkbox(
|
||||
debug_expand_width,
|
||||
"Show which widgets make their parent wider",
|
||||
);
|
||||
ui.checkbox(
|
||||
debug_expand_height,
|
||||
"Show which widgets make their parent higher",
|
||||
);
|
||||
ui.checkbox(debug_resize, "Debug Resize");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -434,26 +434,34 @@ impl Ui {
|
|||
/// You may get LESS space than you asked for if the current layout won't fit what you asked for.
|
||||
pub fn allocate_space(&mut self, desired_size: Vec2) -> Rect {
|
||||
// For debug rendering
|
||||
let too_wide = desired_size.x > self.available().width();
|
||||
let too_high = desired_size.x > self.available().height();
|
||||
let original_size = self.available().size();
|
||||
let too_wide = desired_size.x > original_size.x;
|
||||
let too_high = desired_size.y > original_size.y;
|
||||
|
||||
let rect = self.reserve_space_impl(desired_size);
|
||||
|
||||
if self.style().visuals.debug_widget_rects {
|
||||
let debug_expand_width = self.style().visuals.debug_expand_width;
|
||||
let debug_expand_height = self.style().visuals.debug_expand_height;
|
||||
|
||||
if (debug_expand_width && too_wide) || (debug_expand_height && too_high) {
|
||||
self.painter.rect_stroke(rect, 0.0, (1.0, LIGHT_BLUE));
|
||||
|
||||
let color = color::srgba(200, 0, 0, 255);
|
||||
let color = color::Srgba::from_rgb(200, 0, 0);
|
||||
let width = 2.5;
|
||||
|
||||
let paint_line_seg = |a, b| self.painter().line_segment([a, b], (width, color));
|
||||
|
||||
if too_wide {
|
||||
if debug_expand_width && too_wide {
|
||||
paint_line_seg(rect.left_top(), rect.left_bottom());
|
||||
paint_line_seg(rect.left_center(), rect.right_center());
|
||||
paint_line_seg(
|
||||
pos2(rect.left() + original_size.x, rect.top()),
|
||||
pos2(rect.left() + original_size.x, rect.bottom()),
|
||||
);
|
||||
paint_line_seg(rect.right_top(), rect.right_bottom());
|
||||
}
|
||||
|
||||
if too_high {
|
||||
if debug_expand_height && too_high {
|
||||
paint_line_seg(rect.left_top(), rect.right_top());
|
||||
paint_line_seg(rect.center_top(), rect.center_bottom());
|
||||
paint_line_seg(rect.left_bottom(), rect.right_bottom());
|
||||
|
|
Loading…
Reference in a new issue