summaryrefslogtreecommitdiff
path: root/src/layout/mod.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2020-11-25 16:56:29 +0100
committerLaurenz <laurmaedje@gmail.com>2020-11-25 16:56:29 +0100
commit11e44516fae84f907ea992311fcfdc3636101f14 (patch)
treeff9b6a04c3accd5c0f75f1ceb60e578c389a2606 /src/layout/mod.rs
parent761931405c68efe0a35d96524df797dda7155723 (diff)
Merge some modules 🥞
Diffstat (limited to 'src/layout/mod.rs')
-rw-r--r--src/layout/mod.rs36
1 files changed, 32 insertions, 4 deletions
diff --git a/src/layout/mod.rs b/src/layout/mod.rs
index 2d4553b4..57add044 100644
--- a/src/layout/mod.rs
+++ b/src/layout/mod.rs
@@ -1,8 +1,6 @@
//! Layouting of documents.
-mod document;
mod fixed;
-mod graphics;
mod node;
mod pad;
mod par;
@@ -16,9 +14,7 @@ use crate::font::SharedFontLoader;
use crate::geom::*;
use crate::shaping::Shaped;
-pub use document::*;
pub use fixed::*;
-pub use graphics::*;
pub use node::*;
pub use pad::*;
pub use par::*;
@@ -193,3 +189,35 @@ pub struct ImageElement {
/// The document size of the image.
pub size: Size,
}
+
+/// The top-level layout node.
+#[derive(Debug, Clone, PartialEq)]
+pub struct Document {
+ /// The runs of pages with same properties.
+ pub runs: Vec<Pages>,
+}
+
+impl Document {
+ /// Layout the document.
+ pub fn layout(&self, ctx: &mut LayoutContext) -> Vec<BoxLayout> {
+ self.runs.iter().flat_map(|run| run.layout(ctx)).collect()
+ }
+}
+
+/// A variable-length run of pages that all have the same properties.
+#[derive(Debug, Clone, PartialEq)]
+pub struct Pages {
+ /// The size of each page.
+ pub size: Size,
+ /// The layout node that produces the actual pages (typically a [`Stack`]).
+ pub child: LayoutNode,
+}
+
+impl Pages {
+ /// Layout the page run.
+ pub fn layout(&self, ctx: &mut LayoutContext) -> Vec<BoxLayout> {
+ let areas = Areas::repeat(self.size);
+ let layouted = self.child.layout(ctx, &areas);
+ layouted.into_layouts()
+ }
+}