summaryrefslogtreecommitdiffstats
path: root/lazy/src/pure/component.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2022-03-07 16:33:25 +0700
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2022-03-07 16:35:17 +0700
commitfa3bd4280e7c34354db0a15ef1baba9fbbeb87f1 (patch)
tree091bafa26bb66ff58f6d9f1e920cccfa2ef5de42 /lazy/src/pure/component.rs
parentfbbb864aaa7d4163ffea9ccd39d8097568253c3e (diff)
downloadiced-fa3bd4280e7c34354db0a15ef1baba9fbbeb87f1.tar.gz
iced-fa3bd4280e7c34354db0a15ef1baba9fbbeb87f1.tar.bz2
iced-fa3bd4280e7c34354db0a15ef1baba9fbbeb87f1.zip
Initialize `lazy::pure::Component` view properly
... during `children` and `diff` in the `Widget` implementation
Diffstat (limited to '')
-rw-r--r--lazy/src/pure/component.rs47
1 files changed, 26 insertions, 21 deletions
diff --git a/lazy/src/pure/component.rs b/lazy/src/pure/component.rs
index c79e34f8..ad82c55e 100644
--- a/lazy/src/pure/component.rs
+++ b/lazy/src/pure/component.rs
@@ -101,27 +101,6 @@ where
&self,
f: impl FnOnce(&mut Element<'_, Event, Renderer>) -> T,
) -> T {
- if self
- .state
- .borrow()
- .as_ref()
- .unwrap()
- .borrow_element()
- .is_none()
- {
- let heads = self.state.borrow_mut().take().unwrap().into_heads();
-
- *self.state.borrow_mut() = Some(
- StateBuilder {
- component: heads.component,
- message: PhantomData,
- state: PhantomData,
- element_builder: |state| Some(state.view(&S::default())),
- }
- .build(),
- );
- }
-
self.state
.borrow_mut()
.as_mut()
@@ -145,10 +124,36 @@ where
}
fn children(&self) -> Vec<Tree> {
+ let heads = self.state.borrow_mut().take().unwrap().into_heads();
+
+ *self.state.borrow_mut() = Some(
+ StateBuilder {
+ component: heads.component,
+ message: PhantomData,
+ state: PhantomData,
+ element_builder: |state| Some(state.view(&S::default())),
+ }
+ .build(),
+ );
+
self.with_element(|element| vec![Tree::new(element)])
}
fn diff(&self, tree: &mut Tree) {
+ let heads = self.state.borrow_mut().take().unwrap().into_heads();
+
+ *self.state.borrow_mut() = Some(
+ StateBuilder {
+ component: heads.component,
+ message: PhantomData,
+ state: PhantomData,
+ element_builder: |state| {
+ Some(state.view(tree.state.downcast_ref()))
+ },
+ }
+ .build(),
+ );
+
self.with_element(|element| {
tree.diff_children(std::slice::from_ref(&element))
})