From e384e96939838b5400c5cc7f224702b0f3d613fc Mon Sep 17 00:00:00 2001 From: galister <22305755+galister@users.noreply.github.com> Date: Sat, 3 Feb 2024 13:58:46 +0100 Subject: [PATCH] fix mouse scroll speed --- src/overlays/screen.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/overlays/screen.rs b/src/overlays/screen.rs index 8e91ec7..3b62178 100644 --- a/src/overlays/screen.rs +++ b/src/overlays/screen.rs @@ -4,7 +4,7 @@ use std::{ collections::HashMap, error::Error, f32::consts::PI, - ops::Deref, + ops::{Add, Deref}, path::PathBuf, ptr, sync::{mpsc::Receiver, Arc}, @@ -98,11 +98,18 @@ impl InteractionHandler for ScreenInteractionHandler { let pos = self.mouse_transform.transform_point2(hit.uv); app.hid_provider.mouse_move(pos); } - fn on_scroll(&mut self, app: &mut AppState, _hit: &PointerHit, delta: f32) { - let millis = (1. - delta.abs()) * delta; - if let Some(next_scroll) = Instant::now().checked_add(Duration::from_millis(millis as _)) { - self.next_scroll = next_scroll; + fn on_scroll(&mut self, app: &mut AppState, hit: &PointerHit, delta: f32) { + if self.next_scroll > Instant::now() { + return; } + let max_millis = if matches!(hit.mode, PointerMode::Right) { + 50.0 + } else { + 100.0 + }; + + let millis = (1. - delta.abs()) * max_millis; + self.next_scroll = Instant::now().add(Duration::from_millis(millis as _)); app.hid_provider.wheel(if delta < 0. { -1 } else { 1 }) } fn on_left(&mut self, _app: &mut AppState, _hand: usize) {}