diff options
| author | Laurenz <laurmaedje@gmail.com> | 2020-10-03 13:23:59 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2020-10-03 13:23:59 +0200 |
| commit | 0fc25d732d7cbc37cf801645849d1060f2cec4a3 (patch) | |
| tree | 706aa8d1bf4135d1dd3ac17a5023bc5e24ded69d /src/library | |
| parent | 8dbc5b60cc4a88f68ee82607af3a3c454cd8f68b (diff) | |
Port to kurbo 🎋
Diffstat (limited to 'src/library')
| -rw-r--r-- | src/library/boxed.rs | 20 | ||||
| -rw-r--r-- | src/library/page.rs | 19 |
2 files changed, 21 insertions, 18 deletions
diff --git a/src/library/boxed.rs b/src/library/boxed.rs index 85025264..ac0bc19e 100644 --- a/src/library/boxed.rs +++ b/src/library/boxed.rs @@ -4,8 +4,8 @@ use crate::length::ScaleLength; /// `box`: Layouts its contents into a box. /// /// # Keyword arguments -/// - `width`: The width of the box (length of relative to parent's width). -/// - `height`: The height of the box (length of relative to parent's height). +/// - `width`: The width of the box (length or relative to parent's width). +/// - `height`: The height of the box (length or relative to parent's height). pub async fn boxed( _: Span, mut args: DictValue, @@ -19,17 +19,17 @@ pub async fn boxed( ctx.spaces.truncate(1); ctx.repeat = false; - if let Some(w) = args.take_key::<ScaleLength>("width", &mut f) { - let length = w.raw_scaled(ctx.base.x); - ctx.base.x = length; - ctx.spaces[0].size.x = length; + if let Some(width) = args.take_key::<ScaleLength>("width", &mut f) { + let length = width.raw_scaled(ctx.base.width); + ctx.base.width = length; + ctx.spaces[0].size.width = length; ctx.spaces[0].expansion.horizontal = true; } - if let Some(h) = args.take_key::<ScaleLength>("height", &mut f) { - let length = h.raw_scaled(ctx.base.y); - ctx.base.y = length; - ctx.spaces[0].size.y = length; + if let Some(height) = args.take_key::<ScaleLength>("height", &mut f) { + let length = height.raw_scaled(ctx.base.height); + ctx.base.height = length; + ctx.spaces[0].size.height = length; ctx.spaces[0].expansion.vertical = true; } diff --git a/src/library/page.rs b/src/library/page.rs index b4f74e48..8188bb67 100644 --- a/src/library/page.rs +++ b/src/library/page.rs @@ -1,4 +1,7 @@ +use std::mem; + use super::*; +use crate::geom::Sides; use crate::length::{Length, ScaleLength}; use crate::paper::{Paper, PaperClass}; @@ -27,36 +30,36 @@ pub async fn page(_: Span, mut args: DictValue, ctx: LayoutContext<'_>) -> Pass< if let Some(width) = args.take_key::<Length>("width", &mut f) { style.class = PaperClass::Custom; - style.size.x = width.as_raw(); + style.size.width = width.as_raw(); } if let Some(height) = args.take_key::<Length>("height", &mut f) { style.class = PaperClass::Custom; - style.size.y = height.as_raw(); + style.size.height = height.as_raw(); } if let Some(margins) = args.take_key::<ScaleLength>("margins", &mut f) { - style.margins.set_all(Some(margins)); + style.margins = Sides::uniform(Some(margins)); } if let Some(left) = args.take_key::<ScaleLength>("left", &mut f) { style.margins.left = Some(left); } - if let Some(right) = args.take_key::<ScaleLength>("right", &mut f) { - style.margins.right = Some(right); - } - if let Some(top) = args.take_key::<ScaleLength>("top", &mut f) { style.margins.top = Some(top); } + if let Some(right) = args.take_key::<ScaleLength>("right", &mut f) { + style.margins.right = Some(right); + } + if let Some(bottom) = args.take_key::<ScaleLength>("bottom", &mut f) { style.margins.bottom = Some(bottom); } if args.take_key::<bool>("flip", &mut f).unwrap_or(false) { - style.size.swap(); + mem::swap(&mut style.size.width, &mut style.size.height); } args.unexpected(&mut f); |
