1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
use crate::func::prelude::*;
use super::maps::{PosAxisMap, AlignmentKey};
function! {
/// `align`: Aligns content along the layouting axes.
#[derive(Debug, PartialEq)]
pub struct AlignFunc {
body: Option<SyntaxTree>,
map: PosAxisMap<AlignmentKey>,
}
parse(args, body, ctx) {
AlignFunc {
body: parse!(optional: body, ctx),
map: PosAxisMap::new(&mut args)?,
}
}
layout(self, mut ctx) {
ctx.base = ctx.spaces[0].dimensions;
let map = self.map.dedup(ctx.axes, |alignment| alignment.axis(ctx.axes))?;
for &axis in &[Primary, Secondary] {
if let Some(alignment) = map.get(axis) {
*ctx.alignment.get_mut(axis) = alignment.to_generic(ctx.axes, axis)?;
}
}
match &self.body {
Some(body) => vec![AddMultiple(layout(&body, ctx).await?)],
None => vec![SetAlignment(ctx.alignment)],
}
}
}
|