diff options
| author | Martin Haug <mhaug@live.de> | 2021-02-06 12:30:44 +0100 |
|---|---|---|
| committer | Martin Haug <mhaug@live.de> | 2021-02-06 12:30:44 +0100 |
| commit | 80e076814dde330fb2136172580f11e939bc6601 (patch) | |
| tree | 6cd3474ffa5e2aced38e47a7ef563ab8940612be /src/library/layout.rs | |
| parent | 8469bad7487e111c8e5a0ec542f0232a0ebb4bdc (diff) | |
Merge `rect` and `box` 🦚
Diffstat (limited to 'src/library/layout.rs')
| -rw-r--r-- | src/library/layout.rs | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/library/layout.rs b/src/library/layout.rs index 0e04c507..bbcd7898 100644 --- a/src/library/layout.rs +++ b/src/library/layout.rs @@ -1,7 +1,7 @@ use std::fmt::{self, Display, Formatter}; -use crate::eval::Softness; -use crate::layout::{Expansion, NodeFixed, NodeSpacing, NodeStack}; +use crate::{eval::Softness, layout::NodeBackground}; +use crate::layout::{Expansion, Fill, NodeFixed, NodeSpacing, NodeStack}; use crate::paper::{Paper, PaperClass}; use crate::prelude::*; @@ -175,6 +175,7 @@ impl Display for Alignment { /// # Named arguments /// - Width of the box: `width`, of type `linear` relative to parent width. /// - Height of the box: `height`, of type `linear` relative to parent height. +/// - Background color of the box: `color`, of type `color`. pub fn box_(ctx: &mut EvalContext, args: &mut Args) -> Value { let snapshot = ctx.state.clone(); @@ -182,6 +183,7 @@ pub fn box_(ctx: &mut EvalContext, args: &mut Args) -> Value { let height = args.get(ctx, "height"); let main = args.get(ctx, "main-dir"); let cross = args.get(ctx, "cross-dir"); + let color = args.get(ctx, "color"); ctx.set_dirs(Gen::new(main, cross)); @@ -199,11 +201,21 @@ pub fn box_(ctx: &mut EvalContext, args: &mut Args) -> Value { 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())); - ctx.push(NodeFixed { + let fixed_node = NodeFixed { width, height, child: NodeStack { dirs, align, expand, children }.into(), - }); + }; + + if let Some(color) = color { + ctx.push(NodeBackground { + fill: Fill::Color(color), + child: fixed_node, + }) + } else { + ctx.push(fixed_node); + } + ctx.state = snapshot; Value::None |
