Make Widget::diff mutable
This commit is contained in:
parent
31bc6d48cd
commit
497ebcd0c3
31 changed files with 114 additions and 81 deletions
|
|
@ -223,8 +223,8 @@ where
|
|||
vec![Tree::new(&self.content)]
|
||||
}
|
||||
|
||||
fn diff(&self, tree: &mut Tree) {
|
||||
tree.diff_children(std::slice::from_ref(&self.content));
|
||||
fn diff(&mut self, tree: &mut Tree) {
|
||||
tree.diff_children(std::slice::from_mut(&mut self.content));
|
||||
}
|
||||
|
||||
fn size(&self) -> Size<Length> {
|
||||
|
|
|
|||
|
|
@ -194,8 +194,8 @@ where
|
|||
self.children.iter().map(Tree::new).collect()
|
||||
}
|
||||
|
||||
fn diff(&self, tree: &mut Tree) {
|
||||
tree.diff_children(&self.children);
|
||||
fn diff(&mut self, tree: &mut Tree) {
|
||||
tree.diff_children(&mut self.children);
|
||||
}
|
||||
|
||||
fn size(&self) -> Size<Length> {
|
||||
|
|
|
|||
|
|
@ -509,7 +509,7 @@ where
|
|||
vec![widget::Tree::new(&self.text_input as &dyn Widget<_, _, _>)]
|
||||
}
|
||||
|
||||
fn diff(&self, _tree: &mut widget::Tree) {
|
||||
fn diff(&mut self, _tree: &mut widget::Tree) {
|
||||
// do nothing so the children don't get cleared
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -247,8 +247,8 @@ where
|
|||
self.content.as_widget().children()
|
||||
}
|
||||
|
||||
fn diff(&self, tree: &mut Tree) {
|
||||
self.content.as_widget().diff(tree);
|
||||
fn diff(&mut self, tree: &mut Tree) {
|
||||
self.content.as_widget_mut().diff(tree);
|
||||
}
|
||||
|
||||
fn size(&self) -> Size<Length> {
|
||||
|
|
|
|||
|
|
@ -103,8 +103,8 @@ where
|
|||
self.content.as_widget().children()
|
||||
}
|
||||
|
||||
fn diff(&self, tree: &mut widget::Tree) {
|
||||
self.content.as_widget().diff(tree);
|
||||
fn diff(&mut self, tree: &mut widget::Tree) {
|
||||
self.content.as_widget_mut().diff(tree);
|
||||
}
|
||||
|
||||
fn size(&self) -> Size<Length> {
|
||||
|
|
|
|||
|
|
@ -158,8 +158,8 @@ where
|
|||
self.children.iter().map(Tree::new).collect()
|
||||
}
|
||||
|
||||
fn diff(&self, tree: &mut Tree) {
|
||||
tree.diff_children(&self.children);
|
||||
fn diff(&mut self, tree: &mut Tree) {
|
||||
tree.diff_children(&mut self.children);
|
||||
}
|
||||
|
||||
fn size(&self) -> Size<Length> {
|
||||
|
|
|
|||
|
|
@ -596,8 +596,8 @@ where
|
|||
self.content.as_widget().children()
|
||||
}
|
||||
|
||||
fn diff(&self, tree: &mut Tree) {
|
||||
self.content.as_widget().diff(tree);
|
||||
fn diff(&mut self, tree: &mut Tree) {
|
||||
self.content.as_widget_mut().diff(tree);
|
||||
}
|
||||
|
||||
fn size(&self) -> Size<Length> {
|
||||
|
|
@ -759,8 +759,8 @@ where
|
|||
vec![Tree::new(&self.base), Tree::new(&self.top)]
|
||||
}
|
||||
|
||||
fn diff(&self, tree: &mut Tree) {
|
||||
tree.diff_children(&[&self.base, &self.top]);
|
||||
fn diff(&mut self, tree: &mut Tree) {
|
||||
tree.diff_children(&mut [&mut self.base, &mut self.top]);
|
||||
}
|
||||
|
||||
fn size(&self) -> Size<Length> {
|
||||
|
|
|
|||
|
|
@ -222,7 +222,7 @@ where
|
|||
self.children.iter().map(Tree::new).collect()
|
||||
}
|
||||
|
||||
fn diff(&self, tree: &mut Tree) {
|
||||
fn diff(&mut self, tree: &mut Tree) {
|
||||
let Tree {
|
||||
state, children, ..
|
||||
} = tree;
|
||||
|
|
@ -231,8 +231,8 @@ where
|
|||
|
||||
tree::diff_children_custom_with_search(
|
||||
children,
|
||||
&self.children,
|
||||
|tree, child| child.as_widget().diff(tree),
|
||||
&mut self.children,
|
||||
|tree, child| child.as_widget_mut().diff(tree),
|
||||
|index| {
|
||||
self.keys.get(index).or_else(|| self.keys.last()).copied()
|
||||
!= Some(state.keys[index])
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ where
|
|||
self.with_element(|element| vec![Tree::new(element.as_widget())])
|
||||
}
|
||||
|
||||
fn diff(&self, tree: &mut Tree) {
|
||||
fn diff(&mut self, tree: &mut Tree) {
|
||||
let current = tree
|
||||
.state
|
||||
.downcast_mut::<Internal<Message, Theme, Renderer>>();
|
||||
|
|
@ -146,8 +146,8 @@ where
|
|||
current.element = Rc::new(RefCell::new(Some(element)));
|
||||
|
||||
(*self.element.borrow_mut()) = Some(current.element.clone());
|
||||
self.with_element(|element| {
|
||||
tree.diff_children(std::slice::from_ref(&element.as_widget()));
|
||||
self.with_element_mut(|element| {
|
||||
tree.diff_children(std::slice::from_mut(element));
|
||||
});
|
||||
} else {
|
||||
(*self.element.borrow_mut()) = Some(current.element.clone());
|
||||
|
|
|
|||
|
|
@ -147,13 +147,13 @@ where
|
|||
Renderer: renderer::Renderer,
|
||||
{
|
||||
fn diff_self(&self) {
|
||||
self.with_element(|element| {
|
||||
self.with_element_mut(|element| {
|
||||
self.tree
|
||||
.borrow_mut()
|
||||
.borrow_mut()
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.diff_children(std::slice::from_ref(&element));
|
||||
.diff_children(std::slice::from_mut(element));
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -279,7 +279,7 @@ where
|
|||
vec![]
|
||||
}
|
||||
|
||||
fn diff(&self, tree: &mut Tree) {
|
||||
fn diff(&mut self, tree: &mut Tree) {
|
||||
let tree = tree.state.downcast_ref::<Rc<RefCell<Option<Tree>>>>();
|
||||
*self.tree.borrow_mut() = tree.clone();
|
||||
self.rebuild_element_if_necessary();
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ where
|
|||
let size = limits.max();
|
||||
|
||||
self.content = (self.view)(size);
|
||||
state.tree.diff(&self.content);
|
||||
state.tree.diff(&mut self.content);
|
||||
|
||||
self.content.as_widget_mut().layout(
|
||||
&mut state.tree,
|
||||
|
|
|
|||
|
|
@ -181,8 +181,8 @@ where
|
|||
vec![Tree::new(&self.content)]
|
||||
}
|
||||
|
||||
fn diff(&self, tree: &mut Tree) {
|
||||
tree.diff_children(std::slice::from_ref(&self.content));
|
||||
fn diff(&mut self, tree: &mut Tree) {
|
||||
tree.diff_children(std::slice::from_mut(&mut self.content));
|
||||
}
|
||||
|
||||
fn size(&self) -> Size<Length> {
|
||||
|
|
|
|||
|
|
@ -205,7 +205,7 @@ where
|
|||
class,
|
||||
} = menu;
|
||||
|
||||
let list = Scrollable::new(List {
|
||||
let mut list = Scrollable::new(List {
|
||||
options,
|
||||
hovered_option,
|
||||
on_selected,
|
||||
|
|
@ -218,7 +218,7 @@ where
|
|||
class,
|
||||
});
|
||||
|
||||
state.tree.diff(&list as &dyn Widget<_, _, _>);
|
||||
state.tree.diff(&mut list as &mut dyn Widget<_, _, _>);
|
||||
|
||||
Self {
|
||||
position,
|
||||
|
|
|
|||
|
|
@ -378,7 +378,7 @@ where
|
|||
self.contents.iter().map(Content::state).collect()
|
||||
}
|
||||
|
||||
fn diff(&self, tree: &mut Tree) {
|
||||
fn diff(&mut self, tree: &mut Tree) {
|
||||
let Memory { order, .. } = tree.state.downcast_ref();
|
||||
|
||||
// `Pane` always increments and is iterated by Ord so new
|
||||
|
|
@ -401,7 +401,7 @@ where
|
|||
});
|
||||
|
||||
tree.diff_children_custom(
|
||||
&self.contents,
|
||||
&mut self.contents,
|
||||
|state, content| content.diff(state),
|
||||
Content::state,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -91,13 +91,13 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
pub(super) fn diff(&self, tree: &mut Tree) {
|
||||
pub(super) fn diff(&mut self, tree: &mut Tree) {
|
||||
if tree.children.len() == 2 {
|
||||
if let Some(title_bar) = self.title_bar.as_ref() {
|
||||
if let Some(title_bar) = self.title_bar.as_mut() {
|
||||
title_bar.diff(&mut tree.children[1]);
|
||||
}
|
||||
|
||||
tree.children[0].diff(&self.body);
|
||||
tree.children[0].diff(&mut self.body);
|
||||
} else {
|
||||
*tree = self.state();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -128,17 +128,17 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
pub(super) fn diff(&self, tree: &mut Tree) {
|
||||
pub(super) fn diff(&mut self, tree: &mut Tree) {
|
||||
if tree.children.len() == 3 {
|
||||
if let Some(controls) = self.controls.as_ref() {
|
||||
if let Some(compact) = controls.compact.as_ref() {
|
||||
if let Some(controls) = self.controls.as_mut() {
|
||||
if let Some(compact) = controls.compact.as_mut() {
|
||||
tree.children[2].diff(compact);
|
||||
}
|
||||
|
||||
tree.children[1].diff(&controls.full);
|
||||
tree.children[1].diff(&mut controls.full);
|
||||
}
|
||||
|
||||
tree.children[0].diff(&self.content);
|
||||
tree.children[0].diff(&mut self.content);
|
||||
} else {
|
||||
*tree = self.state();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -127,8 +127,8 @@ where
|
|||
self.content.as_widget().children()
|
||||
}
|
||||
|
||||
fn diff(&self, tree: &mut widget::Tree) {
|
||||
self.content.as_widget().diff(tree);
|
||||
fn diff(&mut self, tree: &mut widget::Tree) {
|
||||
self.content.as_widget_mut().diff(tree);
|
||||
}
|
||||
|
||||
fn size(&self) -> Size<Length> {
|
||||
|
|
|
|||
|
|
@ -196,8 +196,8 @@ where
|
|||
self.children.iter().map(Tree::new).collect()
|
||||
}
|
||||
|
||||
fn diff(&self, tree: &mut Tree) {
|
||||
tree.diff_children(&self.children);
|
||||
fn diff(&mut self, tree: &mut Tree) {
|
||||
tree.diff_children(&mut self.children);
|
||||
}
|
||||
|
||||
fn size(&self) -> Size<Length> {
|
||||
|
|
@ -398,7 +398,7 @@ where
|
|||
self.row.children()
|
||||
}
|
||||
|
||||
fn diff(&self, tree: &mut Tree) {
|
||||
fn diff(&mut self, tree: &mut Tree) {
|
||||
self.row.diff(tree);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -409,8 +409,8 @@ where
|
|||
vec![Tree::new(&self.content)]
|
||||
}
|
||||
|
||||
fn diff(&self, tree: &mut Tree) {
|
||||
tree.diff_children(std::slice::from_ref(&self.content));
|
||||
fn diff(&mut self, tree: &mut Tree) {
|
||||
tree.diff_children(std::slice::from_mut(&mut self.content));
|
||||
}
|
||||
|
||||
fn size(&self) -> Size<Length> {
|
||||
|
|
|
|||
|
|
@ -184,8 +184,8 @@ where
|
|||
vec![Tree::new(&self.content)]
|
||||
}
|
||||
|
||||
fn diff(&self, tree: &mut Tree) {
|
||||
tree.diff_children(&[&self.content]);
|
||||
fn diff(&mut self, tree: &mut Tree) {
|
||||
tree.diff_children(std::slice::from_mut(&mut self.content));
|
||||
}
|
||||
|
||||
fn update(
|
||||
|
|
|
|||
|
|
@ -146,8 +146,8 @@ where
|
|||
self.children.iter().map(Tree::new).collect()
|
||||
}
|
||||
|
||||
fn diff(&self, tree: &mut Tree) {
|
||||
tree.diff_children(&self.children);
|
||||
fn diff(&mut self, tree: &mut Tree) {
|
||||
tree.diff_children(&mut self.children);
|
||||
}
|
||||
|
||||
fn size(&self) -> Size<Length> {
|
||||
|
|
|
|||
|
|
@ -227,8 +227,8 @@ where
|
|||
.collect()
|
||||
}
|
||||
|
||||
fn diff(&self, state: &mut widget::Tree) {
|
||||
state.diff_children(&self.cells);
|
||||
fn diff(&mut self, state: &mut widget::Tree) {
|
||||
state.diff_children(&mut self.cells);
|
||||
}
|
||||
|
||||
fn layout(
|
||||
|
|
|
|||
|
|
@ -654,7 +654,7 @@ where
|
|||
tree::State::new(State::<Renderer::Paragraph>::new())
|
||||
}
|
||||
|
||||
fn diff(&self, tree: &mut Tree) {
|
||||
fn diff(&mut self, tree: &mut Tree) {
|
||||
let state = tree.state.downcast_mut::<State<Renderer::Paragraph>>();
|
||||
|
||||
// Stop pasting if input becomes disabled
|
||||
|
|
|
|||
|
|
@ -81,8 +81,8 @@ where
|
|||
self.content.as_widget().children()
|
||||
}
|
||||
|
||||
fn diff(&self, tree: &mut Tree) {
|
||||
self.content.as_widget().diff(tree);
|
||||
fn diff(&mut self, tree: &mut Tree) {
|
||||
self.content.as_widget_mut().diff(tree);
|
||||
}
|
||||
|
||||
fn size(&self) -> Size<Length> {
|
||||
|
|
|
|||
|
|
@ -155,10 +155,10 @@ where
|
|||
]
|
||||
}
|
||||
|
||||
fn diff(&self, tree: &mut widget::Tree) {
|
||||
tree.diff_children(&[
|
||||
self.content.as_widget(),
|
||||
self.tooltip.as_widget(),
|
||||
fn diff(&mut self, tree: &mut widget::Tree) {
|
||||
tree.diff_children(&mut [
|
||||
self.content.as_widget_mut(),
|
||||
self.tooltip.as_widget_mut(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue