summaryrefslogtreecommitdiff
path: root/src/layout/par.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-01-03 00:12:09 +0100
committerLaurenz <laurmaedje@gmail.com>2021-01-03 00:12:09 +0100
commitaae67bd572ad86f4c57e364daa51a9dc883b8913 (patch)
tree0aba021e0748ebad2197ea390385ec5f93ccbc6e /src/layout/par.rs
parent1c40dc42e7bc7b799b77f06d25414aca59a044ba (diff)
Move and rename many things 🚛
Diffstat (limited to 'src/layout/par.rs')
-rw-r--r--src/layout/par.rs84
1 files changed, 41 insertions, 43 deletions
diff --git a/src/layout/par.rs b/src/layout/par.rs
index 723f27cb..3a8e3969 100644
--- a/src/layout/par.rs
+++ b/src/layout/par.rs
@@ -2,69 +2,67 @@ use super::*;
/// A node that arranges its children into a paragraph.
#[derive(Debug, Clone, PartialEq)]
-pub struct Par {
+pub struct NodePar {
/// The `main` and `cross` directions of this paragraph.
///
/// The children are placed in lines along the `cross` direction. The lines
/// are stacked along the `main` direction.
- pub flow: Flow,
+ 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.
- pub children: Vec<LayoutNode>,
+ pub children: Vec<Node>,
/// How to align this paragraph in _its_ parent.
- pub align: BoxAlign,
+ pub align: ChildAlign,
}
-impl Layout for Par {
+impl Layout for NodePar {
fn layout(&self, ctx: &mut LayoutContext, areas: &Areas) -> Layouted {
let mut layouter = ParLayouter::new(self, areas.clone());
for child in &self.children {
match child.layout(ctx, &layouter.areas) {
Layouted::Spacing(spacing) => layouter.push_spacing(spacing),
- Layouted::Layout(layout, align) => {
- layouter.push_layout(layout, align.cross)
- }
- Layouted::Layouts(layouts, align) => {
- for layout in layouts {
- layouter.push_layout(layout, align.cross);
+ Layouted::Frame(frame, align) => layouter.push_frame(frame, align.cross),
+ Layouted::Frames(frames, align) => {
+ for frame in frames {
+ layouter.push_frame(frame, align.cross);
}
}
}
}
- Layouted::Layouts(layouter.finish(), self.align)
+ Layouted::Frames(layouter.finish(), self.align)
}
}
-impl From<Par> for LayoutNode {
- fn from(par: Par) -> Self {
- Self::dynamic(par)
+impl From<NodePar> for Node {
+ fn from(par: NodePar) -> Self {
+ Self::any(par)
}
}
struct ParLayouter<'a> {
- par: &'a Par,
+ par: &'a NodePar,
main: SpecAxis,
cross: SpecAxis,
- flow: Flow,
+ dirs: LayoutDirs,
areas: Areas,
- finished: Vec<BoxLayout>,
- lines: Vec<(Length, BoxLayout, Align)>,
+ finished: Vec<Frame>,
+ lines: Vec<(Length, Frame, Align)>,
lines_size: Gen<Length>,
- run: Vec<(Length, BoxLayout, Align)>,
+ run: Vec<(Length, Frame, Align)>,
run_size: Gen<Length>,
run_ruler: Align,
}
impl<'a> ParLayouter<'a> {
- fn new(par: &'a Par, areas: Areas) -> Self {
+ fn new(par: &'a NodePar, areas: Areas) -> Self {
Self {
par,
- main: par.flow.main.axis(),
- cross: par.flow.cross.axis(),
- flow: par.flow,
+ main: par.dirs.main.axis(),
+ cross: par.dirs.cross.axis(),
+ dirs: par.dirs,
areas,
finished: vec![],
lines: vec![],
@@ -80,7 +78,7 @@ impl<'a> ParLayouter<'a> {
self.run_size.cross = (self.run_size.cross + amount).min(cross_max);
}
- fn push_layout(&mut self, layout: BoxLayout, align: Align) {
+ fn push_frame(&mut self, frame: Frame, align: Align) {
if self.run_ruler > align {
self.finish_run();
}
@@ -88,16 +86,16 @@ impl<'a> ParLayouter<'a> {
let fits = {
let mut usable = self.areas.current.rem;
*usable.get_mut(self.cross) -= self.run_size.cross;
- usable.fits(layout.size)
+ usable.fits(frame.size)
};
if !fits {
self.finish_run();
- while !self.areas.current.rem.fits(layout.size) {
+ while !self.areas.current.rem.fits(frame.size) {
if self.areas.in_full_last() {
// TODO: Diagnose once the necessary spans exist.
- let _ = warning!("cannot fit box into any area");
+ let _ = warning!("cannot fit frame into any area");
break;
} else {
self.finish_area();
@@ -105,8 +103,8 @@ impl<'a> ParLayouter<'a> {
}
}
- let size = layout.size.switch(self.flow);
- self.run.push((self.run_size.cross, layout, align));
+ let size = frame.size.switch(self.dirs);
+ self.run.push((self.run_size.cross, frame, align));
self.run_size.cross += size.cross;
self.run_size.main = self.run_size.main.max(size.main);
@@ -119,13 +117,13 @@ impl<'a> ParLayouter<'a> {
Expansion::Fit => self.run_size.cross,
});
- let mut output = BoxLayout::new(full_size.switch(self.flow).to_size());
+ let mut output = Frame::new(full_size.switch(self.dirs).to_size());
- for (before, layout, align) in std::mem::take(&mut self.run) {
- let child_cross_size = layout.size.get(self.cross);
+ for (before, frame, align) in std::mem::take(&mut self.run) {
+ let child_cross_size = frame.size.get(self.cross);
// Position along the cross axis.
- let cross = align.resolve(if self.flow.cross.is_positive() {
+ let cross = align.resolve(if self.dirs.cross.is_positive() {
let after_with_self = self.run_size.cross - before;
before .. full_size.cross - after_with_self
} else {
@@ -134,8 +132,8 @@ impl<'a> ParLayouter<'a> {
full_size.cross - before_with_self .. after
});
- let pos = Gen::new(Length::ZERO, cross).switch(self.flow).to_point();
- output.push_layout(pos, layout);
+ let pos = Gen::new(Length::ZERO, cross).switch(self.dirs).to_point();
+ output.push_frame(pos, frame);
}
self.lines.push((self.lines_size.main, output, self.run_ruler));
@@ -151,27 +149,27 @@ impl<'a> ParLayouter<'a> {
fn finish_area(&mut self) {
let size = self.lines_size;
- let mut output = BoxLayout::new(size.switch(self.flow).to_size());
+ let mut output = Frame::new(size.switch(self.dirs).to_size());
for (before, run, cross_align) in std::mem::take(&mut self.lines) {
- let child_size = run.size.switch(self.flow);
+ let child_size = run.size.switch(self.dirs);
// Position along the main axis.
- let main = if self.flow.main.is_positive() {
+ let main = if self.dirs.main.is_positive() {
before
} else {
size.main - (before + child_size.main)
};
// Align along the cross axis.
- let cross = cross_align.resolve(if self.flow.cross.is_positive() {
+ let cross = cross_align.resolve(if self.dirs.cross.is_positive() {
Length::ZERO .. size.cross - child_size.cross
} else {
size.cross - child_size.cross .. Length::ZERO
});
- let pos = Gen::new(main, cross).switch(self.flow).to_point();
- output.push_layout(pos, run);
+ let pos = Gen::new(main, cross).switch(self.dirs).to_point();
+ output.push_frame(pos, run);
}
self.finished.push(output);
@@ -180,7 +178,7 @@ impl<'a> ParLayouter<'a> {
self.lines_size = Gen::ZERO;
}
- fn finish(mut self) -> Vec<BoxLayout> {
+ fn finish(mut self) -> Vec<Frame> {
self.finish_run();
self.finish_area();
self.finished