Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix width of horizontal scrollbar in Scrollable #2084

Merged
merged 3 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/scrollable/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,12 +389,12 @@ impl scrollable::StyleSheet for ScrollbarCustomStyle {
background: style
.active(&theme::Scrollable::default())
.background,
border_radius: 0.0.into(),
border_radius: 2.0.into(),
border_width: 0.0,
border_color: Default::default(),
scroller: Scroller {
color: Color::from_rgb8(250, 85, 134),
border_radius: 0.0.into(),
border_radius: 2.0.into(),
border_width: 0.0,
border_color: Default::default(),
},
Expand Down
20 changes: 10 additions & 10 deletions widget/src/scrollable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1364,15 +1364,15 @@ impl Scrollbars {

let ratio = bounds.height / content_bounds.height;
// min height for easier grabbing with super tall content
let scroller_height = (bounds.height * ratio).max(2.0);
let scroller_offset = translation.y * ratio;
let scroller_height = (scrollbar_bounds.height * ratio).max(2.0);
let scroller_offset =
translation.y * ratio * scrollbar_bounds.height / bounds.height;

let scroller_bounds = Rectangle {
x: bounds.x + bounds.width
- total_scrollbar_width / 2.0
- scroller_width / 2.0,
y: (scrollbar_bounds.y + scroller_offset - x_scrollbar_height)
.max(0.0),
y: (scrollbar_bounds.y + scroller_offset).max(0.0),
width: scroller_width,
height: scroller_height,
};
Expand All @@ -1399,8 +1399,8 @@ impl Scrollbars {

// Need to adjust the width of the horizontal scrollbar if the vertical scrollbar
// is present
let scrollbar_y_width = show_scrollbar_y
.map_or(0.0, |v| v.width.max(v.scroller_width) + v.margin);
let scrollbar_y_width = y_scrollbar
.map_or(0.0, |scrollbar| scrollbar.total_bounds.width);

let total_scrollbar_height =
width.max(scroller_width) + 2.0 * margin;
Expand All @@ -1425,12 +1425,12 @@ impl Scrollbars {

let ratio = bounds.width / content_bounds.width;
// min width for easier grabbing with extra wide content
let scroller_length = (bounds.width * ratio).max(2.0);
let scroller_offset = translation.x * ratio;
let scroller_length = (scrollbar_bounds.width * ratio).max(2.0);
let scroller_offset =
translation.x * ratio * scrollbar_bounds.width / bounds.width;

let scroller_bounds = Rectangle {
x: (scrollbar_bounds.x + scroller_offset - scrollbar_y_width)
.max(0.0),
x: (scrollbar_bounds.x + scroller_offset).max(0.0),
y: bounds.y + bounds.height
- total_scrollbar_height / 2.0
- scroller_width / 2.0,
Expand Down
Loading