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 slider #2610

Closed
wants to merge 2 commits into from
Closed
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
17 changes: 12 additions & 5 deletions widget/src/slider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,21 +451,26 @@ where
(start.into() as f32, end.into() as f32)
};

// Given this layout simplification:
// bound1 start value end bound2
// offset will be the distance: value - start
let offset = if range_start >= range_end {
0.0
} else {
// yes, handle_width need to be there
(bounds.width - handle_width) * (value - range_start)
/ (range_end - range_start)
};

let rail_y = bounds.y + bounds.height / 2.0;

// filled bar
renderer.fill_quad(
renderer::Quad {
bounds: Rectangle {
x: bounds.x,
x: bounds.x + handle_width / 2.0,
y: rail_y - style.rail.width / 2.0,
width: offset + handle_width / 2.0,
width: offset,
height: style.rail.width,
},
border: style.rail.border,
Expand All @@ -474,12 +479,13 @@ where
style.rail.backgrounds.0,
);

// background bar
renderer.fill_quad(
renderer::Quad {
bounds: Rectangle {
x: bounds.x + offset + handle_width / 2.0,
x: bounds.x + (handle_width / 2.0) + offset,
y: rail_y - style.rail.width / 2.0,
width: bounds.width - offset - handle_width / 2.0,
width: bounds.width - (handle_width + offset),
height: style.rail.width,
},
border: style.rail.border,
Expand All @@ -488,6 +494,7 @@ where
style.rail.backgrounds.1,
);

// handle
renderer.fill_quad(
renderer::Quad {
bounds: Rectangle {
Expand All @@ -503,7 +510,7 @@ where
},
..renderer::Quad::default()
},
style.handle.background,
Background::Color(Color::WHITE.scale_alpha(0.1)),
);
}

Expand Down
Loading