From 1e61881b4f52afbc5c8d3310ffcded245a40f7ce Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Tue, 7 Oct 2025 15:30:17 -0700 Subject: [PATCH] Accumulate line scrolling Combined with https://github.com/pop-os/iced/pull/244, discrete value120 scrolling works better. --- src/main.rs | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/src/main.rs b/src/main.rs index ce6cc6c..a14cb31 100644 --- a/src/main.rs +++ b/src/main.rs @@ -672,19 +672,20 @@ impl Application for App { // Accumulate delta with a timer // TODO: Should x scroll be handled too? // Best time/pixel count? + + let previous_scroll = if let Some((scroll, last_scroll_time)) = self.scroll { + if last_scroll_time.elapsed() > Duration::from_millis(100) { + 0. + } else { + scroll + } + } else { + 0. + }; + let direction = match delta { ScrollDelta::Pixels { x: _, mut y } => { y = -y; - let previous_scroll = if let Some((scroll, last_scroll_time)) = self.scroll - { - if last_scroll_time.elapsed() > Duration::from_millis(100) { - 0. - } else { - scroll - } - } else { - 0. - }; let scroll = previous_scroll + y; if scroll <= -4. { @@ -705,12 +706,20 @@ impl Application for App { } ScrollDelta::Lines { x: _, mut y } => { y = -y; - self.scroll = None; - if y < 0. { + + let scroll = previous_scroll + y; + if scroll <= -1. { + self.scroll = None; ScrollDirection::Prev - } else if y > 0. { + } else if scroll >= 1. { + self.scroll = None; ScrollDirection::Next } else { + self.scroll = if y != 0. { + Some((scroll, Instant::now())) + } else { + None + }; return Task::none(); } }