Move the lazy_load logic to a Generic function.
This commit is contained in:
parent
d618771125
commit
83abb5a825
@ -383,17 +383,9 @@ pub fn episodes_listbox(pd: Arc<Podcast>, sender: Sender<Action>) -> Result<gtk:
|
|||||||
Err(Disconnected) => return glib::Continue(false),
|
Err(Disconnected) => return glib::Continue(false),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut idx = 0;
|
lazy_load(episodes, list.clone(), clone!(sender => move |ep| {
|
||||||
gtk::idle_add(clone!(list, sender => move || {
|
let w = EpisodeWidget::new(ep, sender.clone());
|
||||||
if idx >= episodes.len() { return glib::Continue(false) }
|
w.container.clone()
|
||||||
|
|
||||||
episodes.get(idx).cloned().map(|ep| {
|
|
||||||
let widget = EpisodeWidget::new(ep, sender.clone());
|
|
||||||
list.add(&widget.container);
|
|
||||||
});
|
|
||||||
|
|
||||||
idx += 1;
|
|
||||||
glib::Continue(true)
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
glib::Continue(false)
|
glib::Continue(false)
|
||||||
@ -401,3 +393,28 @@ pub fn episodes_listbox(pd: Arc<Podcast>, sender: Sender<Action>) -> Result<gtk:
|
|||||||
|
|
||||||
Ok(list)
|
Ok(list)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
use gtk::{IsA, Widget};
|
||||||
|
|
||||||
|
fn lazy_load<T, U, P, Z>(data: Vec<T>, container: Z, mut predicate: P)
|
||||||
|
where
|
||||||
|
T: Clone + 'static,
|
||||||
|
Z: ContainerExt + 'static,
|
||||||
|
P: FnMut(T) -> U + 'static,
|
||||||
|
U: IsA<Widget>,
|
||||||
|
{
|
||||||
|
let mut idx = 0;
|
||||||
|
gtk::idle_add(move || {
|
||||||
|
if idx >= data.len() {
|
||||||
|
return glib::Continue(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
data.get(idx).cloned().map(|x| {
|
||||||
|
let widget = predicate(x);
|
||||||
|
container.add(&widget);
|
||||||
|
});
|
||||||
|
|
||||||
|
idx += 1;
|
||||||
|
glib::Continue(true)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user