diff options
author | 2023-01-11 07:45:36 -0800 | |
---|---|---|
committer | 2023-01-11 11:37:56 -0800 | |
commit | 58bcc4404e0083276576299217fe6e3187d0ef14 (patch) | |
tree | e4777ad00ba580dca912ff695f5244bf8e9017de /lazy | |
parent | ca337b880f82b3da264ac1626f973f8be29e95f4 (diff) | |
download | iced-58bcc4404e0083276576299217fe6e3187d0ef14.tar.gz iced-58bcc4404e0083276576299217fe6e3187d0ef14.tar.bz2 iced-58bcc4404e0083276576299217fe6e3187d0ef14.zip |
feat: provide `&Dependency` to `Lazy` widget `View`
Diffstat (limited to 'lazy')
-rw-r--r-- | lazy/src/lazy.rs | 12 | ||||
-rw-r--r-- | lazy/src/lib.rs | 2 |
2 files changed, 9 insertions, 5 deletions
diff --git a/lazy/src/lazy.rs b/lazy/src/lazy.rs index 16709f8d..933def96 100644 --- a/lazy/src/lazy.rs +++ b/lazy/src/lazy.rs @@ -16,7 +16,7 @@ use std::rc::Rc; #[allow(missing_debug_implementations)] pub struct Lazy<'a, Message, Renderer, Dependency, View> { dependency: Dependency, - view: Box<dyn Fn() -> View + 'a>, + view: Box<dyn Fn(&Dependency) -> View + 'a>, element: RefCell< Option<Rc<RefCell<Option<Element<'static, Message, Renderer>>>>>, >, @@ -28,7 +28,10 @@ where Dependency: Hash + 'a, View: Into<Element<'static, Message, Renderer>>, { - pub fn new(dependency: Dependency, view: impl Fn() -> View + 'a) -> Self { + pub fn new( + dependency: Dependency, + view: impl Fn(&Dependency) -> View + 'a, + ) -> Self { Self { dependency, view: Box::new(view), @@ -88,7 +91,8 @@ where self.dependency.hash(&mut hasher); let hash = hasher.finish(); - let element = Rc::new(RefCell::new(Some((self.view)().into()))); + let element = + Rc::new(RefCell::new(Some((self.view)(&self.dependency).into()))); (*self.element.borrow_mut()) = Some(element.clone()); @@ -109,7 +113,7 @@ where if current.hash != new_hash { current.hash = new_hash; - let element = (self.view)().into(); + let element = (self.view)(&self.dependency).into(); current.element = Rc::new(RefCell::new(Some(element))); (*self.element.borrow_mut()) = Some(current.element.clone()); diff --git a/lazy/src/lib.rs b/lazy/src/lib.rs index f49fe4b6..41a28773 100644 --- a/lazy/src/lib.rs +++ b/lazy/src/lib.rs @@ -33,7 +33,7 @@ use std::hash::Hash; pub fn lazy<'a, Message, Renderer, Dependency, View>( dependency: Dependency, - view: impl Fn() -> View + 'a, + view: impl Fn(&Dependency) -> View + 'a, ) -> Lazy<'a, Message, Renderer, Dependency, View> where Dependency: Hash + 'a, |