diff options
| author | Martin <mhaug@live.de> | 2021-12-22 20:37:34 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-22 20:37:34 +0100 |
| commit | f6c7a8292dc1ab0560408fca9d74505e9d7cf13a (patch) | |
| tree | badd3076f6146cec34c55764600df5124c408521 /src/library/align.rs | |
| parent | 738ff7e1f573bef678932b313be9969a17af8d22 (diff) | |
| parent | 438255519e88bb790480306b9a9b452aaf054519 (diff) | |
Merge pull request #51 from typst/set-rules
Set rules
Diffstat (limited to 'src/library/align.rs')
| -rw-r--r-- | src/library/align.rs | 44 |
1 files changed, 25 insertions, 19 deletions
diff --git a/src/library/align.rs b/src/library/align.rs index 18920369..c16277f6 100644 --- a/src/library/align.rs +++ b/src/library/align.rs @@ -1,29 +1,19 @@ use super::prelude::*; +use super::ParNode; /// `align`: Configure the alignment along the layouting axes. pub fn align(_: &mut EvalContext, args: &mut Args) -> TypResult<Value> { - castable! { - Spec<Option<Align>>, - Expected: "1d or 2d alignment", - @align: Align => { - let mut aligns = Spec::default(); - aligns.set(align.axis(), Some(*align)); - aligns - }, - @aligns: Spec<Align> => aligns.map(Some), + let aligns: Spec<_> = args.expect("alignment")?; + let body: Node = args.expect("body")?; + let mut styles = Styles::new(); + if let Some(align) = aligns.x { + styles.set(ParNode::ALIGN, align); } - 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) = aligns.x { - style.par_mut().align = x; - } - - body.pack(&style).aligned(aligns) - }))) + Ok(Value::block( + body.into_block().styled(styles).aligned(aligns), + )) } /// A node that aligns its child. @@ -67,3 +57,19 @@ impl Layout for AlignNode { frames } } + +dynamic! { + Align: "alignment", +} + +castable! { + Spec<Option<Align>>, + Expected: "1d or 2d alignment", + @align: Align => { + let mut aligns = Spec::default(); + aligns.set(align.axis(), Some(*align)); + aligns + }, + @aligns: Spec<Align> => aligns.map(Some), + +} |
