@@ -3,50 +3,70 @@ use std::mem;
3
3
use ui:: UI ;
4
4
use ui_sys:: { self , uiControl, uiProgressBar} ;
5
5
6
+ /// An enum representing the value of a `ProgressBar`
7
+ pub enum ProgressBarValue {
8
+ /// Represents a set, consistent percentage of the bar to be filled
9
+ Determinate ( u32 ) ,
10
+ /// Represents an indeterminate value of the progress bar, useful
11
+ /// if you don't know how much of the task being represented is completed
12
+ Indeterminate ,
13
+ }
14
+
6
15
define_control ! {
7
- /// A bar that fills up with a set percentage, used to show completion of a task
16
+ /// A bar that fills up with a set percentage, used to show completion of a
17
+ ///
18
+ /// # Values
19
+ /// A `ProgressBar` can be either determinate or indeterminate. See [`ProgressBarValue`]
20
+ /// for an explanation of the differences.
21
+ ///
22
+ /// [`ProgressBarValue`]: enum.ProgressBarValue.html
8
23
rust_type: ProgressBar ,
9
24
sys_type: uiProgressBar,
10
25
}
11
26
12
- pub enum ProgressBarStyle {
13
- Determinate ( u32 ) ,
14
- Indeterminate ,
15
- }
16
-
17
27
impl ProgressBar {
28
+ /// Create a new progress bar with a value of 0
18
29
pub fn new ( ) -> ProgressBar {
19
30
unsafe { ProgressBar :: from_raw ( ui_sys:: uiNewProgressBar ( ) ) }
20
31
}
21
32
33
+ /// Create a new indeterminate progress bar
22
34
pub fn indeterminate ( ) -> ProgressBar {
23
35
let mut pb = ProgressBar :: new ( ) ;
24
- pb. set_value ( ProgressBarStyle :: Indeterminate ) ;
36
+ pb. set_indeterminate ( ) ;
25
37
pb
26
38
}
27
39
28
- pub fn set_value ( & mut self , value : ProgressBarStyle ) {
40
+ /// Set the value of the progress bar to a determinate value
41
+ pub fn set_determinate ( & mut self , value : u32 ) {
42
+ self . set_value ( ProgressBarValue :: Determinate ( value) ) ;
43
+ }
44
+
45
+ /// Set the value of the progress bar to be indeterminate
46
+ pub fn set_indeterminate ( & mut self ) {
47
+ self . set_value ( ProgressBarValue :: Indeterminate ) ;
48
+ }
49
+
50
+ /// Set the value of the progress bar
51
+ pub fn set_value ( & mut self , value : ProgressBarValue ) {
29
52
let sys_value = match value {
30
- ProgressBarStyle :: Determinate ( value) => value as i32 ,
31
- ProgressBarStyle :: Indeterminate => -1 ,
53
+ ProgressBarValue :: Determinate ( value) => value as i32 ,
54
+ ProgressBarValue :: Indeterminate => -1 ,
32
55
} ;
33
56
unsafe { ui_sys:: uiProgressBarSetValue ( self . uiProgressBar , sys_value) }
34
57
}
35
58
36
- pub fn set_determinate ( & mut self , value : u32 ) {
37
- self . set_value ( ProgressBarStyle :: Determinate ( value) ) ;
38
- }
39
-
40
- pub fn value ( & self ) -> ProgressBarStyle {
59
+ /// Get the value of the progress bar
60
+ pub fn value ( & self ) -> ProgressBarValue {
41
61
let sys_value = unsafe { ui_sys:: uiProgressBarValue ( self . uiProgressBar ) } ;
42
62
if sys_value. is_negative ( ) {
43
63
assert ! (
44
64
sys_value == -1 ,
45
65
"if ProgressBar value is negative it can only be -1"
46
66
) ;
47
- ProgressBarStyle :: Indeterminate
67
+ ProgressBarValue :: Indeterminate
48
68
} else {
49
- ProgressBarStyle :: Determinate ( sys_value as u32 )
69
+ ProgressBarValue :: Determinate ( sys_value as u32 )
50
70
}
51
71
}
52
72
}
0 commit comments