h-gtk:utils Add a more flexible implementation of lazy_load.
lazy_load_full is meant for siturations that you don't need the constraisn of passing a single container parent and adding a sigle widget to it. Reimplemnted lazy_load on top of lazy_load_full.
This commit is contained in:
parent
2d291a08fc
commit
08365c412a
@ -70,11 +70,26 @@ where
|
||||
C: ContainerExt + 'static,
|
||||
F: FnMut(T::Item) -> W + 'static,
|
||||
W: IsA<Widget>,
|
||||
{
|
||||
let func = move |x| container.add(&contructor(x));
|
||||
lazy_load_full(data, func);
|
||||
}
|
||||
|
||||
/// Iterate over `data` and execute `func` using a `glib::idle_add()`.
|
||||
///
|
||||
/// This is a more flexible version of `lazy_load` with less constrains.
|
||||
/// If you just want to lazy add `widgets` to a `container` check if
|
||||
/// `lazy_load` fits your needs first.
|
||||
pub fn lazy_load_full<T, F>(data: T, mut func: F)
|
||||
where
|
||||
T: IntoIterator + 'static,
|
||||
T::Item: 'static,
|
||||
F: FnMut(T::Item) + 'static,
|
||||
{
|
||||
let mut data = data.into_iter();
|
||||
gtk::idle_add(move || {
|
||||
data.next()
|
||||
.map(|x| container.add(&contructor(x)))
|
||||
.map(|x| func(x))
|
||||
.map(|_| glib::Continue(true))
|
||||
.unwrap_or(glib::Continue(false))
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user