summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2025-01-24 21:41:18 +0100
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2025-01-24 21:41:18 +0100
commita22d96aae9af62b8aacc3132914c3f92a47c8c18 (patch)
tree7baf562411f9dffb0adb00265f62985f5e0da293 /examples
parent5eedf5798c0fcd92cfd3f304ce9454bb6c274f09 (diff)
downloadiced-a22d96aae9af62b8aacc3132914c3f92a47c8c18.tar.gz
iced-a22d96aae9af62b8aacc3132914c3f92a47c8c18.tar.bz2
iced-a22d96aae9af62b8aacc3132914c3f92a47c8c18.zip
Implement support for vertical `ProgressBar`
Co-authored-by: MG_REX <49415741+ThisIsRex@users.noreply.github.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/progress_bar/src/main.rs42
1 files changed, 39 insertions, 3 deletions
diff --git a/examples/progress_bar/src/main.rs b/examples/progress_bar/src/main.rs
index 67da62f2..e431a404 100644
--- a/examples/progress_bar/src/main.rs
+++ b/examples/progress_bar/src/main.rs
@@ -1,4 +1,7 @@
-use iced::widget::{column, progress_bar, slider};
+use iced::widget::{
+ center, center_x, checkbox, column, progress_bar, row, slider,
+ vertical_slider,
+};
use iced::Element;
pub fn main() -> iced::Result {
@@ -8,25 +11,58 @@ pub fn main() -> iced::Result {
#[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![
- progress_bar(0.0..=100.0, self.value),
- slider(0.0..=100.0, self.value, Message::SliderChanged).step(0.01)
+ 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()
}