From cb0ce5a7e73080c265f598f42a4cc19d756dabbc Mon Sep 17 00:00:00 2001 From: darkfi Date: Sat, 3 Aug 2024 12:28:06 +0200 Subject: [PATCH] wallet: chatview touch finger scroll accel/decel --- bin/darkwallet/src/main.rs | 1 + bin/darkwallet/src/ui/chatview.rs | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/bin/darkwallet/src/main.rs b/bin/darkwallet/src/main.rs index 42192620b..d619b740a 100644 --- a/bin/darkwallet/src/main.rs +++ b/bin/darkwallet/src/main.rs @@ -18,6 +18,7 @@ #![feature(deadline_api)] #![feature(str_split_whitespace_remainder)] +#![feature(duration_millis_float)] // Use these to incrementally fix warnings with cargo fix //#![allow(warnings, unused)] diff --git a/bin/darkwallet/src/ui/chatview.rs b/bin/darkwallet/src/ui/chatview.rs index ece2ede71..7c615721d 100644 --- a/bin/darkwallet/src/ui/chatview.rs +++ b/bin/darkwallet/src/ui/chatview.rs @@ -203,6 +203,7 @@ fn select_nick_color(nick: &str, nick_colors: &[Color]) -> Color { color } +#[derive(Clone)] struct TouchInfo { start_scroll: f32, start_y: f32, @@ -567,6 +568,14 @@ impl ChatView { } TouchPhase::Ended => { // Now calculate scroll acceleration + let touch_info = self.touch_info.lock().unwrap().clone(); + + let time = touch_info.start_instant.elapsed().as_millis_f32(); + let dist = touch_y - touch_info.start_y; + + let accel = self.mouse_scroll_start_accel.get() * dist / time; + self.accel.fetch_add(accel, Ordering::Relaxed); + self.motion_cv.notify(); } TouchPhase::Cancelled => {} }