From d3bc4ec07349a96c3863ddce63c2e52b5e7e9f2f Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sun, 11 Oct 2020 22:38:30 +0200 Subject: =?UTF-8?q?Refactor=20layouting=20base=20=F0=9F=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layout/document.rs | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) (limited to 'src/layout/document.rs') diff --git a/src/layout/document.rs b/src/layout/document.rs index 69ac3d9d..a91dbbe9 100644 --- a/src/layout/document.rs +++ b/src/layout/document.rs @@ -3,6 +3,7 @@ use super::*; /// The top-level layout node. #[derive(Debug, Clone, PartialEq)] pub struct Document { + /// The runs of pages with same properties. pub runs: Vec, } @@ -22,26 +23,17 @@ impl Document { pub struct Pages { /// The size of the pages. pub size: Size, - /// The layout node that produces the actual pages. + /// The layout node that produces the actual pages (typically a [stack]). + /// + /// [stack]: struct.Stack.html pub child: LayoutNode, } impl Pages { /// Layout the page run. pub async fn layout(&self, ctx: &mut LayoutContext) -> Vec { - let constraints = LayoutConstraints { - spaces: vec![LayoutSpace { base: self.size, size: self.size }], - repeat: true, - }; - - self.child - .layout(ctx, constraints) - .await - .into_iter() - .filter_map(|item| match item { - Layouted::Spacing(_) => None, - Layouted::Box(layout, _) => Some(layout), - }) - .collect() + let areas = Areas::repeat(self.size); + let layouted = self.child.layout(ctx, &areas).await; + layouted.into_iter().filter_map(Layouted::into_boxed).collect() } } -- cgit v1.2.3