summaryrefslogtreecommitdiff
path: root/src/library/align.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-11-17 23:09:23 +0100
committerLaurenz <laurmaedje@gmail.com>2021-11-17 23:09:23 +0100
commit095fa52be5d7ed135f39553359e0253cfea6b71b (patch)
tree71e8a71a8b7755b32221a30c32f62cc146acdd33 /src/library/align.rs
parente869c899bcaefb19c3c47955577396b85494b823 (diff)
Placed node
Diffstat (limited to 'src/library/align.rs')
-rw-r--r--src/library/align.rs26
1 files changed, 15 insertions, 11 deletions
diff --git a/src/library/align.rs b/src/library/align.rs
index 591a4085..19c52f98 100644
--- a/src/library/align.rs
+++ b/src/library/align.rs
@@ -2,18 +2,8 @@ use super::prelude::*;
/// `align`: Configure the alignment along the layouting axes.
pub fn align(_: &mut EvalContext, args: &mut Args) -> TypResult<Value> {
- let mut x = args.named("horizontal")?;
- let mut y = args.named("vertical")?;
- for Spanned { v, span } in args.all::<Spanned<Align>>() {
- match v.axis() {
- None | Some(SpecAxis::Horizontal) if x.is_none() => x = Some(v),
- None | Some(SpecAxis::Vertical) if y.is_none() => y = Some(v),
- _ => bail!(span, "unexpected argument"),
- }
- }
-
+ let Spec { x, y } = parse_aligns(args)?;
let body = args.expect::<Template>("body")?;
-
Ok(Value::Template(Template::from_block(move |style| {
let mut style = style.clone();
if let Some(x) = x {
@@ -24,6 +14,20 @@ pub fn align(_: &mut EvalContext, args: &mut Args) -> TypResult<Value> {
})))
}
+/// 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() {
+ None | Some(SpecAxis::Horizontal) if x.is_none() => x = Some(v),
+ None | Some(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 {