Fix rounding error when scrolling
This commit is contained in:
parent
422e2a6194
commit
5629716120
@ -295,7 +295,7 @@ where
|
|||||||
#[derive(Debug, Clone, Copy, Default)]
|
#[derive(Debug, Clone, Copy, Default)]
|
||||||
pub struct State {
|
pub struct State {
|
||||||
scrollbar_grabbed_at: Option<Point>,
|
scrollbar_grabbed_at: Option<Point>,
|
||||||
offset: u32,
|
offset: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl State {
|
impl State {
|
||||||
@ -321,10 +321,9 @@ impl State {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.offset = (self.offset as i32 - delta_y.round() as i32)
|
self.offset = (self.offset - delta_y)
|
||||||
.max(0)
|
.max(0.0)
|
||||||
.min((content_bounds.height - bounds.height) as i32)
|
.min((content_bounds.height - bounds.height) as f32);
|
||||||
as u32;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Moves the scroll position to a relative amount, given the bounds of
|
/// Moves the scroll position to a relative amount, given the bounds of
|
||||||
@ -341,8 +340,8 @@ impl State {
|
|||||||
bounds: Rectangle,
|
bounds: Rectangle,
|
||||||
content_bounds: Rectangle,
|
content_bounds: Rectangle,
|
||||||
) {
|
) {
|
||||||
self.offset = ((content_bounds.height - bounds.height) * percentage)
|
self.offset =
|
||||||
.max(0.0) as u32;
|
((content_bounds.height - bounds.height) * percentage).max(0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the current scrolling offset of the [`State`], given the bounds
|
/// Returns the current scrolling offset of the [`State`], given the bounds
|
||||||
@ -354,7 +353,7 @@ impl State {
|
|||||||
let hidden_content =
|
let hidden_content =
|
||||||
(content_bounds.height - bounds.height).max(0.0).round() as u32;
|
(content_bounds.height - bounds.height).max(0.0).round() as u32;
|
||||||
|
|
||||||
self.offset.min(hidden_content)
|
self.offset.min(hidden_content as f32) as u32
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns whether the scrollbar is currently grabbed or not.
|
/// Returns whether the scrollbar is currently grabbed or not.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user