update dependancy to stretch2 master and remove refrences to tree

This commit is contained in:
Evan Almloff committed 2022-04-04 13:37:04 -05:00
1 parent 06e8785938
commit 351722d136
10 files changed
+125 -191

No files matched your search

+1 -2
View File
@@ -11,8 +11,7 @@ dioxus-core = { path = "../core", version = "^0.2.0" }
dioxus-html = { path = "../html", version = "^0.2.0" } dioxus-html = { path = "../html", version = "^0.2.0" }
dioxus-core-macro = { path = "../core-macro", version = "^0.2.0" } dioxus-core-macro = { path = "../core-macro", version = "^0.2.0" }
# stretch2 = "0.4.1" stretch2 = { git = "https://github.com/DioxusLabs/stretch" }
stretch2 = { git = "https://github.com/Demonthos/stretch.git" }
smallvec = "1.6" smallvec = "1.6"
fxhash = "0.2" fxhash = "0.2"
+23 -23
View File
@@ -6,9 +6,9 @@ use std::{
use dioxus_core::{ElementId, Mutations, VNode, VirtualDom}; use dioxus_core::{ElementId, Mutations, VNode, VirtualDom};
/// A tree that can sync with the VirtualDom mutations intended for use in lazy renderers. /// A Dom that can sync with the VirtualDom mutations intended for use in lazy renderers.
/// The render state passes from parent to children and or accumulates state from children to parents. /// The render state passes from parent to children and or accumulates state from children to parents.
/// To get started implement [PushedDownState] and or [BubbledUpState] and call [Tree::apply_mutations] to update the tree and [Tree::update_state] to update the state of the nodes. /// To get started implement [PushedDownState] and or [BubbledUpState] and call [RealDom::apply_mutations] to update the dom and [RealDom::update_state] to update the state of the nodes.
#[derive(Debug)] #[derive(Debug)]
pub struct RealDom<US: BubbledUpState = (), DS: PushedDownState = ()> { pub struct RealDom<US: BubbledUpState = (), DS: PushedDownState = ()> {
root: usize, root: usize,
@@ -43,7 +43,7 @@ impl<US: BubbledUpState, DS: PushedDownState> RealDom<US, DS> {
} }
} }
/// Updates the tree, up and down state and return a set of nodes that were updated pass this to update_state. /// Updates the dom, up and down state and return a set of nodes that were updated pass this to update_state.
pub fn apply_mutations(&mut self, mutations_vec: Vec<Mutations>) -> Vec<usize> { pub fn apply_mutations(&mut self, mutations_vec: Vec<Mutations>) -> Vec<usize> {
let mut nodes_updated = Vec::new(); let mut nodes_updated = Vec::new();
for mutations in mutations_vec { for mutations in mutations_vec {
@@ -299,17 +299,17 @@ impl<US: BubbledUpState, DS: PushedDownState> RealDom<US, DS> {
} }
} }
// remove a node and it's children from the tree. // remove a node and it's children from the dom.
fn remove(&mut self, id: usize) -> Option<Node<US, DS>> { fn remove(&mut self, id: usize) -> Option<Node<US, DS>> {
// We do not need to remove the node from the parent's children list for children. // We do not need to remove the node from the parent's children list for children.
fn inner<US: BubbledUpState, DS: PushedDownState>( fn inner<US: BubbledUpState, DS: PushedDownState>(
tree: &mut RealDom<US, DS>, dom: &mut RealDom<US, DS>,
id: usize, id: usize,
) -> Option<Node<US, DS>> { ) -> Option<Node<US, DS>> {
let mut node = tree.nodes[id as usize].take()?; let mut node = dom.nodes[id as usize].take()?;
if let NodeType::Element { children, .. } = &mut node.node_type { if let NodeType::Element { children, .. } = &mut node.node_type {
for c in children { for c in children {
inner(tree, c.0)?; inner(dom, c.0)?;
} }
} }
Some(node) Some(node)
@@ -355,7 +355,7 @@ impl<US: BubbledUpState, DS: PushedDownState> RealDom<US, DS> {
} }
} }
/// Check if the tree contains a node and its children. /// Check if the dom contains a node and its children.
pub fn contains_node(&self, node: &VNode) -> bool { pub fn contains_node(&self, node: &VNode) -> bool {
match node { match node {
VNode::Component(_) => { VNode::Component(_) => {
@@ -363,8 +363,8 @@ impl<US: BubbledUpState, DS: PushedDownState> RealDom<US, DS> {
} }
VNode::Element(e) => { VNode::Element(e) => {
if let Some(id) = e.id.get() { if let Some(id) = e.id.get() {
let tree_node = &self[id]; let dom_node = &self[id];
match &tree_node.node_type { match &dom_node.node_type {
NodeType::Element { NodeType::Element {
tag, tag,
namespace, namespace,
@@ -392,8 +392,8 @@ impl<US: BubbledUpState, DS: PushedDownState> RealDom<US, DS> {
VNode::Placeholder(_) => true, VNode::Placeholder(_) => true,
VNode::Text(t) => { VNode::Text(t) => {
if let Some(id) = t.id.get() { if let Some(id) = t.id.get() {
let tree_node = &self[id]; let dom_node = &self[id];
match &tree_node.node_type { match &dom_node.node_type {
NodeType::Text { text } => t.text == text, NodeType::Text { text } => t.text == text,
_ => false, _ => false,
} }
@@ -404,9 +404,9 @@ impl<US: BubbledUpState, DS: PushedDownState> RealDom<US, DS> {
} }
} }
/// Return the number of nodes in the tree. /// Return the number of nodes in the dom.
pub fn size(&self) -> usize { pub fn size(&self) -> usize {
// The tree has a root node, ignore it. // The dom has a root node, ignore it.
self.nodes.iter().filter(|n| n.is_some()).count() - 1 self.nodes.iter().filter(|n| n.is_some()).count() - 1
} }
@@ -415,18 +415,18 @@ impl<US: BubbledUpState, DS: PushedDownState> RealDom<US, DS> {
self.root self.root
} }
/// Call a function for each node in the tree, depth first. /// Call a function for each node in the dom, depth first.
pub fn traverse_depth_first(&self, mut f: impl FnMut(&Node<US, DS>)) { pub fn traverse_depth_first(&self, mut f: impl FnMut(&Node<US, DS>)) {
fn inner<US: BubbledUpState, DS: PushedDownState>( fn inner<US: BubbledUpState, DS: PushedDownState>(
tree: &RealDom<US, DS>, dom: &RealDom<US, DS>,
id: ElementId, id: ElementId,
f: &mut impl FnMut(&Node<US, DS>), f: &mut impl FnMut(&Node<US, DS>),
) { ) {
let node = &tree[id]; let node = &dom[id];
f(node); f(node);
if let NodeType::Element { children, .. } = &node.node_type { if let NodeType::Element { children, .. } = &node.node_type {
for c in children { for c in children {
inner(tree, *c, f); inner(dom, *c, f);
} }
} }
} }
@@ -437,18 +437,18 @@ impl<US: BubbledUpState, DS: PushedDownState> RealDom<US, DS> {
} }
} }
/// Call a function for each node in the tree, depth first. /// Call a function for each node in the dom, depth first.
pub fn traverse_depth_first_mut(&mut self, mut f: impl FnMut(&mut Node<US, DS>)) { pub fn traverse_depth_first_mut(&mut self, mut f: impl FnMut(&mut Node<US, DS>)) {
fn inner<US: BubbledUpState, DS: PushedDownState>( fn inner<US: BubbledUpState, DS: PushedDownState>(
tree: &mut RealDom<US, DS>, dom: &mut RealDom<US, DS>,
id: ElementId, id: ElementId,
f: &mut impl FnMut(&mut Node<US, DS>), f: &mut impl FnMut(&mut Node<US, DS>),
) { ) {
let node = &mut tree[id]; let node = &mut dom[id];
f(node); f(node);
if let NodeType::Element { children, .. } = &mut node.node_type { if let NodeType::Element { children, .. } = &mut node.node_type {
for c in children.clone() { for c in children.clone() {
inner(tree, c, f); inner(dom, c, f);
} }
} }
} }
@@ -488,7 +488,7 @@ impl<US: BubbledUpState, DS: PushedDownState> IndexMut<ElementId> for RealDom<US
} }
} }
/// The node is stored client side and stores only basic data about the node. For more complete information about the node see [`TreeNode::element`]. /// The node is stored client side and stores only basic data about the node. For more complete information about the node see [`domNode::element`].
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Node<US: BubbledUpState, DS: PushedDownState> { pub struct Node<US: BubbledUpState, DS: PushedDownState> {
/// The id of the node this node was created from. /// The id of the node this node was created from.
+20 -20
View File
@@ -20,9 +20,9 @@ fn remove_node() {
} }
}); });
let mut tree: RealDom<(), ()> = RealDom::new(); let mut dom: RealDom<(), ()> = RealDom::new();
let _to_update = tree.apply_mutations(vec![mutations]); let _to_update = dom.apply_mutations(vec![mutations]);
let child_div = VElement { let child_div = VElement {
id: Cell::new(Some(ElementId(2))), id: Cell::new(Some(ElementId(2))),
key: None, key: None,
@@ -45,10 +45,10 @@ fn remove_node() {
children: &[child_div_el], children: &[child_div_el],
}; };
assert_eq!(tree.size(), 2); assert_eq!(dom.size(), 2);
assert!(&tree.contains_node(&VNode::Element(&root_div))); assert!(&dom.contains_node(&VNode::Element(&root_div)));
assert_eq!(tree[1].height, 1); assert_eq!(dom[1].height, 1);
assert_eq!(tree[2].height, 2); assert_eq!(dom[2].height, 2);
let vdom = VirtualDom::new(Base); let vdom = VirtualDom::new(Base);
let mutations = vdom.diff_lazynodes( let mutations = vdom.diff_lazynodes(
@@ -61,7 +61,7 @@ fn remove_node() {
div{} div{}
}, },
); );
tree.apply_mutations(vec![mutations.1]); dom.apply_mutations(vec![mutations.1]);
let new_root_div = VElement { let new_root_div = VElement {
id: Cell::new(Some(ElementId(1))), id: Cell::new(Some(ElementId(1))),
@@ -74,9 +74,9 @@ fn remove_node() {
children: &[], children: &[],
}; };
assert_eq!(tree.size(), 1); assert_eq!(dom.size(), 1);
assert!(&tree.contains_node(&VNode::Element(&new_root_div))); assert!(&dom.contains_node(&VNode::Element(&new_root_div)));
assert_eq!(tree[1].height, 1); assert_eq!(dom[1].height, 1);
} }
#[test] #[test]
@@ -92,9 +92,9 @@ fn add_node() {
div{} div{}
}); });
let mut tree: RealDom<(), ()> = RealDom::new(); let mut dom: RealDom<(), ()> = RealDom::new();
let _to_update = tree.apply_mutations(vec![mutations]); let _to_update = dom.apply_mutations(vec![mutations]);
let root_div = VElement { let root_div = VElement {
id: Cell::new(Some(ElementId(1))), id: Cell::new(Some(ElementId(1))),
@@ -107,9 +107,9 @@ fn add_node() {
children: &[], children: &[],
}; };
assert_eq!(tree.size(), 1); assert_eq!(dom.size(), 1);
assert!(&tree.contains_node(&VNode::Element(&root_div))); assert!(&dom.contains_node(&VNode::Element(&root_div)));
assert_eq!(tree[1].height, 1); assert_eq!(dom[1].height, 1);
let vdom = VirtualDom::new(Base); let vdom = VirtualDom::new(Base);
let mutations = vdom.diff_lazynodes( let mutations = vdom.diff_lazynodes(
@@ -122,7 +122,7 @@ fn add_node() {
} }
}, },
); );
tree.apply_mutations(vec![mutations.1]); dom.apply_mutations(vec![mutations.1]);
let child_div = VElement { let child_div = VElement {
id: Cell::new(Some(ElementId(2))), id: Cell::new(Some(ElementId(2))),
@@ -146,8 +146,8 @@ fn add_node() {
children: &[child_div_el], children: &[child_div_el],
}; };
assert_eq!(tree.size(), 2); assert_eq!(dom.size(), 2);
assert!(&tree.contains_node(&VNode::Element(&new_root_div))); assert!(&dom.contains_node(&VNode::Element(&new_root_div)));
assert_eq!(tree[1].height, 1); assert_eq!(dom[1].height, 1);
assert_eq!(tree[2].height, 2); assert_eq!(dom[2].height, 2);
} }
+15 -15
View File
@@ -21,9 +21,9 @@ fn initial_build_simple() {
div{} div{}
}); });
let mut tree: RealDom<(), ()> = RealDom::new(); let mut dom: RealDom<(), ()> = RealDom::new();
let _to_update = tree.apply_mutations(vec![mutations]); let _to_update = dom.apply_mutations(vec![mutations]);
let root_div = VElement { let root_div = VElement {
id: Cell::new(Some(ElementId(1))), id: Cell::new(Some(ElementId(1))),
key: None, key: None,
@@ -34,9 +34,9 @@ fn initial_build_simple() {
attributes: &[], attributes: &[],
children: &[], children: &[],
}; };
assert_eq!(tree.size(), 1); assert_eq!(dom.size(), 1);
assert!(&tree.contains_node(&VNode::Element(&root_div))); assert!(&dom.contains_node(&VNode::Element(&root_div)));
assert_eq!(tree[1].height, 1); assert_eq!(dom[1].height, 1);
} }
#[test] #[test]
@@ -60,9 +60,9 @@ fn initial_build_with_children() {
} }
}); });
let mut tree: RealDom<(), ()> = RealDom::new(); let mut dom: RealDom<(), ()> = RealDom::new();
let _to_update = tree.apply_mutations(vec![mutations]); let _to_update = dom.apply_mutations(vec![mutations]);
let first_text = VText { let first_text = VText {
id: Cell::new(Some(ElementId(3))), id: Cell::new(Some(ElementId(3))),
text: "hello", text: "hello",
@@ -113,12 +113,12 @@ fn initial_build_with_children() {
attributes: &[], attributes: &[],
children: &[child_div_node], children: &[child_div_node],
}; };
assert_eq!(tree.size(), 6); assert_eq!(dom.size(), 6);
assert!(&tree.contains_node(&VNode::Element(&root_div))); assert!(&dom.contains_node(&VNode::Element(&root_div)));
assert_eq!(tree[1].height, 1); assert_eq!(dom[1].height, 1);
assert_eq!(tree[2].height, 2); assert_eq!(dom[2].height, 2);
assert_eq!(tree[3].height, 3); assert_eq!(dom[3].height, 3);
assert_eq!(tree[4].height, 3); assert_eq!(dom[4].height, 3);
assert_eq!(tree[5].height, 4); assert_eq!(dom[5].height, 4);
assert_eq!(tree[6].height, 3); assert_eq!(dom[6].height, 3);
} }
+22 -22
View File
@@ -77,12 +77,12 @@ fn state_initial() {
} }
}); });
let mut tree: RealDom<BubbledUpStateTester, PushedDownStateTester> = RealDom::new(); let mut dom: RealDom<BubbledUpStateTester, PushedDownStateTester> = RealDom::new();
let nodes_updated = tree.apply_mutations(vec![mutations]); let nodes_updated = dom.apply_mutations(vec![mutations]);
let _to_rerender = tree.update_state(&vdom, nodes_updated, &mut 42, &mut 42); let _to_rerender = dom.update_state(&vdom, nodes_updated, &mut 42, &mut 42);
let root_div = &tree[1]; let root_div = &dom[1];
assert_eq!(root_div.up_state.0, "1"); assert_eq!(root_div.up_state.0, "1");
assert_eq!( assert_eq!(
root_div.up_state.1, root_div.up_state.1,
@@ -94,7 +94,7 @@ fn state_initial() {
assert_eq!(root_div.down_state.0, "1"); assert_eq!(root_div.down_state.0, "1");
assert_eq!(root_div.down_state.1, None); assert_eq!(root_div.down_state.1, None);
let child_p = &tree[2]; let child_p = &dom[2];
assert_eq!(child_p.up_state.0, "2"); assert_eq!(child_p.up_state.0, "2");
assert_eq!(child_p.up_state.1, Vec::new()); assert_eq!(child_p.up_state.1, Vec::new());
assert_eq!(child_p.down_state.0, "2"); assert_eq!(child_p.down_state.0, "2");
@@ -103,7 +103,7 @@ fn state_initial() {
Some(Box::new(PushedDownStateTester("1".to_string(), None))) Some(Box::new(PushedDownStateTester("1".to_string(), None)))
); );
let child_h1 = &tree[3]; let child_h1 = &dom[3];
assert_eq!(child_h1.up_state.0, "3"); assert_eq!(child_h1.up_state.0, "3");
assert_eq!(child_h1.up_state.1, Vec::new()); assert_eq!(child_h1.up_state.1, Vec::new());
assert_eq!(child_h1.down_state.0, "3"); assert_eq!(child_h1.down_state.0, "3");
@@ -178,12 +178,12 @@ fn state_reduce_initally_called_minimally() {
} }
}); });
let mut tree: RealDom<CallCounter, CallCounter> = RealDom::new(); let mut dom: RealDom<CallCounter, CallCounter> = RealDom::new();
let nodes_updated = tree.apply_mutations(vec![mutations]); let nodes_updated = dom.apply_mutations(vec![mutations]);
let _to_rerender = tree.update_state(&vdom, nodes_updated, &mut (), &mut ()); let _to_rerender = dom.update_state(&vdom, nodes_updated, &mut (), &mut ());
tree.traverse_depth_first(|n| { dom.traverse_depth_first(|n| {
assert_eq!(n.up_state.0, 1); assert_eq!(n.up_state.0, 1);
assert_eq!(n.down_state.0, 1); assert_eq!(n.down_state.0, 1);
}); });
@@ -233,11 +233,11 @@ fn state_reduce_down_called_minimally_on_update() {
} }
}); });
let mut tree: RealDom<CallCounter, CallCounter> = RealDom::new(); let mut dom: RealDom<CallCounter, CallCounter> = RealDom::new();
let nodes_updated = tree.apply_mutations(vec![mutations]); let nodes_updated = dom.apply_mutations(vec![mutations]);
let _to_rerender = tree.update_state(&vdom, nodes_updated, &mut (), &mut ()); let _to_rerender = dom.update_state(&vdom, nodes_updated, &mut (), &mut ());
let nodes_updated = tree.apply_mutations(vec![Mutations { let nodes_updated = dom.apply_mutations(vec![Mutations {
edits: vec![DomEdit::SetAttribute { edits: vec![DomEdit::SetAttribute {
root: 1, root: 1,
field: "width", field: "width",
@@ -247,9 +247,9 @@ fn state_reduce_down_called_minimally_on_update() {
dirty_scopes: fxhash::FxHashSet::default(), dirty_scopes: fxhash::FxHashSet::default(),
refs: Vec::new(), refs: Vec::new(),
}]); }]);
let _to_rerender = tree.update_state(&vdom, nodes_updated, &mut (), &mut ()); let _to_rerender = dom.update_state(&vdom, nodes_updated, &mut (), &mut ());
tree.traverse_depth_first(|n| { dom.traverse_depth_first(|n| {
assert_eq!(n.down_state.0, 2); assert_eq!(n.down_state.0, 2);
}); });
} }
@@ -298,11 +298,11 @@ fn state_reduce_up_called_minimally_on_update() {
} }
}); });
let mut tree: RealDom<CallCounter, CallCounter> = RealDom::new(); let mut dom: RealDom<CallCounter, CallCounter> = RealDom::new();
let nodes_updated = tree.apply_mutations(vec![mutations]); let nodes_updated = dom.apply_mutations(vec![mutations]);
let _to_rerender = tree.update_state(&vdom, nodes_updated, &mut (), &mut ()); let _to_rerender = dom.update_state(&vdom, nodes_updated, &mut (), &mut ());
let nodes_updated = tree.apply_mutations(vec![Mutations { let nodes_updated = dom.apply_mutations(vec![Mutations {
edits: vec![DomEdit::SetAttribute { edits: vec![DomEdit::SetAttribute {
root: 4, root: 4,
field: "width", field: "width",
@@ -312,9 +312,9 @@ fn state_reduce_up_called_minimally_on_update() {
dirty_scopes: fxhash::FxHashSet::default(), dirty_scopes: fxhash::FxHashSet::default(),
refs: Vec::new(), refs: Vec::new(),
}]); }]);
let _to_rerender = tree.update_state(&vdom, nodes_updated, &mut (), &mut ()); let _to_rerender = dom.update_state(&vdom, nodes_updated, &mut (), &mut ());
tree.traverse_depth_first(|n| { dom.traverse_depth_first(|n| {
assert_eq!(n.up_state.0, if n.id.0 > 4 { 1 } else { 2 }); assert_eq!(n.up_state.0, if n.id.0 > 4 { 1 } else { 2 });
}); });
} }
+1 -2
View File
@@ -22,7 +22,6 @@ crossterm = "0.23.0"
anyhow = "1.0.42" anyhow = "1.0.42"
tokio = { version = "1.15.0", features = ["full"] } tokio = { version = "1.15.0", features = ["full"] }
futures = "0.3.19" futures = "0.3.19"
# stretch2 = "0.4.1" stretch2 = { git = "https://github.com/DioxusLabs/stretch" }
stretch2 = { git = "https://github.com/Demonthos/stretch.git" }
smallvec = "1.6" smallvec = "1.6"
fxhash = "0.2" fxhash = "0.2"
+28 -28
View File
@@ -166,7 +166,7 @@ impl InnerInputState {
evts: &mut Vec<EventCore>, evts: &mut Vec<EventCore>,
resolved_events: &mut Vec<UserEvent>, resolved_events: &mut Vec<UserEvent>,
layout: &Stretch, layout: &Stretch,
tree: &mut RealDom<StretchLayout, StyleModifier>, dom: &mut RealDom<StretchLayout, StyleModifier>,
) { ) {
let previous_mouse = self let previous_mouse = self
.mouse .mouse
@@ -179,7 +179,7 @@ impl InnerInputState {
self.apply_event(e); self.apply_event(e);
} }
self.resolve_mouse_events(previous_mouse, resolved_events, layout, tree); self.resolve_mouse_events(previous_mouse, resolved_events, layout, dom);
// for s in &self.subscribers { // for s in &self.subscribers {
// s(); // s();
@@ -191,7 +191,7 @@ impl InnerInputState {
previous_mouse: Option<(MouseData, Vec<u16>)>, previous_mouse: Option<(MouseData, Vec<u16>)>,
resolved_events: &mut Vec<UserEvent>, resolved_events: &mut Vec<UserEvent>,
layout: &Stretch, layout: &Stretch,
tree: &mut RealDom<StretchLayout, StyleModifier>, dom: &mut RealDom<StretchLayout, StyleModifier>,
) { ) {
struct Data<'b> { struct Data<'b> {
new_pos: (i32, i32), new_pos: (i32, i32),
@@ -216,14 +216,14 @@ impl InnerInputState {
will_bubble: &mut FxHashSet<ElementId>, will_bubble: &mut FxHashSet<ElementId>,
resolved_events: &mut Vec<UserEvent>, resolved_events: &mut Vec<UserEvent>,
node: &Node<StretchLayout, StyleModifier>, node: &Node<StretchLayout, StyleModifier>,
tree: &RealDom<StretchLayout, StyleModifier>, dom: &RealDom<StretchLayout, StyleModifier>,
) { ) {
// only trigger event if the event was not triggered already by a child // only trigger event if the event was not triggered already by a child
if will_bubble.insert(node.id) { if will_bubble.insert(node.id) {
let mut parent = node.parent; let mut parent = node.parent;
while let Some(parent_id) = parent { while let Some(parent_id) = parent {
will_bubble.insert(parent_id); will_bubble.insert(parent_id);
parent = tree[parent_id.0].parent; parent = dom[parent_id.0].parent;
} }
resolved_events.push(UserEvent { resolved_events.push(UserEvent {
scope_id: None, scope_id: None,
@@ -260,7 +260,7 @@ impl InnerInputState {
{ {
// mousemove // mousemove
let mut will_bubble = FxHashSet::default(); let mut will_bubble = FxHashSet::default();
for node in tree.get_listening_sorted("mousemove") { for node in dom.get_listening_sorted("mousemove") {
let node_layout = layout.layout(node.up_state.node.unwrap()).unwrap(); let node_layout = layout.layout(node.up_state.node.unwrap()).unwrap();
let previously_contained = data let previously_contained = data
.old_pos .old_pos
@@ -275,7 +275,7 @@ impl InnerInputState {
&mut will_bubble, &mut will_bubble,
resolved_events, resolved_events,
node, node,
tree, dom,
); );
} }
} }
@@ -284,7 +284,7 @@ impl InnerInputState {
{ {
// mouseenter // mouseenter
let mut will_bubble = FxHashSet::default(); let mut will_bubble = FxHashSet::default();
for node in tree.get_listening_sorted("mouseenter") { for node in dom.get_listening_sorted("mouseenter") {
let node_layout = layout.layout(node.up_state.node.unwrap()).unwrap(); let node_layout = layout.layout(node.up_state.node.unwrap()).unwrap();
let previously_contained = data let previously_contained = data
.old_pos .old_pos
@@ -299,7 +299,7 @@ impl InnerInputState {
&mut will_bubble, &mut will_bubble,
resolved_events, resolved_events,
node, node,
tree, dom,
); );
} }
} }
@@ -308,7 +308,7 @@ impl InnerInputState {
{ {
// mouseover // mouseover
let mut will_bubble = FxHashSet::default(); let mut will_bubble = FxHashSet::default();
for node in tree.get_listening_sorted("mouseover") { for node in dom.get_listening_sorted("mouseover") {
let node_layout = layout.layout(node.up_state.node.unwrap()).unwrap(); let node_layout = layout.layout(node.up_state.node.unwrap()).unwrap();
let previously_contained = data let previously_contained = data
.old_pos .old_pos
@@ -323,7 +323,7 @@ impl InnerInputState {
&mut will_bubble, &mut will_bubble,
resolved_events, resolved_events,
node, node,
tree, dom,
); );
} }
} }
@@ -332,7 +332,7 @@ impl InnerInputState {
{ {
// mousedown // mousedown
let mut will_bubble = FxHashSet::default(); let mut will_bubble = FxHashSet::default();
for node in tree.get_listening_sorted("mousedown") { for node in dom.get_listening_sorted("mousedown") {
let node_layout = layout.layout(node.up_state.node.unwrap()).unwrap(); let node_layout = layout.layout(node.up_state.node.unwrap()).unwrap();
let currently_contains = layout_contains_point(node_layout, data.new_pos); let currently_contains = layout_contains_point(node_layout, data.new_pos);
@@ -343,7 +343,7 @@ impl InnerInputState {
&mut will_bubble, &mut will_bubble,
resolved_events, resolved_events,
node, node,
tree, dom,
); );
} }
} }
@@ -352,7 +352,7 @@ impl InnerInputState {
{ {
// mouseup // mouseup
let mut will_bubble = FxHashSet::default(); let mut will_bubble = FxHashSet::default();
for node in tree.get_listening_sorted("mouseup") { for node in dom.get_listening_sorted("mouseup") {
let node_layout = layout.layout(node.up_state.node.unwrap()).unwrap(); let node_layout = layout.layout(node.up_state.node.unwrap()).unwrap();
let currently_contains = layout_contains_point(node_layout, data.new_pos); let currently_contains = layout_contains_point(node_layout, data.new_pos);
@@ -363,7 +363,7 @@ impl InnerInputState {
&mut will_bubble, &mut will_bubble,
resolved_events, resolved_events,
node, node,
tree, dom,
); );
} }
} }
@@ -372,7 +372,7 @@ impl InnerInputState {
{ {
// click // click
let mut will_bubble = FxHashSet::default(); let mut will_bubble = FxHashSet::default();
for node in tree.get_listening_sorted("click") { for node in dom.get_listening_sorted("click") {
let node_layout = layout.layout(node.up_state.node.unwrap()).unwrap(); let node_layout = layout.layout(node.up_state.node.unwrap()).unwrap();
let currently_contains = layout_contains_point(node_layout, data.new_pos); let currently_contains = layout_contains_point(node_layout, data.new_pos);
@@ -383,7 +383,7 @@ impl InnerInputState {
&mut will_bubble, &mut will_bubble,
resolved_events, resolved_events,
node, node,
tree, dom,
); );
} }
} }
@@ -392,7 +392,7 @@ impl InnerInputState {
{ {
// contextmenu // contextmenu
let mut will_bubble = FxHashSet::default(); let mut will_bubble = FxHashSet::default();
for node in tree.get_listening_sorted("contextmenu") { for node in dom.get_listening_sorted("contextmenu") {
let node_layout = layout.layout(node.up_state.node.unwrap()).unwrap(); let node_layout = layout.layout(node.up_state.node.unwrap()).unwrap();
let currently_contains = layout_contains_point(node_layout, data.new_pos); let currently_contains = layout_contains_point(node_layout, data.new_pos);
@@ -403,7 +403,7 @@ impl InnerInputState {
&mut will_bubble, &mut will_bubble,
resolved_events, resolved_events,
node, node,
tree, dom,
); );
} }
} }
@@ -412,7 +412,7 @@ impl InnerInputState {
{ {
// wheel // wheel
let mut will_bubble = FxHashSet::default(); let mut will_bubble = FxHashSet::default();
for node in tree.get_listening_sorted("wheel") { for node in dom.get_listening_sorted("wheel") {
let node_layout = layout.layout(node.up_state.node.unwrap()).unwrap(); let node_layout = layout.layout(node.up_state.node.unwrap()).unwrap();
let currently_contains = layout_contains_point(node_layout, data.new_pos); let currently_contains = layout_contains_point(node_layout, data.new_pos);
@@ -424,7 +424,7 @@ impl InnerInputState {
&mut will_bubble, &mut will_bubble,
resolved_events, resolved_events,
node, node,
tree, dom,
); );
} }
} }
@@ -434,7 +434,7 @@ impl InnerInputState {
{ {
// mouseleave // mouseleave
let mut will_bubble = FxHashSet::default(); let mut will_bubble = FxHashSet::default();
for node in tree.get_listening_sorted("mouseleave") { for node in dom.get_listening_sorted("mouseleave") {
let node_layout = layout.layout(node.up_state.node.unwrap()).unwrap(); let node_layout = layout.layout(node.up_state.node.unwrap()).unwrap();
let previously_contained = data let previously_contained = data
.old_pos .old_pos
@@ -449,7 +449,7 @@ impl InnerInputState {
&mut will_bubble, &mut will_bubble,
resolved_events, resolved_events,
node, node,
tree, dom,
); );
} }
} }
@@ -458,7 +458,7 @@ impl InnerInputState {
{ {
// mouseout // mouseout
let mut will_bubble = FxHashSet::default(); let mut will_bubble = FxHashSet::default();
for node in tree.get_listening_sorted("mouseout") { for node in dom.get_listening_sorted("mouseout") {
let node_layout = layout.layout(node.up_state.node.unwrap()).unwrap(); let node_layout = layout.layout(node.up_state.node.unwrap()).unwrap();
let previously_contained = data let previously_contained = data
.old_pos .old_pos
@@ -473,7 +473,7 @@ impl InnerInputState {
&mut will_bubble, &mut will_bubble,
resolved_events, resolved_events,
node, node,
tree, dom,
); );
} }
} }
@@ -525,7 +525,7 @@ impl RinkInputHandler {
pub fn get_events( pub fn get_events(
&self, &self,
layout: &Stretch, layout: &Stretch,
tree: &mut RealDom<StretchLayout, StyleModifier>, dom: &mut RealDom<StretchLayout, StyleModifier>,
) -> Vec<UserEvent> { ) -> Vec<UserEvent> {
let mut resolved_events = Vec::new(); let mut resolved_events = Vec::new();
@@ -533,7 +533,7 @@ impl RinkInputHandler {
&mut (*self.queued_events).borrow_mut(), &mut (*self.queued_events).borrow_mut(),
&mut resolved_events, &mut resolved_events,
layout, layout,
tree, dom,
); );
let events = self let events = self
@@ -569,7 +569,7 @@ impl RinkInputHandler {
} }
} }
for (event, datas) in hm { for (event, datas) in hm {
for node in tree.get_listening_sorted(event) { for node in dom.get_listening_sorted(event) {
for data in &datas { for data in &datas {
resolved_events.push(UserEvent { resolved_events.push(UserEvent {
scope_id: None, scope_id: None,
+13 -13
View File
@@ -68,11 +68,11 @@ pub fn launch_cfg(app: Component<()>, cfg: Config) {
cx.provide_root_context(state); cx.provide_root_context(state);
cx.provide_root_context(TuiContext { tx: event_tx_clone }); cx.provide_root_context(TuiContext { tx: event_tx_clone });
let mut tree: RealDom<StretchLayout, StyleModifier> = RealDom::new(); let mut rdom: RealDom<StretchLayout, StyleModifier> = RealDom::new();
let mutations = dom.rebuild(); let mutations = dom.rebuild();
let to_update = tree.apply_mutations(vec![mutations]); let to_update = rdom.apply_mutations(vec![mutations]);
let mut stretch = Stretch::new(); let mut stretch = Stretch::new();
let _to_rerender = tree let _to_rerender = rdom
.update_state(&dom, to_update, &mut stretch, &mut ()) .update_state(&dom, to_update, &mut stretch, &mut ())
.unwrap(); .unwrap();
@@ -81,7 +81,7 @@ pub fn launch_cfg(app: Component<()>, cfg: Config) {
event_rx, event_rx,
handler, handler,
cfg, cfg,
tree, rdom,
stretch, stretch,
register_event, register_event,
) )
@@ -93,7 +93,7 @@ fn render_vdom(
mut event_reciever: UnboundedReceiver<InputEvent>, mut event_reciever: UnboundedReceiver<InputEvent>,
handler: RinkInputHandler, handler: RinkInputHandler,
cfg: Config, cfg: Config,
mut tree: RealDom<StretchLayout, StyleModifier>, mut rdom: RealDom<StretchLayout, StyleModifier>,
mut stretch: Stretch, mut stretch: Stretch,
mut register_event: impl FnMut(crossterm::event::Event), mut register_event: impl FnMut(crossterm::event::Event),
) -> Result<()> { ) -> Result<()> {
@@ -130,8 +130,8 @@ fn render_vdom(
let dims = frame.size(); let dims = frame.size();
let width = dims.width; let width = dims.width;
let height = dims.height; let height = dims.height;
let root_id = tree.root_id(); let root_id = rdom.root_id();
let root_node = tree[root_id].up_state.node.unwrap(); let root_node = rdom[root_id].up_state.node.unwrap();
stretch stretch
.compute_layout( .compute_layout(
@@ -142,8 +142,8 @@ fn render_vdom(
}, },
) )
.unwrap(); .unwrap();
let root = &tree[tree.root_id()]; let root = &rdom[rdom.root_id()];
render::render_vnode(frame, &stretch, &tree, &root, cfg); render::render_vnode(frame, &stretch, &rdom, &root, cfg);
})?; })?;
} }
@@ -182,16 +182,16 @@ fn render_vdom(
{ {
// resolve events before rendering // resolve events before rendering
let evts = handler.get_events(&stretch, &mut tree); let evts = handler.get_events(&stretch, &mut rdom);
for e in evts { for e in evts {
vdom.handle_message(SchedulerMsg::Event(e)); vdom.handle_message(SchedulerMsg::Event(e));
} }
let mutations = vdom.work_with_deadline(|| false); let mutations = vdom.work_with_deadline(|| false);
// updates the tree's nodes // updates the dom's nodes
let to_update = tree.apply_mutations(mutations); let to_update = rdom.apply_mutations(mutations);
// update the style and layout // update the style and layout
to_rerender.extend( to_rerender.extend(
tree.update_state(vdom, to_update, &mut stretch, &mut ()) rdom.update_state(vdom, to_update, &mut stretch, &mut ())
.unwrap() .unwrap()
.iter(), .iter(),
) )
+2 -2
View File
@@ -23,7 +23,7 @@ const RADIUS_MULTIPLIER: [f32; 2] = [1.0, 0.5];
pub fn render_vnode( pub fn render_vnode(
frame: &mut tui::Frame<CrosstermBackend<Stdout>>, frame: &mut tui::Frame<CrosstermBackend<Stdout>>,
layout: &Stretch, layout: &Stretch,
tree: &RealDom<StretchLayout, StyleModifier>, rdom: &RealDom<StretchLayout, StyleModifier>,
node: &Node<StretchLayout, StyleModifier>, node: &Node<StretchLayout, StyleModifier>,
cfg: Config, cfg: Config,
) { ) {
@@ -77,7 +77,7 @@ pub fn render_vnode(
} }
for c in children { for c in children {
render_vnode(frame, layout, tree, &tree[c.0], cfg); render_vnode(frame, layout, rdom, &rdom[c.0], cfg);
} }
} }
NodeType::Placeholder => unreachable!(), NodeType::Placeholder => unreachable!(),
-64
View File
@@ -1,64 +0,0 @@
use stretch::style::Dimension;
use stretch2 as stretch;
#[test]
fn relayout() {
let mut stretch = stretch::Stretch::new();
let node1 = stretch
.new_node(
stretch::style::Style {
size: stretch::geometry::Size { width: Dimension::Points(8f32), height: Dimension::Points(80f32) },
..Default::default()
},
&[],
)
.unwrap();
let node0 = stretch
.new_node(
stretch::style::Style {
align_self: stretch::prelude::AlignSelf::Center,
size: stretch::geometry::Size { width: Dimension::Auto, height: Dimension::Auto },
// size: stretch::geometry::Size { width: Dimension::Percent(1.0), height: Dimension::Percent(1.0) },
..Default::default()
},
&[node1],
)
.unwrap();
let node = stretch
.new_node(
stretch::style::Style {
size: stretch::geometry::Size { width: Dimension::Percent(1f32), height: Dimension::Percent(1f32) },
..Default::default()
},
&[node0],
)
.unwrap();
println!("0:");
stretch
.compute_layout(
node,
stretch::geometry::Size {
width: stretch::prelude::Number::Defined(100f32),
height: stretch::prelude::Number::Defined(100f32),
},
)
.unwrap();
let initial = stretch.layout(node).unwrap().location;
let initial0 = stretch.layout(node0).unwrap().location;
let initial1 = stretch.layout(node1).unwrap().location;
for i in 1..10 {
println!("\n\n{i}:");
stretch
.compute_layout(
node,
stretch::geometry::Size {
width: stretch::prelude::Number::Defined(100f32),
height: stretch::prelude::Number::Defined(100f32),
},
)
.unwrap();
assert_eq!(stretch.layout(node).unwrap().location, initial);
assert_eq!(stretch.layout(node0).unwrap().location, initial0);
assert_eq!(stretch.layout(node1).unwrap().location, initial1);
}
}