Skip to content

Commit

Permalink
widget: slider: Fix max_step_value calculation
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher N. Hesse <[email protected]>
  • Loading branch information
raymanfx committed Jul 25, 2021
1 parent 1b91b8b commit cfdcc87
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions druid/src/widget/slider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,7 @@ impl Slider {
.min(1.0);
let mut value = self.min + scalar * (self.max - self.min);
if let Some(step) = self.step {
let make_discrete = |value: f64, step: f64, min: f64, max: f64| {
(((value - min) / step).round() * step + min).min(max)
};
let max_step_value = make_discrete(self.max, step, self.min, self.max);
let max_step_value = ((self.max - self.min) / step).floor() * step + self.min;
if value > max_step_value {
// edge case: make sure max is reachable
let left_dist = value - max_step_value;
Expand All @@ -105,7 +102,7 @@ impl Slider {
};
} else {
// snap to discrete intervals
value = make_discrete(value, step, self.min, self.max);
value = (((value - self.min) / step).round() * step + self.min).min(self.max);
}
}
value
Expand Down

0 comments on commit cfdcc87

Please sign in to comment.