1
0
Fork 0
forked from wry/wry

all: make scroll axis handling more robust

This commit is contained in:
Julian Orth 2025-03-20 21:09:16 +01:00
parent bb569dfa00
commit 7305f68909
10 changed files with 38 additions and 33 deletions

View file

@ -17,14 +17,14 @@ pub struct Scroller {
impl Scroller {
pub fn handle(&self, scroll: &PendingScroll) -> Option<i32> {
let n = if let Some(d) = scroll.v120[VERTICAL_SCROLL as usize].get() {
let n = if let Some(d) = scroll.v120[VERTICAL_SCROLL].get() {
self.px.set(0.0);
let mut v120 = self.v120.get() + d;
let discrete = v120 / AXIS_120;
v120 -= discrete * AXIS_120;
self.v120.set(v120);
discrete
} else if let Some(px) = scroll.px[VERTICAL_SCROLL as usize].get() {
} else if let Some(px) = scroll.px[VERTICAL_SCROLL].get() {
self.v120.set(0);
let mut px = self.px.get() + px.to_f64();
let discrete = (px / PX_PER_SCROLL).trunc();
@ -34,7 +34,7 @@ impl Scroller {
} else {
0
};
if scroll.stop[VERTICAL_SCROLL as usize].get() {
if scroll.stop[VERTICAL_SCROLL].get() {
self.v120.set(0);
self.px.set(0.0);
}