From e55ac637a9c4422b2fccfcc56c25449160e56e02 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 23 Jul 2019 10:49:24 +0200 Subject: Add `Runtime` concept to abstract caching --- src/layout.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'src/layout.rs') 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> { - 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) + }) } } -- cgit