gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 227Rust 7TOML 3CSS 1307 Sutichaykuna

Add parent method to the TaffyTree (#619)

c1a078f6015f7147aa170cc6b9209cd09207bf2d · ruwaq Nico Burns · (2 wata ñawpaq) · tayta 0e438dc27 · kay commitpi sach'ata qhaway

Semántico sayk'uy · 1

src/tree/taffy_tree.rs

1 qillqakuna · +8 −0

diff --git a/src/tree/taffy_tree.rs b/src/tree/taffy_tree.rs
index e93d7d27c..7a8f4bd9d 100644
--- a/src/tree/taffy_tree.rs
+++ b/src/tree/taffy_tree.rs
@@ -601,6 +601,14 @@ impl<NodeContext> TaffyTree<NodeContext> {
         self.nodes.len()
     }
 
+    /// Returns the `NodeId` of the parent node of the specified node (if it exists)
+    ///
+    /// - Return None if the specified node has no parent
+    /// - Panics if the specified node does not exist
+    pub fn parent(&self, child_id: NodeId) -> Option<NodeId> {
+        self.parents[child_id.into()]
+    }
+
     /// Returns a list of children that belong to the parent node
     pub fn children(&self, parent: NodeId) -> TaffyResult<Vec<NodeId>> {
         Ok(self.children[parent.into()].iter().copied().collect::<_>())