Skip to content

Commit 896e7f8

Browse files
coolreader18NoraCodes
authored andcommitted
Cap ProgressBarValue::Determinate to 100 in set_value
1 parent e20ac89 commit 896e7f8

File tree

1 file changed

+2
-14
lines changed

1 file changed

+2
-14
lines changed

iui/src/controls/progressbar.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use ui_sys::{self, uiControl, uiProgressBar};
77
pub enum ProgressBarValue {
88
/// Represents a set, consistent percentage of the bar to be filled
99
///
10-
/// The u32 should be in the range 0..=100
10+
/// The value should be in the range 0..=100
1111
Determinate(u32),
1212
/// Represents an indeterminate value of the progress bar, useful
1313
/// if you don't know how much of the task being represented is completed
@@ -40,10 +40,6 @@ impl ProgressBar {
4040
}
4141

4242
/// Set the value of the progress bar to a determinate value
43-
///
44-
/// # Panics
45-
///
46-
/// This function will panic if `value` is not in the range 0..=100
4743
pub fn set_determinate(&mut self, value: u32) {
4844
self.set_value(ProgressBarValue::Determinate(value));
4945
}
@@ -54,18 +50,10 @@ impl ProgressBar {
5450
}
5551

5652
/// Set the value of the progress bar
57-
///
58-
/// # Panics
59-
///
60-
/// This function will panic if the value is `Determinate` and its value is not
61-
/// in the range 0..=100
6253
pub fn set_value(&mut self, value: ProgressBarValue) {
6354
let sys_value = match value {
6455
ProgressBarValue::Determinate(value) => {
65-
assert!(match value {
66-
0..=100 => true,
67-
_ => false,
68-
});
56+
let value = if value > 100 { 100 } else { value };
6957
value as i32
7058
}
7159
ProgressBarValue::Indeterminate => -1,

0 commit comments

Comments
 (0)