From 47f0d5bae4198e471cf913898b1f7102193ba399 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Mon, 18 Aug 2025 02:29:13 +0200 Subject: [PATCH] Add `child` method to `Layout` --- core/src/layout.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/core/src/layout.rs b/core/src/layout.rs index 98d05602..9938342f 100644 --- a/core/src/layout.rs +++ b/core/src/layout.rs @@ -53,7 +53,7 @@ impl<'a> Layout<'a> { } } - /// Returns an iterator over the [`Layout`] of the children of a [`Node`]. + /// Returns an iterator over the children of this [`Layout`]. pub fn children(self) -> impl DoubleEndedIterator> { self.node.children().iter().map(move |node| { Layout::with_offset( @@ -62,6 +62,19 @@ impl<'a> Layout<'a> { ) }) } + + /// Returns the [`Layout`] of the child at the given index. + /// + /// This can be useful if you ever need to access children out of order + /// for layering purposes. + /// + /// # Panics + /// Panics if index is out of bounds. + pub fn child(self, index: usize) -> Layout<'a> { + let node = &self.node.children()[index]; + + Layout::with_offset(Vector::new(self.position.x, self.position.y), node) + } } /// Produces a [`Node`] with two children nodes one right next to each other.