Skip to content

Commit

Permalink
Implement mouse wheel multiplier
Browse files Browse the repository at this point in the history
  • Loading branch information
MStarha committed Dec 6, 2024
1 parent 4b8da6d commit da6f64f
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion crates/egui/src/containers/scroll_area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ pub struct ScrollArea {
offset_y: Option<f32>,
on_hover_cursor: Option<CursorIcon>,
on_drag_cursor: Option<CursorIcon>,

scroll_source: ScrollSource,
wheel_scroll_multiplier: Vec2,

/// If true for vertical or horizontal the scroll wheel will stick to the
/// end position until user manually changes position. It will become true
Expand Down Expand Up @@ -338,6 +338,7 @@ impl ScrollArea {
on_hover_cursor: None,
on_drag_cursor: None,
scroll_source: ScrollSource::default(),
wheel_scroll_multiplier: Vec2::splat(1.0),
stick_to_end: Vec2b::FALSE,
animated: true,
}
Expand Down Expand Up @@ -556,6 +557,17 @@ impl ScrollArea {
self
}

/// The scroll amount caused by a mouse wheel scroll is multiplied by this amount.
///
/// Independent for each scroll direction. Defaults to `Vec2{x: 1.0, y: 1.0}`.
///
/// This can invert or effectively disable mouse scrolling.
#[inline]
pub fn wheel_scroll_multiplier(mut self, multiplier: Vec2) -> Self {
self.wheel_scroll_multiplier = multiplier;
self
}

/// For each axis, should the containing area shrink if the content is small?
///
/// * If `true`, egui will add blank space outside the scroll area.
Expand Down Expand Up @@ -643,6 +655,7 @@ struct Prepared {
viewport: Rect,

scroll_source: ScrollSource,
wheel_scroll_multiplier: Vec2,
stick_to_end: Vec2b,
animated: bool,
}
Expand All @@ -662,6 +675,7 @@ impl ScrollArea {
on_hover_cursor,
on_drag_cursor,
scroll_source,
wheel_scroll_multiplier,
stick_to_end,
animated,
} = self;
Expand Down Expand Up @@ -865,6 +879,7 @@ impl ScrollArea {
content_ui,
viewport,
scroll_source,
wheel_scroll_multiplier,
stick_to_end,
animated,
}
Expand Down Expand Up @@ -978,6 +993,7 @@ impl Prepared {
content_ui,
viewport: _,
scroll_source,
wheel_scroll_multiplier,
stick_to_end,
animated,
} = self;
Expand Down Expand Up @@ -1099,6 +1115,7 @@ impl Prepared {
input.smooth_scroll_delta[d]
}
});
let scroll_delta = scroll_delta * wheel_scroll_multiplier[d];

let scrolling_up = state.offset[d] > 0.0 && scroll_delta > 0.0;
let scrolling_down = state.offset[d] < max_offset[d] && scroll_delta < 0.0;
Expand Down

0 comments on commit da6f64f

Please sign in to comment.