Improve layout when two scrollbars are shown
This commit is contained in:
parent
1f2d18e691
commit
a067729525
1 changed files with 68 additions and 57 deletions
|
@ -984,10 +984,18 @@ impl<S: ScrollbarVisibilitySetting, T: ScrollableHandle> Element for ScrollbarEl
|
|||
.not()
|
||||
.then(|| ScrollbarPrepaintState {
|
||||
parent_bounds: bounds,
|
||||
thumbs: self
|
||||
.state
|
||||
.read(cx)
|
||||
.thumb_ranges()
|
||||
thumbs: {
|
||||
let thumb_ranges = self.state.read(cx).thumb_ranges().collect::<Vec<_>>();
|
||||
let width = self.state.read(cx).width.to_pixels();
|
||||
|
||||
let additional_padding = if thumb_ranges.len() == 2 {
|
||||
width + SCROLLBAR_PADDING
|
||||
} else {
|
||||
Pixels::ZERO
|
||||
};
|
||||
|
||||
thumb_ranges
|
||||
.into_iter()
|
||||
.map(|(axis, thumb_range, reserved_space)| {
|
||||
let track_anchor = match axis {
|
||||
ScrollbarAxis::Horizontal => Corner::BottomLeft,
|
||||
|
@ -997,10 +1005,10 @@ impl<S: ScrollbarVisibilitySetting, T: ScrollableHandle> Element for ScrollbarEl
|
|||
track_anchor,
|
||||
bounds
|
||||
.corner(track_anchor)
|
||||
.apply_along(axis.invert(), |corner| corner - SCROLLBAR_PADDING),
|
||||
bounds.size.apply_along(axis.invert(), |_| {
|
||||
self.state.read(cx).width.to_pixels()
|
||||
.apply_along(axis.invert(), |corner| {
|
||||
corner - SCROLLBAR_PADDING
|
||||
}),
|
||||
bounds.size.apply_along(axis.invert(), |_| width),
|
||||
);
|
||||
let scroll_track_bounds = Bounds::new(self.origin + origin, size);
|
||||
|
||||
|
@ -1017,9 +1025,11 @@ impl<S: ScrollbarVisibilitySetting, T: ScrollableHandle> Element for ScrollbarEl
|
|||
},
|
||||
});
|
||||
|
||||
let thumb_offset = thumb_range.start * padded_bounds.size.along(axis);
|
||||
let thumb_end = thumb_range.end * padded_bounds.size.along(axis);
|
||||
let available_space =
|
||||
padded_bounds.size.along(axis) - additional_padding;
|
||||
|
||||
let thumb_offset = thumb_range.start * available_space;
|
||||
let thumb_end = thumb_range.end * available_space;
|
||||
let thumb_bounds = Bounds::new(
|
||||
padded_bounds
|
||||
.origin
|
||||
|
@ -1044,7 +1054,8 @@ impl<S: ScrollbarVisibilitySetting, T: ScrollableHandle> Element for ScrollbarEl
|
|||
reserved_space,
|
||||
}
|
||||
})
|
||||
.collect(),
|
||||
.collect()
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue