From 09fcbf225e61be0a0b5732a6dcd51326f98316fc Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Tue, 24 Jul 2018 22:53:56 -0700 Subject: [PATCH] Fix underflow in ScrollView --- src/views/scroll_view.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/views/scroll_view.rs b/src/views/scroll_view.rs index dbd483f..651a731 100644 --- a/src/views/scroll_view.rs +++ b/src/views/scroll_view.rs @@ -38,6 +38,8 @@ pub struct ScrollView { show_scrollbars: bool, /// How much padding should be between content and scrollbar? + /// + /// scrollbar_padding.x is the vertical padding before the horizontal scrollbar. scrollbar_padding: Vec2, /// Initial position of the cursor when dragging. @@ -364,7 +366,9 @@ where let available = self.available_size(); // The number of steps is 1 + the "extra space" let steps = (available + (1, 1)).saturating_sub(lengths); - steps * self.offset / (self.inner_size + (1, 1) - available) + let max_offset = self.inner_size.saturating_sub(available) + (1, 1); + + steps * self.offset / max_offset } /// Apply the scrolling strategy to the current scroll position.