Implement pure version of PaneGrid widget
This commit is contained in:
parent
9f27969d14
commit
6dd187ff08
13 changed files with 2107 additions and 417 deletions
|
|
@ -41,6 +41,19 @@ impl Tree {
|
|||
pub fn diff_children<Message, Renderer>(
|
||||
&mut self,
|
||||
new_children: &[Element<'_, Message, Renderer>],
|
||||
) {
|
||||
self.diff_children_custom(
|
||||
new_children,
|
||||
|new, child_state| child_state.diff(new),
|
||||
Self::new,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn diff_children_custom<T>(
|
||||
&mut self,
|
||||
new_children: &[T],
|
||||
diff: impl Fn(&T, &mut Tree),
|
||||
new_state: impl Fn(&T) -> Self,
|
||||
) {
|
||||
if self.children.len() > new_children.len() {
|
||||
self.children.truncate(new_children.len());
|
||||
|
|
@ -49,12 +62,12 @@ impl Tree {
|
|||
for (child_state, new) in
|
||||
self.children.iter_mut().zip(new_children.iter())
|
||||
{
|
||||
child_state.diff(new);
|
||||
diff(new, child_state);
|
||||
}
|
||||
|
||||
if self.children.len() < new_children.len() {
|
||||
self.children.extend(
|
||||
new_children[self.children.len()..].iter().map(Self::new),
|
||||
new_children[self.children.len()..].iter().map(new_state),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue