Skip to content

Commit

Permalink
Merge pull request #527 from rubik83/master
Browse files Browse the repository at this point in the history
Account for empty ranges in `Slider` and `ProgressBar`
  • Loading branch information
hecrj authored Nov 26, 2020
2 parents 1f7e8b7 + c23136a commit 50a1f78
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
9 changes: 6 additions & 3 deletions graphics/src/widget/progress_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@ where
style_sheet: &Self::Style,
) -> Self::Output {
let style = style_sheet.style();

let (range_start, range_end) = range.into_inner();
let active_progress_width = bounds.width
* ((value - range_start) / (range_end - range_start).max(1.0));

let active_progress_width = if range_start >= range_end {
0.0
} else {
bounds.width * (value - range_start) / (range_end - range_start)
};

let background = Primitive::Group {
primitives: vec![Primitive::Quad {
Expand Down
12 changes: 8 additions & 4 deletions graphics/src/widget/slider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ where
},
);

let (range_start, range_end) = range.into_inner();

let (handle_width, handle_height, handle_border_radius) = match style
.handle
.shape
Expand All @@ -87,8 +85,14 @@ where
} => (f32::from(width), f32::from(bounds.height), border_radius),
};

let handle_offset = (bounds.width - handle_width)
* ((value - range_start) / (range_end - range_start).max(1.0));
let (range_start, range_end) = range.into_inner();

let handle_offset = if range_start >= range_end {
0.0
} else {
(bounds.width - handle_width) * (value - range_start)
/ (range_end - range_start)
};

let handle = Primitive::Quad {
bounds: Rectangle {
Expand Down

0 comments on commit 50a1f78

Please sign in to comment.