diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-11-23 12:45:20 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-11-23 12:45:20 +0100 |
| commit | 4f9e5819bbab1f93ad4f4b789038c60487a76368 (patch) | |
| tree | 488a4e0422db4531d9882cf08f0b5cc21ae55a23 /src/library/align.rs | |
| parent | d3f6040cedacad1b6c323be721c9086f6c5d9a44 (diff) | |
2d alignments with plus operator
Diffstat (limited to 'src/library/align.rs')
| -rw-r--r-- | src/library/align.rs | 20 |
1 files changed, 3 insertions, 17 deletions
diff --git a/src/library/align.rs b/src/library/align.rs index 97196aa7..7ce749d1 100644 --- a/src/library/align.rs +++ b/src/library/align.rs @@ -2,32 +2,18 @@ use super::prelude::*; /// `align`: Configure the alignment along the layouting axes. pub fn align(_: &mut EvalContext, args: &mut Args) -> TypResult<Value> { - let Spec { x, y } = parse_aligns(args)?; + let aligns = args.expect::<Spec<_>>("alignment")?; let body = args.expect::<Template>("body")?; Ok(Value::Template(Template::from_block(move |style| { let mut style = style.clone(); - if let Some(x) = x { + if let Some(x) = aligns.x { style.par_mut().align = x; } - body.pack(&style).aligned(x, y) + body.pack(&style).aligned(aligns) }))) } -/// Parse alignment arguments with shorthand. -pub(super) fn parse_aligns(args: &mut Args) -> TypResult<Spec<Option<Align>>> { - let mut x = args.named("horizontal")?; - let mut y = args.named("vertical")?; - for Spanned { v, span } in args.all::<Spanned<Align>>() { - match v.axis() { - SpecAxis::Horizontal if x.is_none() => x = Some(v), - SpecAxis::Vertical if y.is_none() => y = Some(v), - _ => bail!(span, "unexpected argument"), - } - } - Ok(Spec::new(x, y)) -} - /// A node that aligns its child. #[derive(Debug, Hash)] pub struct AlignNode { |
