@@ -6,6 +6,8 @@ use ui_sys::{self, uiControl, uiProgressBar};
6
6
/// An enum representing the value of a `ProgressBar`
7
7
pub enum ProgressBarValue {
8
8
/// Represents a set, consistent percentage of the bar to be filled
9
+ ///
10
+ /// The u32 should be in the range 0..=100
9
11
Determinate ( u32 ) ,
10
12
/// Represents an indeterminate value of the progress bar, useful
11
13
/// if you don't know how much of the task being represented is completed
@@ -38,6 +40,10 @@ impl ProgressBar {
38
40
}
39
41
40
42
/// 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
41
47
pub fn set_determinate ( & mut self , value : u32 ) {
42
48
self . set_value ( ProgressBarValue :: Determinate ( value) ) ;
43
49
}
@@ -48,9 +54,20 @@ impl ProgressBar {
48
54
}
49
55
50
56
/// 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
51
62
pub fn set_value ( & mut self , value : ProgressBarValue ) {
52
63
let sys_value = match value {
53
- ProgressBarValue :: Determinate ( value) => value as i32 ,
64
+ ProgressBarValue :: Determinate ( value) => {
65
+ assert ! ( match value {
66
+ 0 ..=100 => true ,
67
+ _ => false ,
68
+ } ) ;
69
+ value as i32
70
+ }
54
71
ProgressBarValue :: Indeterminate => -1 ,
55
72
} ;
56
73
unsafe { ui_sys:: uiProgressBarSetValue ( self . uiProgressBar , sys_value) }
0 commit comments