diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-10-16 11:39:26 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-10-23 20:22:47 +0200 |
| commit | 6690bc23545bfe7275ad92de9e6bd11b7345caf4 (patch) | |
| tree | e116a23f2f04b3053160aae09088830fdb21460f /src/eval | |
| parent | 1e74f7c407e42174b631cb7477f3c88252da7e25 (diff) | |
Revise block node contract
Frames produced by block nodes are now always treated as exactly one per
given region and a frame must not be larger than its respective region.
Any overflow must be handled internally. This means that stack and grid
don't need to search for fitting regions anymore, since the child has
already does that for them. This commit further moves stack spacing into
a new `SpacingNode`.
Diffstat (limited to 'src/eval')
| -rw-r--r-- | src/eval/template.rs | 14 | ||||
| -rw-r--r-- | src/eval/walk.rs | 8 |
2 files changed, 10 insertions, 12 deletions
diff --git a/src/eval/template.rs b/src/eval/template.rs index 59fe293a..63916339 100644 --- a/src/eval/template.rs +++ b/src/eval/template.rs @@ -6,7 +6,7 @@ use std::rc::Rc; use super::Str; use crate::diag::StrResult; -use crate::geom::{Align, Dir, GenAxis, Length, Linear, Sides, Size}; +use crate::geom::{Align, Dir, GenAxis, Length, Linear, Sides, Size, SpecAxis}; use crate::layout::{ Decoration, LayoutNode, LayoutTree, PadNode, PageRun, ParChild, ParNode, StackChild, StackNode, @@ -309,7 +309,7 @@ impl Builder { fn parbreak(&mut self) { let amount = self.style.par_spacing(); self.stack.finish_par(&self.style); - self.stack.push_soft(StackChild::Spacing(amount.into())); + self.stack.push_soft(StackChild::spacing(amount, SpecAxis::Vertical)); } /// Apply a forced page break. @@ -335,7 +335,7 @@ impl Builder { /// Push a block node into the active stack, finishing the active paragraph. fn block(&mut self, node: impl Into<LayoutNode>) { self.parbreak(); - self.stack.push(StackChild::Any(node.into(), self.style.aligns.block)); + self.stack.push(StackChild::new(node, self.style.aligns.block)); self.parbreak(); } @@ -344,7 +344,7 @@ impl Builder { match axis { GenAxis::Block => { self.stack.finish_par(&self.style); - self.stack.push_hard(StackChild::Spacing(amount)); + self.stack.push_hard(StackChild::spacing(amount, SpecAxis::Vertical)); } GenAxis::Inline => { self.stack.par.push_hard(ParChild::Spacing(amount)); @@ -508,10 +508,8 @@ impl ParBuilder { fn build(self) -> Option<StackChild> { let Self { align, dir, line_spacing, children, .. } = self; - (!children.is_empty()).then(|| { - let node = ParNode { dir, line_spacing, children }; - StackChild::Any(node.into(), align) - }) + (!children.is_empty()) + .then(|| StackChild::new(ParNode { dir, line_spacing, children }, align)) } } diff --git a/src/eval/walk.rs b/src/eval/walk.rs index b76300ec..24284e4e 100644 --- a/src/eval/walk.rs +++ b/src/eval/walk.rs @@ -2,7 +2,7 @@ use std::rc::Rc; use super::{Eval, EvalContext, Str, Template, Value}; use crate::diag::TypResult; -use crate::geom::Align; +use crate::geom::{Align, SpecAxis}; use crate::layout::{ParChild, ParNode, StackChild, StackNode}; use crate::syntax::*; use crate::util::BoolExt; @@ -119,9 +119,9 @@ fn walk_item(ctx: &mut EvalContext, label: Str, body: Template) { StackNode { dir: style.dir, children: vec![ - StackChild::Any(label.into(), Align::Start), - StackChild::Spacing((style.text.size / 2.0).into()), - StackChild::Any(body.to_stack(&style).into(), Align::Start), + StackChild::new(label, Align::Start), + StackChild::spacing(style.text.size / 2.0, SpecAxis::Horizontal), + StackChild::new(body.to_stack(&style), Align::Start), ], } }); |
