diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-01-04 21:29:15 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-01-04 21:29:15 +0100 |
| commit | 2e77b1c836220766398e379ae0157736fb448874 (patch) | |
| tree | 70fc7d28f44193f26d880b5315ce55ed951af73c /src/library/layout.rs | |
| parent | 77c06ebc24ab3a43dc2268763ff8f10963f875b4 (diff) | |
Better value representations, type function 🌐
Diffstat (limited to 'src/library/layout.rs')
| -rw-r--r-- | src/library/layout.rs | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/library/layout.rs b/src/library/layout.rs index e469c9be..774e6781 100644 --- a/src/library/layout.rs +++ b/src/library/layout.rs @@ -1,3 +1,5 @@ +use std::fmt::{self, Display, Formatter}; + use crate::eval::Softness; use crate::layout::{Expansion, NodeFixed, NodeSpacing, NodeStack}; use crate::paper::{Paper, PaperClass}; @@ -153,7 +155,19 @@ impl Switch for Alignment { } impl_type! { - Alignment: "alignment" + Alignment: "alignment", +} + +impl Display for Alignment { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + f.pad(match self { + Self::Left => "left", + Self::Center => "center", + Self::Right => "right", + Self::Top => "top", + Self::Bottom => "bottom", + }) + } } /// `box`: Layout content into a box. @@ -161,7 +175,7 @@ impl_type! { /// # 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. -pub fn boxed(ctx: &mut EvalContext, args: &mut Args) -> Value { +pub fn box_(ctx: &mut EvalContext, args: &mut Args) -> Value { let snapshot = ctx.state.clone(); let width = args.get(ctx, "width"); @@ -189,7 +203,7 @@ pub fn boxed(ctx: &mut EvalContext, args: &mut Args) -> Value { ctx.push(NodeFixed { width, height, - child: Node::any(NodeStack { dirs, align, expansion, children }), + child: NodeStack { dirs, align, expansion, children }.into(), }); ctx.state = snapshot; |
