diff options
| author | 2019-11-30 17:49:42 +0100 | |
|---|---|---|
| committer | 2019-12-02 19:12:05 +0100 | |
| commit | c12ba14ddad40e8f0e656ae0f8a43c87f0b5907f (patch) | |
| tree | 5aca4bc190d8d1bbda6b60ae72b0798795df6b22 /native/src | |
| parent | f8fac432c665e57267243a9ee3920208b2724e6e (diff) | |
| download | iced-c12ba14ddad40e8f0e656ae0f8a43c87f0b5907f.tar.gz iced-c12ba14ddad40e8f0e656ae0f8a43c87f0b5907f.tar.bz2 iced-c12ba14ddad40e8f0e656ae0f8a43c87f0b5907f.zip  | |
Move scrolling percentage logic to separate function
Diffstat (limited to '')
| -rw-r--r-- | native/src/widget/scrollable.rs | 33 | 
1 files changed, 23 insertions, 10 deletions
diff --git a/native/src/widget/scrollable.rs b/native/src/widget/scrollable.rs index 17a1363e..ab1a203b 100644 --- a/native/src/widget/scrollable.rs +++ b/native/src/widget/scrollable.rs @@ -102,6 +102,17 @@ impl<'a, Message, Renderer> Scrollable<'a, Message, Renderer> {      }  } +fn scroll_percentage( +    bounds: Rectangle, +    scroller_bounds: Rectangle, +    scroller_grabbed_at: f32, +    cursor_position: Point, +) -> f32 { +    (cursor_position.y + bounds.y +        - scroller_bounds.height * scroller_grabbed_at) +        / (bounds.height - scroller_bounds.height) +} +  impl<'a, Message, Renderer> Widget<Message, Renderer>      for Scrollable<'a, Message, Renderer>  where @@ -195,12 +206,13 @@ where                              }                          }; -                        let scroll_percentage = (cursor_position.y + bounds.y -                            - scroller_bounds.height * scroller_grabbed_at) -                            / (bounds.height - scroller_bounds.height); -                          self.state.scroll_to( -                            scroll_percentage, +                            scroll_percentage( +                                bounds, +                                scroller_bounds, +                                scroller_grabbed_at, +                                cursor_position, +                            ),                              bounds,                              content_bounds,                          ); @@ -216,12 +228,13 @@ where                      if let Some(scroller_grabbed_at) =                          self.state.scroller_grabbed_at                      { -                        let scroll_percentage = (cursor_position.y + bounds.y -                            - scroller_bounds.height * scroller_grabbed_at) -                            / (bounds.height - scroller_bounds.height); -                          self.state.scroll_to( -                            scroll_percentage, +                            scroll_percentage( +                                bounds, +                                scroller_bounds, +                                scroller_grabbed_at, +                                cursor_position, +                            ),                              bounds,                              content_bounds,                          );  | 
