blob: a91dbbe9f54a29e84ffe05166d26129a1c0ac69a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
use super::*;
/// 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 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 (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<BoxLayout> {
let areas = Areas::repeat(self.size);
let layouted = self.child.layout(ctx, &areas).await;
layouted.into_iter().filter_map(Layouted::into_boxed).collect()
}
}
|