diff options
Diffstat (limited to 'src/layout.rs')
-rw-r--r-- | src/layout.rs | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/layout.rs b/src/layout.rs index 011f859a..481b4166 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -19,8 +19,16 @@ pub struct Layout<'a> { } impl<'a> Layout<'a> { - pub(crate) fn new(layout: &'a result::Layout, parent_position: Point) -> Self { - let position = parent_position + Vector::new(layout.location.x, layout.location.y); + pub(crate) fn new(layout: &'a result::Layout) -> Self { + Self::with_parent_position(layout, Point::new(0.0, 0.0)) + } + + fn with_parent_position( + layout: &'a result::Layout, + parent_position: Point, + ) -> Self { + let position = + parent_position + Vector::new(layout.location.x, layout.location.y); Layout { layout, position } } @@ -47,9 +55,8 @@ impl<'a> Layout<'a> { /// [`Layout`]: struct.Layout.html /// [`Node`]: struct.Node.html pub fn children(&'a self) -> impl Iterator<Item = Layout<'a>> { - self.layout - .children - .iter() - .map(move |layout| Layout::new(layout, self.position)) + self.layout.children.iter().map(move |layout| { + Layout::with_parent_position(layout, self.position) + }) } } |