Skip to content

Commit 453b153

Browse files
authored
bevy_ui_debug scrollbars inset fix (#22343)
# Objective `ComputedNode`'s `content_inset` field was changed to allocate space for the scrollbars between the content and padding areas. The UI debug overlay expects the `content_insets` to include that space and as a result wrongly draws the scrollbars inset into the content box by their width. ## Solution Use `ComputedNode`'s `horizontal_scrollbar` and `vertical_scrollbar` methods to position the debug overlay's scroll bar rects instead. ## Testing ``` cargo run --example scroll --features="bevy_ui_debug" ``` On main you should see a gap between the the vertical scrollbar and the right edge of the node. With this PR, the gap should be gone.
1 parent 71ce303 commit 453b153

File tree

1 file changed

+16
-40
lines changed

1 file changed

+16
-40
lines changed

crates/bevy_ui_render/src/debug_overlay.rs

Lines changed: 16 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -178,49 +178,25 @@ pub fn extract_debug_overlay(
178178
}
179179

180180
if debug_options.outline_scrollbars {
181-
if 0. <= uinode.scrollbar_size.y {
182-
let content_inset = uinode.content_inset();
183-
let half_size = 0.5 * uinode.size;
184-
let min_x = -half_size.x + content_inset.min_inset.x;
185-
let max_x = half_size.x - content_inset.max_inset.x - uinode.scrollbar_size.x;
186-
let max_y = half_size.y - content_inset.max_inset.y;
187-
let min_y = max_y - uinode.scrollbar_size.y;
188-
let gutter = Rect {
189-
min: Vec2::new(min_x, min_y),
190-
max: Vec2::new(max_x, max_y),
191-
};
192-
let gutter_length = gutter.size().x;
193-
let thumb_min =
194-
gutter.min.x + gutter_length * uinode.scroll_position.x / uinode.content_size.x;
195-
let thumb_max = thumb_min + gutter_length * gutter_length / uinode.content_size.x;
196-
let thumb = Rect {
197-
min: Vec2::new(thumb_min, gutter.min.y),
198-
max: Vec2::new(thumb_max, gutter.max.y),
199-
};
181+
if let Some((gutter, [thumb_min, thumb_max])) = uinode.horizontal_scrollbar() {
200182
push_outline(gutter, ResolvedBorderRadius::ZERO);
201-
push_outline(thumb, ResolvedBorderRadius::ZERO);
183+
push_outline(
184+
Rect {
185+
min: Vec2::new(thumb_min, gutter.min.y),
186+
max: Vec2::new(thumb_max, gutter.max.y),
187+
},
188+
ResolvedBorderRadius::ZERO,
189+
);
202190
}
203-
if 0. <= uinode.scrollbar_size.x {
204-
let content_inset = uinode.content_inset();
205-
let half_size = 0.5 * uinode.size;
206-
let max_x = half_size.x - content_inset.max_inset.x;
207-
let min_x = max_x - uinode.scrollbar_size.x;
208-
let min_y = -half_size.y + content_inset.min_inset.y;
209-
let max_y = half_size.y - content_inset.max_inset.y - uinode.scrollbar_size.y;
210-
let gutter = Rect {
211-
min: Vec2::new(min_x, min_y),
212-
max: Vec2::new(max_x, max_y),
213-
};
214-
let gutter_length = gutter.size().y;
215-
let thumb_min =
216-
gutter.min.y + gutter_length * uinode.scroll_position.y / uinode.content_size.y;
217-
let thumb_max = thumb_min + gutter_length * gutter_length / uinode.content_size.y;
218-
let thumb = Rect {
219-
min: Vec2::new(gutter.min.x, thumb_min),
220-
max: Vec2::new(gutter.max.x, thumb_max),
221-
};
191+
if let Some((gutter, [thumb_min, thumb_max])) = uinode.vertical_scrollbar() {
222192
push_outline(gutter, ResolvedBorderRadius::ZERO);
223-
push_outline(thumb, ResolvedBorderRadius::ZERO);
193+
push_outline(
194+
Rect {
195+
min: Vec2::new(gutter.min.x, thumb_min),
196+
max: Vec2::new(gutter.max.x, thumb_max),
197+
},
198+
ResolvedBorderRadius::ZERO,
199+
);
224200
}
225201
}
226202
}

0 commit comments

Comments
 (0)