diff options
| author | Laurenz <laurmaedje@gmail.com> | 2020-10-04 19:06:20 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2020-10-04 19:06:20 +0200 |
| commit | 0f7c70fd93db23ec866ae13aa2f146b7787afabf (patch) | |
| tree | 7a67019fa77931e1722789cfd27997dd82a9b521 /src/library/page.rs | |
| parent | 6672f8f7dfcb38bbda3ec92bdf95341c05e9a782 (diff) | |
Separate state and constraints 🧶
Diffstat (limited to 'src/library/page.rs')
| -rw-r--r-- | src/library/page.rs | 56 |
1 files changed, 27 insertions, 29 deletions
diff --git a/src/library/page.rs b/src/library/page.rs index 77eb6244..5fda9d5d 100644 --- a/src/library/page.rs +++ b/src/library/page.rs @@ -19,56 +19,54 @@ use crate::paper::{Paper, PaperClass}; /// - `top`: The top margin (length or relative to height). /// - `bottom`: The bottom margin (length or relative to height). /// - `flip`: Flips custom or paper-defined width and height (boolean). -pub async fn page(_: Span, mut args: DictValue, ctx: LayoutContext<'_>) -> Pass<Value> { - let mut f = Feedback::new(); - let mut style = ctx.style.page; +pub async fn page(mut args: DictValue, ctx: &mut LayoutContext) -> Value { + let mut page = ctx.state.page.clone(); if let Some(paper) = args.take::<Paper>() { - style.class = paper.class; - style.size = paper.size(); + page.class = paper.class; + page.size = paper.size(); } - if let Some(Abs(width)) = args.take_key::<Abs>("width", &mut f) { - style.class = PaperClass::Custom; - style.size.width = width; + if let Some(Abs(width)) = args.take_key::<Abs>("width", &mut ctx.f) { + page.class = PaperClass::Custom; + page.size.width = width; } - if let Some(Abs(height)) = args.take_key::<Abs>("height", &mut f) { - style.class = PaperClass::Custom; - style.size.height = height; + if let Some(Abs(height)) = args.take_key::<Abs>("height", &mut ctx.f) { + page.class = PaperClass::Custom; + page.size.height = height; } - if let Some(margins) = args.take_key::<Linear>("margins", &mut f) { - style.margins = Sides::uniform(Some(margins)); + if let Some(margins) = args.take_key::<Linear>("margins", &mut ctx.f) { + page.margins = Sides::uniform(Some(margins)); } - if let Some(left) = args.take_key::<Linear>("left", &mut f) { - style.margins.left = Some(left); + if let Some(left) = args.take_key::<Linear>("left", &mut ctx.f) { + page.margins.left = Some(left); } - if let Some(top) = args.take_key::<Linear>("top", &mut f) { - style.margins.top = Some(top); + if let Some(top) = args.take_key::<Linear>("top", &mut ctx.f) { + page.margins.top = Some(top); } - if let Some(right) = args.take_key::<Linear>("right", &mut f) { - style.margins.right = Some(right); + if let Some(right) = args.take_key::<Linear>("right", &mut ctx.f) { + page.margins.right = Some(right); } - if let Some(bottom) = args.take_key::<Linear>("bottom", &mut f) { - style.margins.bottom = Some(bottom); + if let Some(bottom) = args.take_key::<Linear>("bottom", &mut ctx.f) { + page.margins.bottom = Some(bottom); } - if args.take_key::<bool>("flip", &mut f).unwrap_or(false) { - mem::swap(&mut style.size.width, &mut style.size.height); + if args.take_key::<bool>("flip", &mut ctx.f).unwrap_or(false) { + mem::swap(&mut page.size.width, &mut page.size.height); } - args.unexpected(&mut f); - Pass::commands(vec![SetPageStyle(style)], f) + args.unexpected(&mut ctx.f); + Value::Commands(vec![SetPageState(page)]) } /// `pagebreak`: Ends the current page. -pub async fn pagebreak(_: Span, args: DictValue, _: LayoutContext<'_>) -> Pass<Value> { - let mut f = Feedback::new(); - args.unexpected(&mut f); - Pass::commands(vec![BreakPage], f) +pub async fn pagebreak(args: DictValue, ctx: &mut LayoutContext) -> Value { + args.unexpected(&mut ctx.f); + Value::Commands(vec![BreakPage]) } |
