perf: create thumbnails, preload

This commit is contained in:
electria 2026-08-09 15:53:48 -07:00
commit 7d45896a6f
Signed by: electria
SSH key fingerprint: SHA256:8LlB3ucPbBHqozqkhsNbaV5oG3SlzzqUj8FZDL6IPQs

View file

@ -69,10 +69,14 @@ impl State {
let entry = self.images.entry(path.clone()).or_default();
if matches!(entry, MaybeImage::Unloaded) {
let columns = self.columns;
let (task, handle) = Task::perform(
async {
async move {
utils::load_image(&path)
.map(|img| (path, handle_from_image(img)))
.map(|img| {
let size = 1000 / columns as u32;
(path, handle_from_image(img.thumbnail(size, size)))
})
.map_err(Arc::new)
},
Message::ImageLoaded,
@ -163,6 +167,7 @@ impl State {
|| Element::from(widget::space()),
|handle| widget::image(handle).into(),
))
.anticipate(2000)
.on_show(|_size| Message::LoadImage(path.clone()))
.on_hide(Message::UnloadImage(path.clone())),
)