From 08365c412a93984568c304295e7eae179f58db0c Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Tue, 17 Apr 2018 02:33:32 +0300 Subject: [PATCH] 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. --- hammond-gtk/src/utils.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/hammond-gtk/src/utils.rs b/hammond-gtk/src/utils.rs index fadad58..3d54ef4 100644 --- a/hammond-gtk/src/utils.rs +++ b/hammond-gtk/src/utils.rs @@ -70,11 +70,26 @@ where C: ContainerExt + 'static, F: FnMut(T::Item) -> W + 'static, W: IsA, +{ + 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(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)) });