Skip to content
Snippets Groups Projects
Commit 8bd90bf8 authored by StarArawn's avatar StarArawn
Browse files

Fixed diff issue where fragments with no children were diffing.

parent c158bed3
No related branches found
No related tags found
No related merge requests found
......@@ -96,7 +96,6 @@ pub fn extract(
extracted_quads.extend(nine_patch_quads);
}
RenderPrimitive::Clip { layout } => {
// dbg!(&layout);
extracted_quads.push(ExtractQuadBundle {
extracted_quad: ExtractedQuad {
rect: Rect {
......
......@@ -35,24 +35,22 @@ impl Widget for Fragment {
}
fn render(&mut self, context: &mut KayakContext) {
let parent_id = self.get_id();
let tree = crate::WidgetTree::new();
tree.add(parent_id, None);
if let Some(children) = self.children.take() {
children(tree.clone(), Some(self.get_id()), context);
children(tree.clone(), Some(parent_id), context);
} else {
return;
}
// Consume the widget tree taking the inner value
let tree = tree.take();
// Evaluate changes to the tree.
let changes = context
.widget_manager
.tree
.diff_children(&tree, self.get_id());
// dbg!(&changes);
context
.widget_manager
.tree
.merge(&tree, self.get_id(), changes);
let changes = context.widget_manager.tree.diff_children(&tree, parent_id);
context.widget_manager.tree.merge(&tree, parent_id, changes);
}
}
......@@ -30,6 +30,15 @@ pub struct ChildChanges {
pub child_changes: Vec<(usize, ChildChanges)>,
}
impl ChildChanges {
pub fn has_changes(&self) -> bool {
!self
.changes
.iter()
.all(|change| change.3.iter().all(|c| *c == Change::Unchanged))
}
}
impl From<Vec<(usize, Index, Index, Vec<Change>)>> for ChildChanges {
fn from(changes: Vec<(usize, Index, Index, Vec<Change>)>) -> Self {
Self {
......@@ -295,7 +304,6 @@ impl Tree {
})
.collect::<Vec<_>>();
changes.extend(deleted_nodes);
dbg!(&changes);
let inserted_and_changed = tree2
.iter()
......@@ -325,7 +333,6 @@ impl Tree {
})
.collect::<Vec<_>>();
changes.extend(inserted_and_changed);
dbg!(&changes);
let flat_tree_diff_nodes = changes
.iter()
......@@ -343,7 +350,6 @@ impl Tree {
return (child_id, *node, *parent_node, change.clone());
}
dbg!(id, node, parent_node, change);
let parent_a = self.parent(tree1.get(*id).unwrap().1);
let parent_b = self.parent(*node);
let definitely_moved = if parent_a.is_some() && parent_b.is_some() {
......@@ -378,6 +384,7 @@ impl Tree {
}
pub fn merge(&mut self, other: &Tree, root_node: Index, changes: ChildChanges) {
let has_changes = changes.has_changes();
let children_a = self.children.get_mut(&root_node);
let children_b = other.children.get(&root_node);
if children_a.is_none() && children_b.is_none() {
......@@ -389,11 +396,13 @@ impl Tree {
return;
} else if children_a.is_some() && children_b.is_none() {
// Case for erasing all
let children_a = children_a.unwrap();
for child in children_a.iter() {
self.parents.remove(&*child);
if has_changes {
let children_a = children_a.unwrap();
for child in children_a.iter() {
self.parents.remove(&*child);
}
self.children.remove(&root_node);
}
self.children.remove(&root_node);
return;
}
let children_a = children_a.unwrap();
......@@ -419,13 +428,13 @@ impl Tree {
}
}
for (child_id, children_of_child_changes) in changes.child_changes {
self.merge(
other,
changes.changes[child_id].1,
children_of_child_changes,
);
}
// for (child_id, children_of_child_changes) in changes.child_changes {
// self.merge(
// other,
// changes.changes[child_id].1,
// children_of_child_changes,
// );
// }
}
}
......
......@@ -83,7 +83,6 @@ where
.widget_manager
.tree
.diff_children(&tree, self.get_id());
// dbg!(&changes);
context
.widget_manager
.tree
......
use kayak_ui::core::{
render_command::RenderCommand,
rsx,
styles::{Style, StyleProp},
widget,
};
......@@ -16,9 +15,9 @@ pub fn Text(size: f32, content: String, styles: Option<Style>) {
render_command: StyleProp::Value(render_command),
..styles.clone().unwrap_or_default()
});
rsx! {
<>
{}
</>
}
// rsx! {
// <>
// {}
// </>
// }
}
......@@ -68,7 +68,7 @@ pub fn Window(
<Fragment>
<Clip styles={Some(clip_styles)}>
<Background styles={Some(title_background_styles)}>
<Text styles={Some(title_text_styles)} size={16.0} content={title}>{}</Text>
<Text styles={Some(title_text_styles)} size={16.0} content={title} />
</Background>
<Element styles={Some(content_styles)}>
{children}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment