From cd25b402816b0b4db0b310e3fff179f2a4fd7751 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sun, 23 May 2021 22:36:34 +0200 Subject: Stack function --- src/library/stack.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/library/stack.rs (limited to 'src/library/stack.rs') diff --git a/src/library/stack.rs b/src/library/stack.rs new file mode 100644 index 00000000..b6f92e16 --- /dev/null +++ b/src/library/stack.rs @@ -0,0 +1,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::(ctx, "dir").unwrap_or(Dir::TTB); + let children = args.eat_all::(ctx); + + Value::template("stack", move |ctx| { + let children = children + .iter() + .map(|child| { + let child = ctx.exec_template(child).into(); + StackChild::Any(child, ctx.state.aligns) + }) + .collect(); + + ctx.push(StackNode { + dirs: Gen::new(ctx.state.lang.dir, dir), + aspect: None, + children, + }); + }) +} -- cgit v1.2.3