diff options
| author | 2019-11-24 12:12:08 +0100 | |
|---|---|---|
| committer | 2019-11-24 12:12:08 +0100 | |
| commit | 5629716120f2635406707792a6967bcd7d3e0ff3 (patch) | |
| tree | 135c13aca73009fadcdf44edc2a8eebdf52e3a0d /native | |
| parent | 422e2a619415fdd9ed7fb12db26f6e28603e4590 (diff) | |
| download | iced-5629716120f2635406707792a6967bcd7d3e0ff3.tar.gz iced-5629716120f2635406707792a6967bcd7d3e0ff3.tar.bz2 iced-5629716120f2635406707792a6967bcd7d3e0ff3.zip | |
Fix rounding error when scrolling
Diffstat (limited to '')
| -rw-r--r-- | native/src/widget/scrollable.rs | 15 | 
1 files changed, 7 insertions, 8 deletions
| diff --git a/native/src/widget/scrollable.rs b/native/src/widget/scrollable.rs index 0d745756..9b7ccf84 100644 --- a/native/src/widget/scrollable.rs +++ b/native/src/widget/scrollable.rs @@ -295,7 +295,7 @@ where  #[derive(Debug, Clone, Copy, Default)]  pub struct State {      scrollbar_grabbed_at: Option<Point>, -    offset: u32, +    offset: f32,  }  impl State { @@ -321,10 +321,9 @@ impl State {              return;          } -        self.offset = (self.offset as i32 - delta_y.round() as i32) -            .max(0) -            .min((content_bounds.height - bounds.height) as i32) -            as u32; +        self.offset = (self.offset - delta_y) +            .max(0.0) +            .min((content_bounds.height - bounds.height) as f32);      }      /// Moves the scroll position to a relative amount, given the bounds of @@ -341,8 +340,8 @@ impl State {          bounds: Rectangle,          content_bounds: Rectangle,      ) { -        self.offset = ((content_bounds.height - bounds.height) * percentage) -            .max(0.0) as u32; +        self.offset = +            ((content_bounds.height - bounds.height) * percentage).max(0.0);      }      /// Returns the current scrolling offset of the [`State`], given the bounds @@ -354,7 +353,7 @@ impl State {          let hidden_content =              (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. | 
