diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-06-26 15:47:37 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-06-26 15:47:37 +0200 |
| commit | d53c933e4d56e6c0484d81814779ddb1597ee032 (patch) | |
| tree | 493aa2f8397a26b11a1137d2882994686b5ac7de /src/library | |
| parent | 784018124d13a4cfb050b8bf1fecd283cdc309db (diff) | |
Add box and block functions
Diffstat (limited to 'src/library')
| -rw-r--r-- | src/library/layout.rs | 20 | ||||
| -rw-r--r-- | src/library/mod.rs | 2 |
2 files changed, 22 insertions, 0 deletions
diff --git a/src/library/layout.rs b/src/library/layout.rs index 10389779..27b2e743 100644 --- a/src/library/layout.rs +++ b/src/library/layout.rs @@ -210,6 +210,26 @@ castable! { AlignValue: "alignment", } +/// ´box`: Place content in a rectangular box. +pub fn boxed(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value { + let width = args.named(ctx, "width"); + let height = args.named(ctx, "height"); + let body = args.eat(ctx).unwrap_or_default(); + Value::template(move |ctx| { + let child = ctx.exec_template_stack(&body).into(); + ctx.push_into_par(FixedNode { width, height, child }); + }) +} + +/// block`: Place content in a block. +pub fn block(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value { + let body = args.eat(ctx).unwrap_or_default(); + Value::template(move |ctx| { + let block = ctx.exec_template_stack(&body); + ctx.push_into_stack(block); + }) +} + /// `pad`: Pad content at the sides. pub fn pad(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value { let all = args.eat(ctx); diff --git a/src/library/mod.rs b/src/library/mod.rs index 5f0430b2..92ee9faa 100644 --- a/src/library/mod.rs +++ b/src/library/mod.rs @@ -41,6 +41,8 @@ pub fn new() -> Scope { std.def_func("h", h); std.def_func("v", v); std.def_func("align", align); + std.def_func("box", boxed); + std.def_func("block", block); std.def_func("pad", pad); std.def_func("stack", stack); std.def_func("grid", grid); |
