Skip to content

Commit 563f6c6

Browse files
coolreader18NoraCodes
authored andcommitted
Add doc comments, rename ProgressBarStyle to ProgressBarValue
1 parent b85808f commit 563f6c6

File tree

1 file changed

+37
-17
lines changed

1 file changed

+37
-17
lines changed

iui/src/controls/progressbar.rs

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,50 +3,70 @@ use std::mem;
33
use ui::UI;
44
use ui_sys::{self, uiControl, uiProgressBar};
55

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+
615
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
823
rust_type: ProgressBar,
924
sys_type: uiProgressBar,
1025
}
1126

12-
pub enum ProgressBarStyle {
13-
Determinate(u32),
14-
Indeterminate,
15-
}
16-
1727
impl ProgressBar {
28+
/// Create a new progress bar with a value of 0
1829
pub fn new() -> ProgressBar {
1930
unsafe { ProgressBar::from_raw(ui_sys::uiNewProgressBar()) }
2031
}
2132

33+
/// Create a new indeterminate progress bar
2234
pub fn indeterminate() -> ProgressBar {
2335
let mut pb = ProgressBar::new();
24-
pb.set_value(ProgressBarStyle::Indeterminate);
36+
pb.set_indeterminate();
2537
pb
2638
}
2739

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) {
2952
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,
3255
};
3356
unsafe { ui_sys::uiProgressBarSetValue(self.uiProgressBar, sys_value) }
3457
}
3558

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 {
4161
let sys_value = unsafe { ui_sys::uiProgressBarValue(self.uiProgressBar) };
4262
if sys_value.is_negative() {
4363
assert!(
4464
sys_value == -1,
4565
"if ProgressBar value is negative it can only be -1"
4666
);
47-
ProgressBarStyle::Indeterminate
67+
ProgressBarValue::Indeterminate
4868
} else {
49-
ProgressBarStyle::Determinate(sys_value as u32)
69+
ProgressBarValue::Determinate(sys_value as u32)
5070
}
5171
}
5272
}

0 commit comments

Comments
 (0)