Add child method to Layout

This commit is contained in:
Héctor Ramón Jiménez 2025-08-18 02:29:13 +02:00
parent 2fd530a918
commit 47f0d5bae4
No known key found for this signature in database
GPG key ID: 7CC46565708259A7

View file

@ -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<Item = Layout<'a>> {
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.