mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
41 lines
1.1 KiB
Rust
41 lines
1.1 KiB
Rust
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.named::<Dir>(ctx, "dir").unwrap_or(Dir::TTB);
|
|
let children = args.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_into_stack(StackNode {
|
|
dirs: Gen::new(ctx.state.lang.dir, dir),
|
|
aspect: None,
|
|
children,
|
|
});
|
|
})
|
|
}
|