HomeEpisode: Do not initialize the Image until it needs to be drawn.
This commit is contained in:
parent
39e6c258d5
commit
6036562af2
@ -13,6 +13,7 @@ use app::Action;
|
|||||||
use utils::{self, lazy_load_full};
|
use utils::{self, lazy_load_full};
|
||||||
use widgets::EpisodeWidget;
|
use widgets::EpisodeWidget;
|
||||||
|
|
||||||
|
use std::cell::Cell;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
|
|
||||||
@ -216,14 +217,27 @@ impl HomeEpisode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn init(&self, show_id: i32) {
|
fn init(&self, show_id: i32) {
|
||||||
self.set_cover(show_id)
|
self.set_cover(show_id);
|
||||||
.map_err(|err| error!("Failed to set a cover: {}", err))
|
|
||||||
.ok();
|
|
||||||
|
|
||||||
self.container.pack_start(&self.episode, true, true, 6);
|
self.container.pack_start(&self.episode, true, true, 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_cover(&self, show_id: i32) -> Result<(), Error> {
|
fn set_cover(&self, show_id: i32) {
|
||||||
utils::set_image_from_path(&self.image, show_id, 64)
|
// The closure above is a regular `Fn` closure.
|
||||||
|
// which means we can't mutate stuff inside it easily,
|
||||||
|
// so Cell is used.
|
||||||
|
//
|
||||||
|
// `Option<T>` along with the `.take()` method ensure
|
||||||
|
// that the function will only be run once, during the first execution.
|
||||||
|
let show_id = Cell::new(Some(show_id));
|
||||||
|
|
||||||
|
self.image.connect_draw(move |image, _| {
|
||||||
|
show_id.take().map(|id| {
|
||||||
|
utils::set_image_from_path(image, id, 64)
|
||||||
|
.map_err(|err| error!("Failed to set a cover: {}", err))
|
||||||
|
.ok();
|
||||||
|
});
|
||||||
|
|
||||||
|
gtk::Inhibit(false)
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user