diff options
author | 2020-03-23 20:43:55 +0100 | |
---|---|---|
committer | 2020-03-23 20:43:55 +0100 | |
commit | 0d719bbdf336a022c073986e1e5a91cf632a270c (patch) | |
tree | 912103234bf134221e44fc6405c76beabfc19e50 /examples/download_progress/src/main.rs | |
parent | b92e1f957408e3254e5fe0da389808474de6c4a9 (diff) | |
download | iced-0d719bbdf336a022c073986e1e5a91cf632a270c.tar.gz iced-0d719bbdf336a022c073986e1e5a91cf632a270c.tar.bz2 iced-0d719bbdf336a022c073986e1e5a91cf632a270c.zip |
Handle errors in `download_progress` example
Diffstat (limited to 'examples/download_progress/src/main.rs')
-rw-r--r-- | examples/download_progress/src/main.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/examples/download_progress/src/main.rs b/examples/download_progress/src/main.rs index f3da3d7b..817a45ac 100644 --- a/examples/download_progress/src/main.rs +++ b/examples/download_progress/src/main.rs @@ -14,6 +14,7 @@ enum Example { Idle { button: button::State }, Downloading { progress: f32 }, Finished { button: button::State }, + Errored { button: button::State }, } #[derive(Debug, Clone)] @@ -60,6 +61,11 @@ impl Application for Example { button: button::State::new(), } } + download::Progress::Errored => { + *self = Example::Errored { + button: button::State::new(), + }; + } }, _ => {} }, @@ -83,6 +89,7 @@ impl Application for Example { Example::Idle { .. } => 0.0, Example::Downloading { progress } => *progress, Example::Finished { .. } => 100.0, + Example::Errored { .. } => 0.0, }; let progress_bar = ProgressBar::new(0.0..=100.0, current_progress); @@ -106,6 +113,15 @@ impl Application for Example { Text::new(format!("Downloading... {:.2}%", current_progress)) .into() } + Example::Errored { button } => Column::new() + .spacing(10) + .align_items(Align::Center) + .push(Text::new("Something went wrong :(")) + .push( + Button::new(button, Text::new("Try again")) + .on_press(Message::Download), + ) + .into(), }; let content = Column::new() |