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/src/ui.rs b/crates/egui/src/ui.rs index ab8ace57e1b..e34a3ad1cb9 100644 --- a/crates/egui/src/ui.rs +++ b/crates/egui/src/ui.rs @@ -1073,7 +1073,7 @@ impl Ui { /// 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. /// - /// If this is called multiple times per frame for the same ScrollArea, the deltas will be combined. + /// If this is called multiple times per frame for the same [`ScrollArea`], the deltas will be combined. /// /// /// See also: [`Response::scroll_to_me`], [`Ui::scroll_to_rect`], [`Ui::scroll_to_cursor`] /// 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)); } });