Skip to content

Commit

Permalink
Fix scroll_with_delta behaviour being inverted
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmerlin committed May 27, 2024
1 parent cbcccd2 commit 6c58dbe
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
3 changes: 2 additions & 1 deletion crates/egui/src/containers/scroll_area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions crates/egui/src/frame_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ pub(crate) struct FrameState {
pub(crate) scroll_target: [Option<(Rangef, Option<Align>)>; 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")]
Expand Down
2 changes: 1 addition & 1 deletion crates/egui/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`]
///
Expand Down
2 changes: 1 addition & 1 deletion crates/egui_demo_lib/src/demo/scrolling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
});

Expand Down

0 comments on commit 6c58dbe

Please sign in to comment.