More natural thumb drag

This commit is contained in:
Alexandre Bury 2017-10-12 12:35:57 -07:00
parent e7da474769
commit f5492da4e4

View File

@ -1,8 +1,8 @@
use Printer; use Printer;
use div::div_up;
use std::cmp::{max, min}; use std::cmp::{max, min};
use theme::ColorStyle; use theme::ColorStyle;
use vec::Vec2; use vec::Vec2;
use div::div_up;
/// Provide scrolling functionalities to a view. /// Provide scrolling functionalities to a view.
/// ///
@ -149,8 +149,10 @@ impl ScrollBase {
// The saturating_sub is there to stop at the bottom of the content. // The saturating_sub is there to stop at the bottom of the content.
// eprintln!("Scrolling to {}", thumb_y); // eprintln!("Scrolling to {}", thumb_y);
self.start_line = min( self.start_line = min(
div_up((1 + self.content_height - self.view_height) * thumb_y div_up(
, (self.view_height - thumb_height + 1)), (1 + self.content_height - self.view_height) * thumb_y,
(self.view_height - thumb_height + 1),
),
self.content_height - self.view_height, self.content_height - self.view_height,
); );
} }
@ -181,7 +183,8 @@ impl ScrollBase {
self.thumb_grab = position.y - thumb_y; self.thumb_grab = position.y - thumb_y;
} else { } else {
// Just jump a bit... // Just jump a bit...
self.thumb_grab = height / 2; self.thumb_grab = (height - 1) / 2;
eprintln!("Grabbed at {}", self.thumb_grab);
self.drag(position); self.drag(position);
} }