summaryrefslogtreecommitdiff
path: root/src/library/stack.rs
blob: 03bdc6a1ddf4c7b8656200c68c1b9560647167e1 (plain) (blame)
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
36
37
38
39
40
use super::*;
use crate::layout::{StackChild, StackNode};

/// `stack`: Stack children along an axis.
///
/// # Positional parameters
/// - Children: variadic, of type `template`.
///
/// # Named parameters
/// - Stacking direction: `dir`, of type `direction`.
///
/// # Return value
/// A template that places its children along the specified layouting axis.
///
/// # Relevant types and constants
/// - Type `direction`
///   - `ltr`
///   - `rtl`
///   - `ttb`
///   - `btt`
pub fn stack(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value {
    let dir = args.eat_named::<Dir>(ctx, "dir").unwrap_or(Dir::TTB);
    let children = args.eat_all::<TemplateValue>(ctx);

    Value::template("stack", move |ctx| {
        let children = children
            .iter()
            .map(|child| {
                let child = ctx.exec_template_stack(child).into();
                StackChild::Any(child, ctx.state.aligns)
            })
            .collect();

        ctx.push(StackNode {
            dirs: Gen::new(ctx.state.lang.dir, dir),
            aspect: None,
            children,
        });
    })
}