From 78c0e39d1d7ced1a0d91671a51e398b5338f63a7 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Tue, 4 Aug 2026 17:10:34 +0900 Subject: [PATCH] Fix ScrollArea failure by handling horizontal and vertical scrolling separately in the missing place (#8275) Fix ScrollArea failure by handling horizontal and vertical scrolling separately in the missing place Everywhere in `ScrollArea`, horizontal and vertical scrolling are handled separately. However, because there is a single place where they are not handled separately, when trying to process horizontal and vertical scrolls independently, one of the dimensions fails to scroll. This Pull Request ensures that horizontal and vertical scrolling are handled separately in this area, just like in the rest of the codebase. * Closes #5289 * Closes #5307 * Closes #8274 --- crates/egui/src/containers/scroll_area.rs | 27 +++++++++++++---------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/crates/egui/src/containers/scroll_area.rs b/crates/egui/src/containers/scroll_area.rs index e59f7e01d..7b1bf87e1 100644 --- a/crates/egui/src/containers/scroll_area.rs +++ b/crates/egui/src/containers/scroll_area.rs @@ -1081,17 +1081,9 @@ impl Prepared { let content_size = content_ui.min_size(); - let scroll_delta = content_ui - .ctx() - .pass_state_mut(|state| std::mem::take(&mut state.scroll_delta)); - let mut had_explicit_scroll_adjustment = Vec2b::FALSE; for d in 0..2 { - // PassState::scroll_delta is inverted from the way we apply the delta, so we need to negate it. - let mut delta = -scroll_delta.0[d]; - let mut animation = scroll_delta.1; - // We always take both scroll targets regardless of which scroll axes are enabled. This // is to avoid them leaking to other scroll areas. let scroll_target = content_ui @@ -1099,6 +1091,17 @@ impl Prepared { .pass_state_mut(|state| state.scroll_target[d].take()); if direction_enabled[d] { + let (scroll_delta, scroll_animation) = content_ui.ctx().pass_state_mut(|state| { + ( + std::mem::take(&mut state.scroll_delta.0[d]), + state.scroll_delta.1, + ) + }); + + // PassState::scroll_delta is inverted from the way we apply the delta, so we need to negate it. + let mut delta = -scroll_delta; + let mut animation = scroll_animation; + if let Some(target) = scroll_target { let pass_state::ScrollTarget { range, @@ -1132,8 +1135,8 @@ impl Prepared { 0.0 }; - delta += delta_update; animation = animation_update; + delta += delta_update; } if delta != 0.0 { @@ -1157,10 +1160,10 @@ impl Prepared { } ui.request_repaint(); } - } - if delta != 0.0 { - had_explicit_scroll_adjustment[d] = true; + if delta != 0.0 { + had_explicit_scroll_adjustment[d] = true; + } } }