diff options
author | 2023-06-06 16:18:20 +0200 | |
---|---|---|
committer | 2023-06-06 16:18:20 +0200 | |
commit | 5b5000e3ae9789cf1d83cecd08f4d0cedc16d788 (patch) | |
tree | d7f0851d872ec8fbff733fb9ab804cdb3b55c4e0 /examples/screenshot | |
parent | 5324928044cba800454b1861eb9999038bc28c2e (diff) | |
download | iced-5b5000e3ae9789cf1d83cecd08f4d0cedc16d788.tar.gz iced-5b5000e3ae9789cf1d83cecd08f4d0cedc16d788.tar.bz2 iced-5b5000e3ae9789cf1d83cecd08f4d0cedc16d788.zip |
Introduce `on_press_maybe` helper for `Button`
Diffstat (limited to 'examples/screenshot')
-rw-r--r-- | examples/screenshot/src/main.rs | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/examples/screenshot/src/main.rs b/examples/screenshot/src/main.rs index 7d53b3b2..be39f829 100644 --- a/examples/screenshot/src/main.rs +++ b/examples/screenshot/src/main.rs @@ -79,12 +79,13 @@ impl Application for Example { } Message::Png => { if let Some(screenshot) = &self.screenshot { + self.png_saving = true; + return Command::perform( save_to_png(screenshot.clone()), Message::PngSaved, ); } - self.png_saving = true; } Message::PngSaved(res) => { self.png_saving = false; @@ -185,7 +186,7 @@ impl Application for Example { button("Save to png") .style(Button::Secondary) .padding([10, 20, 10, 20]) - .on_press(Message::Png) + .on_press_maybe(self.screenshot.is_some().then(|| Message::Png)) } else { button("Saving...") .style(Button::Secondary) |