summaryrefslogtreecommitdiff
path: root/src/library/stack.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-05-23 22:36:34 +0200
committerLaurenz <laurmaedje@gmail.com>2021-05-23 22:36:34 +0200
commitcd25b402816b0b4db0b310e3fff179f2a4fd7751 (patch)
treea57445b7b59fa1fcdd64cc1c8d331d0532f8f225 /src/library/stack.rs
parent5ced5a69c0d4692bd625d19da290f2023ae4993d (diff)
Stack function
Diffstat (limited to 'src/library/stack.rs')
-rw-r--r--src/library/stack.rs40
1 files changed, 40 insertions, 0 deletions
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::<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(child).into();
+ StackChild::Any(child, ctx.state.aligns)
+ })
+ .collect();
+
+ ctx.push(StackNode {
+ dirs: Gen::new(ctx.state.lang.dir, dir),
+ aspect: None,
+ children,
+ });
+ })
+}