diff options
| author | Laurenz <laurmaedje@gmail.com> | 2020-10-07 17:07:44 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2020-10-07 17:07:44 +0200 |
| commit | 537545e7f8351d7677c396456e46568f5a5e2a7a (patch) | |
| tree | f4c7614293246db06c7fa7496458da01b15c3b84 /src/library/align.rs | |
| parent | ca1256c924f3672feb76dbc2bc2e309eb4fc4cf5 (diff) | |
Evaluation and node-based layouting 🚀
Diffstat (limited to 'src/library/align.rs')
| -rw-r--r-- | src/library/align.rs | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/src/library/align.rs b/src/library/align.rs index f3280065..acd3a85c 100644 --- a/src/library/align.rs +++ b/src/library/align.rs @@ -14,7 +14,9 @@ use crate::prelude::*; /// - `vertical`: Any of `top`, `bottom` or `center`. /// /// There may not be two alignment specifications for the same axis. -pub async fn align(mut args: Args, ctx: &mut LayoutContext) -> Value { +pub fn align(mut args: Args, ctx: &mut EvalContext) -> Value { + let snapshot = ctx.state.clone(); + let body = args.find::<SynTree>(); let first = args.get::<_, Spanned<SpecAlign>>(ctx, 0); let second = args.get::<_, Spanned<SpecAlign>>(ctx, 1); @@ -29,21 +31,25 @@ pub async fn align(mut args: Args, ctx: &mut LayoutContext) -> Value { .chain(hor.into_iter().map(|align| (Some(SpecAxis::Horizontal), align))) .chain(ver.into_iter().map(|align| (Some(SpecAxis::Vertical), align))); - let aligns = dedup_aligns(ctx, iter); + let prev_main = ctx.state.aligns.main; + ctx.state.aligns = dedup_aligns(ctx, iter); + + if prev_main != ctx.state.aligns.main { + ctx.end_par_group(); + ctx.start_par_group(); + } + + if let Some(body) = body { + body.eval(ctx); + ctx.state = snapshot; + } - Value::Commands(match body { - Some(tree) => vec![ - SetAlignment(aligns), - LayoutSyntaxTree(tree), - SetAlignment(ctx.state.aligns), - ], - None => vec![SetAlignment(aligns)], - }) + Value::None } /// Deduplicate alignments and deduce to which axes they apply. fn dedup_aligns( - ctx: &mut LayoutContext, + ctx: &mut EvalContext, iter: impl Iterator<Item = (Option<SpecAxis>, Spanned<SpecAlign>)>, ) -> Gen2<GenAlign> { let mut aligns = ctx.state.aligns; |
