summaryrefslogtreecommitdiff
path: root/src/layout/tree.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2019-11-18 15:10:11 +0100
committerLaurenz <laurmaedje@gmail.com>2019-11-18 15:10:11 +0100
commit1a6fb48bc5e95d0a9ef243ab62517557189c0eea (patch)
tree06f704fe638d5ae25f4976874500c5da75316348 /src/layout/tree.rs
parent1eb25f86dd6763c4f2d7e60b6d09af60ada50af6 (diff)
Page style modification functions 📜
- `page.size` - `page.margins`
Diffstat (limited to 'src/layout/tree.rs')
-rw-r--r--src/layout/tree.rs24
1 files changed, 20 insertions, 4 deletions
diff --git a/src/layout/tree.rs b/src/layout/tree.rs
index 177a6308..ae6a15c8 100644
--- a/src/layout/tree.rs
+++ b/src/layout/tree.rs
@@ -1,4 +1,5 @@
use super::*;
+use smallvec::smallvec;
/// Layouts syntax trees into boxes.
pub fn layout_tree(tree: &SyntaxTree, ctx: LayoutContext) -> LayoutResult<MultiLayout> {
@@ -19,12 +20,12 @@ impl<'a, 'p> TreeLayouter<'a, 'p> {
fn new(ctx: LayoutContext<'a, 'p>) -> TreeLayouter<'a, 'p> {
TreeLayouter {
flex: FlexLayouter::new(FlexContext {
- flex_spacing: flex_spacing(&ctx.style),
+ flex_spacing: flex_spacing(&ctx.text_style),
spaces: ctx.spaces.clone(),
axes: ctx.axes,
shrink_to_fit: ctx.shrink_to_fit,
}),
- style: ctx.style.clone(),
+ style: ctx.text_style.clone(),
ctx,
}
}
@@ -68,7 +69,8 @@ impl<'a, 'p> TreeLayouter<'a, 'p> {
let (flex_spaces, stack_spaces) = self.flex.remaining()?;
let ctx = |spaces| LayoutContext {
- style: &self.style,
+ top_level: false,
+ text_style: &self.style,
spaces: spaces,
shrink_to_fit: true,
.. self.ctx
@@ -107,7 +109,21 @@ impl<'a, 'p> TreeLayouter<'a, 'p> {
Command::BreakParagraph => self.break_paragraph()?,
- Command::SetStyle(style) => self.style = style,
+ Command::SetTextStyle(style) => self.style = style,
+ Command::SetPageStyle(style) => {
+ if !self.ctx.top_level {
+ Err(LayoutError::Unallowed("can only set page style from top level"))?;
+ }
+
+ self.ctx.page_style = style;
+ self.flex.set_spaces(smallvec![
+ LayoutSpace {
+ dimensions: style.dimensions,
+ padding: style.margins,
+ }
+ ], true);
+ },
+
Command::SetAxes(axes) => {
self.flex.set_axes(axes);
self.ctx.axes = axes;