perf: create thumbnails, preload
This commit is contained in:
parent
d9751fe2e6
commit
7d45896a6f
1 changed files with 7 additions and 2 deletions
|
|
@ -69,10 +69,14 @@ impl State {
|
||||||
let entry = self.images.entry(path.clone()).or_default();
|
let entry = self.images.entry(path.clone()).or_default();
|
||||||
|
|
||||||
if matches!(entry, MaybeImage::Unloaded) {
|
if matches!(entry, MaybeImage::Unloaded) {
|
||||||
|
let columns = self.columns;
|
||||||
let (task, handle) = Task::perform(
|
let (task, handle) = Task::perform(
|
||||||
async {
|
async move {
|
||||||
utils::load_image(&path)
|
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)
|
.map_err(Arc::new)
|
||||||
},
|
},
|
||||||
Message::ImageLoaded,
|
Message::ImageLoaded,
|
||||||
|
|
@ -163,6 +167,7 @@ impl State {
|
||||||
|| Element::from(widget::space()),
|
|| Element::from(widget::space()),
|
||||||
|handle| widget::image(handle).into(),
|
|handle| widget::image(handle).into(),
|
||||||
))
|
))
|
||||||
|
.anticipate(2000)
|
||||||
.on_show(|_size| Message::LoadImage(path.clone()))
|
.on_show(|_size| Message::LoadImage(path.clone()))
|
||||||
.on_hide(Message::UnloadImage(path.clone())),
|
.on_hide(Message::UnloadImage(path.clone())),
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue