diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-10-31 15:52:16 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-10-31 15:52:35 +0100 |
| commit | 5b344b663a3d224134923eea0d67ebf44c069b07 (patch) | |
| tree | 34a5fb464a38b9d4cb11294379b3ddf351dfce21 /src/library/container.rs | |
| parent | feff013abb17f31bc5305fe77fe67cf615c19ff2 (diff) | |
Reorganize modules
Instead of separating functionality into layout and library, everything lives in the library now. This way, related things live side by side and there are no duplicate file names in the two directories.
Diffstat (limited to 'src/library/container.rs')
| -rw-r--r-- | src/library/container.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/library/container.rs b/src/library/container.rs new file mode 100644 index 00000000..b2591cce --- /dev/null +++ b/src/library/container.rs @@ -0,0 +1,27 @@ +use super::prelude::*; +use super::{ShapeKind, ShapeNode}; + +/// `box`: Place content in a rectangular box. +pub fn box_(_: &mut EvalContext, args: &mut Args) -> TypResult<Value> { + let width = args.named("width")?; + let height = args.named("height")?; + let fill = args.named("fill")?; + let body: Template = args.find().unwrap_or_default(); + Ok(Value::Template(Template::from_inline(move |style| { + ShapeNode { + shape: ShapeKind::Rect, + width, + height, + fill: fill.map(Paint::Color), + child: Some(body.to_stack(style).pack()), + } + }))) +} + +/// `block`: Place content in a block. +pub fn block(_: &mut EvalContext, args: &mut Args) -> TypResult<Value> { + let body: Template = args.expect("body")?; + Ok(Value::Template(Template::from_block(move |style| { + body.to_stack(style) + }))) +} |
