summaryrefslogtreecommitdiff
path: root/src/eval
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-11-16 12:47:14 +0100
committerLaurenz <laurmaedje@gmail.com>2021-11-16 12:47:14 +0100
commit79638d4bbdc140a8dca0ccfdf70ffd607d5da251 (patch)
tree3da8a7d345ccac389d07c8327d9c63fd7209a250 /src/eval
parent73c4701749ac3919c5b845002052326502c67306 (diff)
Don't wrap already layoutable nodes into flows/pars unnecessarily
Diffstat (limited to 'src/eval')
-rw-r--r--src/eval/template.rs15
-rw-r--r--src/eval/walk.rs6
2 files changed, 12 insertions, 9 deletions
diff --git a/src/eval/template.rs b/src/eval/template.rs
index 82a069f9..0604cc05 100644
--- a/src/eval/template.rs
+++ b/src/eval/template.rs
@@ -149,12 +149,15 @@ impl Template {
Self(Rc::new(vec![TemplateNode::Decorated(deco, self)]))
}
- /// Build the flow node resulting from instantiating the template with the
- /// given style.
- pub fn to_flow(&self, style: &Style) -> FlowNode {
- let mut builder = Builder::new(style, false);
- builder.template(self);
- builder.build_flow()
+ /// Pack the template into a layout node.
+ pub fn pack(&self, style: &Style) -> PackedNode {
+ if let [TemplateNode::Block(f) | TemplateNode::Inline(f)] = self.0.as_slice() {
+ f(style)
+ } else {
+ let mut builder = Builder::new(style, false);
+ builder.template(self);
+ builder.build_flow().pack()
+ }
}
/// Build the layout tree resulting from instantiating the template with the
diff --git a/src/eval/walk.rs b/src/eval/walk.rs
index 134f10c7..fe7f0e98 100644
--- a/src/eval/walk.rs
+++ b/src/eval/walk.rs
@@ -124,7 +124,7 @@ impl Walk for EnumNode {
fn walk_item(ctx: &mut EvalContext, label: EcoString, body: Template) {
ctx.template += Template::from_block(move |style| {
- let label = ParNode {
+ let label = Layout::pack(ParNode {
dir: style.par.dir,
leading: style.leading(),
children: vec![ParChild::Text(
@@ -132,13 +132,13 @@ fn walk_item(ctx: &mut EvalContext, label: EcoString, body: Template) {
style.aligns.inline,
Rc::clone(&style.text),
)],
- };
+ });
let spacing = style.text.size / 2.0;
GridNode {
tracks: Spec::new(vec![TrackSizing::Auto; 2], vec![]),
gutter: Spec::new(vec![TrackSizing::Linear(spacing.into())], vec![]),
- children: vec![label.pack(), body.to_flow(style).pack()],
+ children: vec![label, body.pack(style)],
}
});
}