diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-03-10 17:42:47 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-03-10 17:42:47 +0100 |
| commit | 4e5f85aa4ac0d6b51323bb2a6e1fbd3f4f46babb (patch) | |
| tree | 87f157c2058800e510e5538b0815c947c14fe22d /src/library/shapes.rs | |
| parent | b0446cbdd189a8cc3b6a7321579f4aa89415a8e0 (diff) | |
Pad function 🔲
Diffstat (limited to 'src/library/shapes.rs')
| -rw-r--r-- | src/library/shapes.rs | 22 |
1 files changed, 6 insertions, 16 deletions
diff --git a/src/library/shapes.rs b/src/library/shapes.rs index f9685fce..5e638c01 100644 --- a/src/library/shapes.rs +++ b/src/library/shapes.rs @@ -24,28 +24,18 @@ pub fn box_(ctx: &mut EvalContext, args: &mut ValueArgs) -> Value { let main = args.get(ctx, "main-dir"); let cross = args.get(ctx, "cross-dir"); let color = args.get(ctx, "color"); - let body = args.find::<ValueTemplate>(ctx); + let body = args.find::<ValueTemplate>(ctx).unwrap_or_default(); + + let fill_if = |c| if c { Expansion::Fill } else { Expansion::Fit }; + let expand = Spec::new(fill_if(width.is_some()), fill_if(height.is_some())); Value::template("box", move |ctx| { let snapshot = ctx.state.clone(); ctx.set_dirs(Gen::new(main, cross)); - let dirs = ctx.state.dirs; - let align = ctx.state.align; - - ctx.start_content_group(); - if let Some(body) = &body { - body.exec(ctx); - } - let children = ctx.end_content_group(); - let fill_if = |c| if c { Expansion::Fill } else { Expansion::Fit }; - let expand = Spec::new(fill_if(width.is_some()), fill_if(height.is_some())); - let fixed = NodeFixed { - width, - height, - child: NodeStack { dirs, align, expand, children }.into(), - }; + let child = ctx.exec_body(&body, expand); + let fixed = NodeFixed { width, height, child }; if let Some(color) = color { ctx.push(NodeBackground { |
