diff --git a/packages/native-core/src/node_ref.rs b/packages/native-core/src/node_ref.rs index beb8519dc..12ac47f2b 100644 --- a/packages/native-core/src/node_ref.rs +++ b/packages/native-core/src/node_ref.rs @@ -160,36 +160,6 @@ pub struct NodeMask { } impl NodeMask { - pub fn from_node(node: &NodeType) -> Self { - match node { - NodeType::Text { .. } => NodeMaskBuilder::new().with_text().build(), - NodeType::Element(ElementNode { - tag: _, - namespace: _, - attributes, - listeners, - }) => Self { - attritutes: AttributeMask::Some( - attributes - .keys() - .map(|key| key.name.as_str().into()) - .collect(), - ), - namespace: true, - tag: true, - text: false, - listeners: !listeners.is_empty(), - }, - NodeType::Placeholder => Self { - attritutes: AttributeMask::default(), - tag: true, - namespace: true, - text: false, - listeners: false, - }, - } - } - /// Check if two masks overlap pub fn overlaps(&self, other: &Self) -> bool { (self.tag && other.tag) diff --git a/packages/native-core/src/passes.rs b/packages/native-core/src/passes.rs index d8961068f..2ca7eab47 100644 --- a/packages/native-core/src/passes.rs +++ b/packages/native-core/src/passes.rs @@ -191,7 +191,6 @@ pub trait Pass: Any + Send + Sync { debug_assert!(!Self::NodeDependencies::type_ids() .iter() .any(|id| *id == TypeId::of::())); - println!("passing: {node_id:?}"); // get all of the states from the tree view // Safety: No node has itself as a parent or child. let myself: SlabEntry<'static, Self> = unsafe { diff --git a/packages/native-core/src/real_dom.rs b/packages/native-core/src/real_dom.rs index fd3a0cac2..71dbf668e 100644 --- a/packages/native-core/src/real_dom.rs +++ b/packages/native-core/src/real_dom.rs @@ -610,6 +610,7 @@ pub trait NodeImmutable: Sized { pub trait NodeMutable: Sized + NodeImmutable { fn get_mut(&mut self) -> Option<&mut T>; + fn insert(&mut self, value: T); } #[derive(Clone, Copy)] @@ -648,6 +649,10 @@ impl<'a, V: FromAnyValue + Send + Sync> NodeMutable for NodeMut<'a, V> { fn get_mut(&mut self) -> Option<&mut T> { todo!("get_mut with mark as dirty") } + + fn insert(&mut self, _: T) { + todo!("insert with mark as dirty") + } } impl<'a, V: FromAnyValue + Send + Sync> NodeMut<'a, V> { @@ -777,4 +782,8 @@ impl<'a, V: FromAnyValue + Send + Sync> NodeMutable for NodeMutRaw<'a, V> { fn get_mut(&mut self) -> Option<&mut T> { self.dom.tree.get_mut::(self.id) } + + fn insert(&mut self, value: T) { + self.dom.tree.insert(self.id, value); + } } diff --git a/packages/native-core/src/tree.rs b/packages/native-core/src/tree.rs index 2ea71c3eb..ee2b03690 100644 --- a/packages/native-core/src/tree.rs +++ b/packages/native-core/src/tree.rs @@ -173,15 +173,17 @@ impl Tree { } pub fn get(&self, id: NodeId) -> Option<&T> { - self.nodes.read_slab().get(id) + self.nodes.try_read_slab().and_then(|slab| slab.get(id)) } pub fn get_mut(&mut self, id: NodeId) -> Option<&mut T> { - self.nodes.write_slab().get_mut(id) + self.nodes + .try_write_slab() + .and_then(|slab| slab.get_mut(id)) } pub fn insert(&mut self, id: NodeId, value: T) { - self.nodes.write_slab().insert(id, value); + self.nodes.get_or_insert_slab_mut().insert(id, value); } pub fn contains(&self, id: NodeId) -> bool { @@ -218,11 +220,9 @@ impl<'a> DynamicallyBorrowedTree<'a> { let nodes_data = self.node_slab(); let mut nodes = FxHashMap::default(); for id in immutable { - println!("reading {id:?}"); nodes.insert(id, MaybeRead::Read(self.nodes.get_slab(id).unwrap())); } for id in mutable { - println!("writing {id:?}"); nodes.insert(id, MaybeRead::Write(self.nodes.get_slab_mut(id).unwrap())); } diff --git a/packages/tui/src/focus.rs b/packages/tui/src/focus.rs index c263bc996..05ae2019c 100644 --- a/packages/tui/src/focus.rs +++ b/packages/tui/src/focus.rs @@ -246,8 +246,7 @@ impl FocusState { if !node.get::().unwrap().level.focusable() { panic!() } - let focused = node.get_mut::().unwrap(); - focused.0 = true; + node.insert(Focused(true)); if let Some(old) = self.last_focused_id.replace(id) { let mut old = rdom.get_mut_raw(old).unwrap(); let focused = old.get_mut::().unwrap(); @@ -304,7 +303,7 @@ impl FocusState { node.get_mut::().unwrap().0 = false; } let mut node = rdom.get_mut_raw(id).unwrap(); - node.get_mut::().unwrap().0 = true; + node.insert(Focused(true)); self.focus_level = node.get::().unwrap().level; // reset the position to the currently focused element while self.focus_iter.next(rdom).id() != id {} diff --git a/packages/tui/src/hooks.rs b/packages/tui/src/hooks.rs index 6f043d522..feec8686c 100644 --- a/packages/tui/src/hooks.rs +++ b/packages/tui/src/hooks.rs @@ -688,7 +688,8 @@ impl RinkInputHandler { for (event, datas) in hm { for node in dom.get_listening_sorted(event) { for data in &datas { - if node.get::().unwrap().0 { + let focused = node.get::(); + if focused.is_some() && focused.unwrap().0 { if let Some(id) = node.mounted_id() { resolved_events.push(Event { name: event, diff --git a/packages/tui/src/layout.rs b/packages/tui/src/layout.rs index 53287cc8b..6e34ba0c9 100644 --- a/packages/tui/src/layout.rs +++ b/packages/tui/src/layout.rs @@ -91,9 +91,6 @@ impl Pass for TaffyLayout { attribute, value, .. } in attributes { - assert!(SORTED_LAYOUT_ATTRS - .binary_search(&attribute.name.as_ref()) - .is_ok()); if let Some(text) = value.as_text() { apply_layout_attributes_cfg( &attribute.name, diff --git a/packages/tui/src/render.rs b/packages/tui/src/render.rs index 17355b5b5..fe6600ade 100644 --- a/packages/tui/src/render.rs +++ b/packages/tui/src/render.rs @@ -272,7 +272,8 @@ impl RinkWidget for NodeRef<'_> { if let Some(c) = self.get::().unwrap().core.bg { new_cell.bg = c; } - if self.get::().unwrap().0 { + let focused = self.get::(); + if focused.is_some() && focused.unwrap().0 { new_cell.bg.alpha = 100; new_cell.bg.color = new_cell.bg.blend(Color::White); }