Fix possible panic in scrollview with full-height bar
@@ -306,9 +306,15 @@ where
// The new offset is:
// thumb_pos * (content + 1 - available) / (available + 1 - thumb size)
- let new_offset = ((self.inner_size + (1, 1)).saturating_sub(available)
- * thumb_pos)
- .div_up((available + (1, 1)).saturating_sub(lengths));
+ let extra =
+ (available + (1, 1)).saturating_sub(lengths).or_max((1, 1));
+
+ // We're dividing by this value, so make sure it's positive!
+ assert!(extra > Vec2::zero());
+
+ let new_offset =
+ ((self.inner_size + (1, 1)).saturating_sub(available) * thumb_pos)
+ .div_up(extra);
let max_offset = self.inner_size.saturating_sub(self.available_size());
self.offset
.set_axis_from(orientation, &new_offset.or_min(max_offset));
@@ -376,6 +382,8 @@ where
fn scrollbar_thumb_lengths(&self) -> Vec2 {
let available = self.available_size();
+ // The length should be (visible / total) * visible
+
(available * available / self.inner_size.or_max((1, 1))).or_max((1, 1))
}
@@ -530,8 +538,7 @@ where
position,
offset,
}
- if self.show_scrollbars
- && position
+ if self.show_scrollbars && position
.checked_sub(offset)
.map(|position| self.start_drag(position))
.unwrap_or(false) =>
