diff options
author | 2025-02-11 03:39:42 +0100 | |
---|---|---|
committer | 2025-02-11 03:41:29 +0100 | |
commit | 0c528be2ea74f9aae1d4ac80b282ba9c16674649 (patch) | |
tree | 87108ca5917382a8e6a7d53968896f5ee1f7a617 /examples/gallery/src/main.rs | |
parent | 9f21eae1528fa414adbfb987ce4c851fa58326fe (diff) | |
download | iced-0c528be2ea74f9aae1d4ac80b282ba9c16674649.tar.gz iced-0c528be2ea74f9aae1d4ac80b282ba9c16674649.tar.bz2 iced-0c528be2ea74f9aae1d4ac80b282ba9c16674649.zip |
Introduce `with` helper and use `sipper` in `gallery` example
Diffstat (limited to '')
-rw-r--r-- | examples/gallery/src/main.rs | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/examples/gallery/src/main.rs b/examples/gallery/src/main.rs index 441ad924..0ed2a862 100644 --- a/examples/gallery/src/main.rs +++ b/examples/gallery/src/main.rs @@ -14,7 +14,8 @@ use iced::widget::{ }; use iced::window; use iced::{ - color, Animation, ContentFit, Element, Fill, Subscription, Task, Theme, + color, with, Animation, ContentFit, Element, Fill, Subscription, Task, + Theme, }; use std::collections::HashMap; @@ -40,7 +41,7 @@ enum Message { ImageDownloaded(Result<Rgba, Error>), ThumbnailDownloaded(Id, Result<Rgba, Error>), ThumbnailHovered(Id, bool), - BlurhashDecoded(Id, Result<Rgba, Error>), + BlurhashDecoded(Id, civitai::Blurhash), Open(Id), Close, Animate(Instant), @@ -94,16 +95,14 @@ impl Gallery { return Task::none(); }; - Task::batch([ - Task::future( - image.clone().blurhash(Preview::WIDTH, Preview::HEIGHT), - ) - .map_with(id, Message::BlurhashDecoded), - Task::future(image.download(Size::Thumbnail { + Task::sip( + image.download(Size::Thumbnail { width: Preview::WIDTH, - })) - .map_with(id, Message::ThumbnailDownloaded), - ]) + height: Preview::HEIGHT, + }), + with(Message::BlurhashDecoded, id), + with(Message::ThumbnailDownloaded, id), + ) } Message::ImageDownloaded(Ok(rgba)) => { self.viewer.show(rgba); @@ -129,9 +128,11 @@ impl Gallery { Task::none() } - Message::BlurhashDecoded(id, Ok(rgba)) => { + Message::BlurhashDecoded(id, blurhash) => { if !self.previews.contains_key(&id) { - let _ = self.previews.insert(id, Preview::loading(rgba)); + let _ = self + .previews + .insert(id, Preview::loading(blurhash.rgba)); } Task::none() @@ -165,8 +166,7 @@ impl Gallery { } Message::ImagesListed(Err(error)) | Message::ImageDownloaded(Err(error)) - | Message::ThumbnailDownloaded(_, Err(error)) - | Message::BlurhashDecoded(_, Err(error)) => { + | Message::ThumbnailDownloaded(_, Err(error)) => { dbg!(error); Task::none() |