1
0
Fork 0
forked from wry/wry

input: rename axix_smooth to axis_px

This commit is contained in:
Julian Orth 2022-05-27 17:02:44 +02:00
parent 64416d417b
commit 20f0fba553
7 changed files with 18 additions and 21 deletions

View file

@ -12,31 +12,31 @@ use {
#[derive(Default)]
pub struct Scroller {
v120: Cell<i32>,
smooth: Cell<f64>,
px: Cell<f64>,
}
impl Scroller {
pub fn handle(&self, scroll: &PendingScroll) -> Option<i32> {
let n = if let Some(d) = scroll.v120[VERTICAL_SCROLL as usize].get() {
self.smooth.set(0.0);
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(smooth) = scroll.smooth[VERTICAL_SCROLL as usize].get() {
} else if let Some(px) = scroll.px[VERTICAL_SCROLL as usize].get() {
self.v120.set(0);
let mut smooth = self.smooth.get() + smooth.to_f64();
let discrete = (smooth / PX_PER_SCROLL).trunc();
smooth -= discrete * PX_PER_SCROLL;
self.smooth.set(smooth);
let mut px = self.px.get() + px.to_f64();
let discrete = (px / PX_PER_SCROLL).trunc();
px -= discrete * PX_PER_SCROLL;
self.px.set(px);
discrete as _
} else {
0
};
if scroll.stop[VERTICAL_SCROLL as usize].get() {
self.v120.set(0);
self.smooth.set(0.0);
self.px.set(0.0);
}
if n != 0 {
Some(n)