From 8de976f4bf8fa7b7637855012ef9a4e503ab6cbc Mon Sep 17 00:00:00 2001 From: Wu Shuwen Date: Mon, 5 Oct 2026 21:52:23 +0800 Subject: [PATCH] Fix #8495: Match scrollbar interaction rect to drawn bar rect (remove dead zone) (#8635) Closes #8495. ## Problem `ScrollArea::scroll_bar_rect` is used when painting the scrollbar (`outer_scroll_bar_rect` at lines 1360-1364) and when computing handle geometry/travel (`from_content`, `handle_travel`), but the interaction rect `max_bar_rect` (lines 1318-1322) was derived from `outer_rect` along the scrolling axis. When a caller passes a `scroll_bar_rect` smaller than `outer_rect` (as `egui_table::SplitScroll` does to keep bars out of sticky row/column regions), the two rects disagree along the scroll axis. Consequences: 1. A press in the region where no scrollbar is drawn is sensed as a scrollbar press and snaps the offset to the minimum. 2. During a drag, that region behaves as a dead zone because `scroll_start_offset_from_top_left` is latched for the whole drag and the offset is pinned until the pointer crosses back into `handle_travel`. ## Fix Changed `max_bar_rect` to use `scroll_bar_rect.x_range()` for horizontal bars and `scroll_bar_rect.y_range()` for vertical bars along the scrolling axis, while keeping the existing cross-axis positioning (`max_cross`, `full_width`, and the clip-rect adjustment that moves bars into view). The interactive region now matches the painted bar and handle travel exactly. The default case (`scroll_bar_rect` is `None`, which resolves to `inner_rect`) is unchanged in behavior since `inner_rect` and `outer_rect` share the same min along the scroll axis (only the far edge differs for scroll bar space). - [x] `cargo check -p egui` and `cargo test -p egui` pass. --- crates/egui/src/containers/scroll_area.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/crates/egui/src/containers/scroll_area.rs b/crates/egui/src/containers/scroll_area.rs index 55c38071..2603bad8 100644 --- a/crates/egui/src/containers/scroll_area.rs +++ b/crates/egui/src/containers/scroll_area.rs @@ -1437,11 +1437,21 @@ impl Prepared { let full_width = scroll_style.bar_width; // The bounding rect of a fully visible bar. - // When we hover this area, we should show the full bar: + // When we hover this area, we should show the full bar. + // The interaction rect must match where the scroll bar is drawn (outer_scroll_bar_rect), + // i.e. use `scroll_bar_rect` along the scrolling axis. Otherwise a press in a region + // where no scrollbar is drawn is sensed as a scrollbar press, creating a dead zone + // and snapping the offset to the minimum (see issue #8495). let max_bar_rect = if d == 0 { - outer_rect.with_min_y(max_cross - full_width) + Rect::from_x_y_ranges( + scroll_bar_rect.x_range(), + Rangef::new(max_cross - full_width, max_cross), + ) } else { - outer_rect.with_min_x(max_cross - full_width) + Rect::from_x_y_ranges( + Rangef::new(max_cross - full_width, max_cross), + scroll_bar_rect.y_range(), + ) }; let sense = if scroll_source.scroll_bar && ui.is_enabled() {