mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 17:35:00 +00:00
Fix possible panic in scrollview with full-height bar
This commit is contained in:
parent
2167ba68a1
commit
2f0f632e22
@ -306,9 +306,15 @@ where
|
|||||||
|
|
||||||
// The new offset is:
|
// The new offset is:
|
||||||
// thumb_pos * (content + 1 - available) / (available + 1 - thumb size)
|
// thumb_pos * (content + 1 - available) / (available + 1 - thumb size)
|
||||||
let new_offset = ((self.inner_size + (1, 1)).saturating_sub(available)
|
let extra =
|
||||||
* thumb_pos)
|
(available + (1, 1)).saturating_sub(lengths).or_max((1, 1));
|
||||||
.div_up((available + (1, 1)).saturating_sub(lengths));
|
|
||||||
|
// 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());
|
let max_offset = self.inner_size.saturating_sub(self.available_size());
|
||||||
self.offset
|
self.offset
|
||||||
.set_axis_from(orientation, &new_offset.or_min(max_offset));
|
.set_axis_from(orientation, &new_offset.or_min(max_offset));
|
||||||
@ -376,7 +382,9 @@ where
|
|||||||
|
|
||||||
fn scrollbar_thumb_lengths(&self) -> Vec2 {
|
fn scrollbar_thumb_lengths(&self) -> Vec2 {
|
||||||
let available = self.available_size();
|
let available = self.available_size();
|
||||||
(available * available / self.inner_size.or_max((1,1))).or_max((1, 1))
|
// The length should be (visible / total) * visible
|
||||||
|
|
||||||
|
(available * available / self.inner_size.or_max((1, 1))).or_max((1, 1))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn scrollbar_thumb_offsets(&self, lengths: Vec2) -> Vec2 {
|
fn scrollbar_thumb_offsets(&self, lengths: Vec2) -> Vec2 {
|
||||||
@ -530,11 +538,10 @@ where
|
|||||||
position,
|
position,
|
||||||
offset,
|
offset,
|
||||||
}
|
}
|
||||||
if self.show_scrollbars
|
if self.show_scrollbars && position
|
||||||
&& position
|
.checked_sub(offset)
|
||||||
.checked_sub(offset)
|
.map(|position| self.start_drag(position))
|
||||||
.map(|position| self.start_drag(position))
|
.unwrap_or(false) =>
|
||||||
.unwrap_or(false) =>
|
|
||||||
{
|
{
|
||||||
// Just consume the event.
|
// Just consume the event.
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user