1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
use iced::widget::{
center, center_x, checkbox, column, progress_bar, row, slider,
vertical_slider,
};
use iced::Element;
pub fn main() -> iced::Result {
iced::run("Progress Bar - Iced", Progress::update, Progress::view)
}
#[derive(Default)]
struct Progress {
value: f32,
is_vertical: bool,
}
#[derive(Debug, Clone, Copy)]
enum Message {
SliderChanged(f32),
ToggleVertical(bool),
}
impl Progress {
fn update(&mut self, message: Message) {
match message {
Message::SliderChanged(x) => self.value = x,
Message::ToggleVertical(is_vertical) => {
self.is_vertical = is_vertical
}
}
}
fn view(&self) -> Element<Message> {
let bar = progress_bar(0.0..=100.0, self.value);
column![
if self.is_vertical {
center(
row![
bar.vertical(),
vertical_slider(
0.0..=100.0,
self.value,
Message::SliderChanged
)
.step(0.01)
]
.spacing(20),
)
} else {
center(
column![
bar,
slider(0.0..=100.0, self.value, Message::SliderChanged)
.step(0.01)
]
.spacing(20),
)
},
center_x(
checkbox("Vertical", self.is_vertical)
.on_toggle(Message::ToggleVertical)
),
]
.spacing(20)
.padding(20)
.into()
}
}
|