summaryrefslogtreecommitdiff
path: root/src/layout/document.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2020-10-10 22:19:36 +0200
committerLaurenz <laurmaedje@gmail.com>2020-10-10 22:19:36 +0200
commit92c01da36016e94ff20163806ddcbcf7e33d4031 (patch)
tree1a900b3c11edcc93e9153fada3ce92310db5768b /src/layout/document.rs
parent42500d5ed85539c5ab04dd3544beaf802da29be9 (diff)
Switch back to custom geometry types, unified with layout primitives 🏞
Diffstat (limited to 'src/layout/document.rs')
-rw-r--r--src/layout/document.rs47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/layout/document.rs b/src/layout/document.rs
new file mode 100644
index 00000000..c2d7b38b
--- /dev/null
+++ b/src/layout/document.rs
@@ -0,0 +1,47 @@
+use super::*;
+
+/// The top-level layout node.
+#[derive(Debug, Clone, PartialEq)]
+pub struct Document {
+ pub runs: Vec<Pages>,
+}
+
+impl Document {
+ /// Layout the document.
+ pub async fn layout(&self, ctx: &mut LayoutContext) -> Vec<BoxLayout> {
+ let mut layouts = vec![];
+ for run in &self.runs {
+ layouts.extend(run.layout(ctx).await);
+ }
+ layouts
+ }
+}
+
+/// A variable-length run of pages that all have the same properties.
+#[derive(Debug, Clone, PartialEq)]
+pub struct Pages {
+ /// The size of the pages.
+ pub size: Size,
+ /// The layout node that produces the actual pages.
+ pub child: LayoutNode,
+}
+
+impl Pages {
+ /// Layout the page run.
+ pub async fn layout(&self, ctx: &mut LayoutContext) -> Vec<BoxLayout> {
+ 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 {
+ LayoutItem::Spacing(_) => None,
+ LayoutItem::Box(layout, _) => Some(layout),
+ })
+ .collect()
+ }
+}