From a1d19383a467b1df96e977db638a219db188aca3 Mon Sep 17 00:00:00 2001 From: Lucas Meurer Date: Mon, 27 May 2024 17:20:09 +0200 Subject: [PATCH] Fix scroll_with_delta behaviour being inverted --- crates/egui/src/containers/scroll_area.rs | 3 ++- crates/egui/src/frame_state.rs | 8 ++++++++ crates/egui_demo_lib/src/demo/scrolling.rs | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/crates/egui/src/containers/scroll_area.rs b/crates/egui/src/containers/scroll_area.rs index 855ba5dc582..3bdac533ba2 100644 --- a/crates/egui/src/containers/scroll_area.rs +++ b/crates/egui/src/containers/scroll_area.rs @@ -787,7 +787,8 @@ impl Prepared { .frame_state_mut(|state| std::mem::take(&mut state.scroll_delta)); for d in 0..2 { - let mut delta = scroll_delta[d]; + // FrameState::scroll_delta is inverted from the way we apply the delta, so we need to negate it. + let mut delta = -scroll_delta[d]; // We always take both scroll targets regardless of which scroll axes are enabled. This // is to avoid them leaking to other scroll areas. diff --git a/crates/egui/src/frame_state.rs b/crates/egui/src/frame_state.rs index 3ed1a3691de..5b7de3d10b3 100644 --- a/crates/egui/src/frame_state.rs +++ b/crates/egui/src/frame_state.rs @@ -42,6 +42,14 @@ pub(crate) struct FrameState { pub(crate) scroll_target: [Option<(Rangef, Option)>; 2], /// The current scroll area should scroll by this much. + /// + /// The delta dictates how the _content_ should move. + /// + /// A positive X-value indicates the content is being moved right, + /// as when swiping right on a touch-screen or track-pad with natural scrolling. + /// + /// A positive Y-value indicates the content is being moved down, + /// as when swiping down on a touch-screen or track-pad with natural scrolling. pub(crate) scroll_delta: Vec2, #[cfg(feature = "accesskit")] diff --git a/crates/egui_demo_lib/src/demo/scrolling.rs b/crates/egui_demo_lib/src/demo/scrolling.rs index 6e2c1d0128f..d7bee754c5b 100644 --- a/crates/egui_demo_lib/src/demo/scrolling.rs +++ b/crates/egui_demo_lib/src/demo/scrolling.rs @@ -294,7 +294,7 @@ impl super::View for ScrollTo { scroll_top |= ui.button("Scroll to top").clicked(); scroll_bottom |= ui.button("Scroll to bottom").clicked(); if ui.button("Scroll down by 64px").clicked() { - scroll_delta = Some(Vec2::new(0.0, 64.0)); + scroll_delta = Some(Vec2::new(0.0, -64.0)); } });