summaryrefslogtreecommitdiff
path: root/src/layout/par.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-03-11 10:48:29 +0100
committerLaurenz <laurmaedje@gmail.com>2021-03-11 10:48:29 +0100
commitc1b1dbcc0925ba1730fabbfbca3c8b99831c5561 (patch)
tree6e4cb30753729c699bd899a7f2ec352e276beee8 /src/layout/par.rs
parent4e5f85aa4ac0d6b51323bb2a6e1fbd3f4f46babb (diff)
Better expansion behaviour 🐪
This makes expansion behaviour inheritable by placing it into the area and passing it down during layouting instead of computing some approximation of what we want during execution.
Diffstat (limited to 'src/layout/par.rs')
-rw-r--r--src/layout/par.rs21
1 files changed, 9 insertions, 12 deletions
diff --git a/src/layout/par.rs b/src/layout/par.rs
index 45494dec..9a5d26dd 100644
--- a/src/layout/par.rs
+++ b/src/layout/par.rs
@@ -8,8 +8,6 @@ pub struct NodePar {
/// The children are placed in lines along the `cross` direction. The lines
/// are stacked along the `main` direction.
pub dirs: LayoutDirs,
- /// Whether to expand the cross axis to fill the area or to fit the content.
- pub cross_expansion: Expansion,
/// The spacing to insert after each line.
pub line_spacing: Length,
/// The nodes to be arranged in a paragraph.
@@ -42,11 +40,11 @@ impl From<NodePar> for NodeAny {
}
}
-struct ParLayouter<'a> {
- par: &'a NodePar,
+struct ParLayouter {
main: SpecAxis,
cross: SpecAxis,
dirs: LayoutDirs,
+ line_spacing: Length,
areas: Areas,
finished: Vec<Frame>,
lines: Vec<(Length, Frame, Align)>,
@@ -56,13 +54,13 @@ struct ParLayouter<'a> {
line_ruler: Align,
}
-impl<'a> ParLayouter<'a> {
- fn new(par: &'a NodePar, areas: Areas) -> Self {
+impl ParLayouter {
+ fn new(par: &NodePar, areas: Areas) -> Self {
Self {
- par,
main: par.dirs.main.axis(),
cross: par.dirs.cross.axis(),
dirs: par.dirs,
+ line_spacing: par.line_spacing,
areas,
finished: vec![],
lines: vec![],
@@ -134,13 +132,12 @@ impl<'a> ParLayouter<'a> {
}
fn finish_line(&mut self) {
+ let expand = self.areas.expand.switch(self.dirs);
let full_size = {
let full = self.areas.full.switch(self.dirs);
Gen::new(
self.line_size.main,
- self.par
- .cross_expansion
- .resolve(self.line_size.cross.min(full.cross), full.cross),
+ expand.cross.resolve(self.line_size.cross.min(full.cross), full.cross),
)
};
@@ -165,8 +162,8 @@ impl<'a> ParLayouter<'a> {
// Add line spacing, but only between lines.
if !self.lines.is_empty() {
- self.lines_size.main += self.par.line_spacing;
- *self.areas.current.get_mut(self.main) -= self.par.line_spacing;
+ self.lines_size.main += self.line_spacing;
+ *self.areas.current.get_mut(self.main) -= self.line_spacing;
}
// Update metrics of the whole paragraph.