diff --git a/crates/egui/src/context.rs b/crates/egui/src/context.rs index 04bdd16432aa..d0dedaa1ac10 100644 --- a/crates/egui/src/context.rs +++ b/crates/egui/src/context.rs @@ -442,6 +442,7 @@ impl ContextImpl { new_raw_input, viewport.repaint.requested_immediate_repaint_prev_frame(), pixels_per_point, + &self.memory.options, ); let screen_rect = viewport.input.screen_rect; diff --git a/crates/egui/src/input_state.rs b/crates/egui/src/input_state.rs index 49699795943b..f52bfe24928a 100644 --- a/crates/egui/src/input_state.rs +++ b/crates/egui/src/input_state.rs @@ -183,6 +183,7 @@ impl InputState { mut new: RawInput, requested_immediate_repaint_prev_frame: bool, pixels_per_point: f32, + options: &crate::Options, ) -> Self { crate::profile_function!(); @@ -235,17 +236,7 @@ impl InputState { } => { let mut delta = match unit { MouseWheelUnit::Point => *delta, - MouseWheelUnit::Line => { - // TODO(emilk): figure out why these constants need to be different on web and on native (winit). - let is_web = cfg!(target_arch = "wasm32"); - let points_per_scroll_line = if is_web { - 8.0 - } else { - 50.0 // Scroll speed decided by consensus: https://github.com/emilk/egui/issues/461 - }; - - points_per_scroll_line * *delta - } + MouseWheelUnit::Line => options.line_scroll_speed * *delta, MouseWheelUnit::Page => screen_rect.height() * *delta, }; @@ -319,7 +310,8 @@ impl InputState { unprocessed_scroll_delta_for_zoom -= applied; } - zoom_factor_delta *= (smooth_scroll_delta_for_zoom / 200.0).exp(); + zoom_factor_delta *= + (options.scroll_zoom_speed * smooth_scroll_delta_for_zoom).exp(); } } diff --git a/crates/egui/src/memory.rs b/crates/egui/src/memory.rs index 4bee395c530b..8a642adf28ec 100644 --- a/crates/egui/src/memory.rs +++ b/crates/egui/src/memory.rs @@ -227,10 +227,26 @@ pub struct Options { /// /// By default this is `true` in debug builds. pub warn_on_id_clash: bool, + + // ------------------------------ + // Input: + /// Multiplier for the scroll speed when reported in [`crate::MouseWheelUnit::Line`]s. + pub line_scroll_speed: f32, + + /// Controls the speed at which we zoom in when doing ctrl/cmd + scroll. + pub scroll_zoom_speed: f32, } impl Default for Options { fn default() -> Self { + // TODO(emilk): figure out why these constants need to be different on web and on native (winit). + let is_web = cfg!(target_arch = "wasm32"); + let line_scroll_speed = if is_web { + 8.0 + } else { + 40.0 // Scroll speed decided by consensus: https://github.com/emilk/egui/issues/461 + }; + Self { style: Default::default(), zoom_factor: 1.0, @@ -240,6 +256,10 @@ impl Default for Options { screen_reader: false, preload_font_glyphs: true, warn_on_id_clash: cfg!(debug_assertions), + + // Input: + line_scroll_speed, + scroll_zoom_speed: 1.0 / 200.0, } } } @@ -256,6 +276,9 @@ impl Options { screen_reader: _, // needs to come from the integration preload_font_glyphs: _, warn_on_id_clash, + + line_scroll_speed, + scroll_zoom_speed, } = self; use crate::Widget as _; @@ -292,6 +315,27 @@ impl Options { }); }); + CollapsingHeader::new("🖱 Input") + .default_open(false) + .show(ui, |ui| { + ui.horizontal(|ui| { + ui.label("Line scroll speed"); + ui.add( + crate::DragValue::new(line_scroll_speed).clamp_range(0.0..=f32::INFINITY), + ) + .on_hover_text("How many lines to scroll with each tick of the mouse wheel"); + }); + ui.horizontal(|ui| { + ui.label("Scroll zoom speed"); + ui.add( + crate::DragValue::new(scroll_zoom_speed) + .clamp_range(0.0..=f32::INFINITY) + .speed(0.001), + ) + .on_hover_text("How fast to zoom with ctrl/cmd + scroll"); + }); + }); + ui.vertical_centered(|ui| crate::reset_button(ui, self, "Reset all")); } }