summaryrefslogtreecommitdiff
path: root/src/layout
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-03-12 14:12:30 +0100
committerLaurenz <laurmaedje@gmail.com>2021-03-12 14:12:30 +0100
commit584a43277dbfbdba834a2681afe63d10598db3f9 (patch)
tree2a7b8d1f6b41fa39996c907d8d582b4c52448fcd /src/layout
parentffcb8cd97a7107bfd66805b1073c5ef3e0dd59a7 (diff)
Rename ChildAlign to LayoutAligns ✏
Diffstat (limited to 'src/layout')
-rw-r--r--src/layout/mod.rs4
-rw-r--r--src/layout/par.rs14
-rw-r--r--src/layout/stack.rs28
-rw-r--r--src/layout/text.rs10
4 files changed, 29 insertions, 27 deletions
diff --git a/src/layout/mod.rs b/src/layout/mod.rs
index 2e6a39ff..b5cfb1b0 100644
--- a/src/layout/mod.rs
+++ b/src/layout/mod.rs
@@ -159,9 +159,9 @@ pub enum Layouted {
/// Spacing that should be added to the parent.
Spacing(Length),
/// A layout that should be added to and aligned in the parent.
- Frame(Frame, ChildAlign),
+ Frame(Frame, LayoutAligns),
/// Multiple layouts.
- Frames(Vec<Frame>, ChildAlign),
+ Frames(Vec<Frame>, LayoutAligns),
}
impl Layouted {
diff --git a/src/layout/par.rs b/src/layout/par.rs
index 9a5d26dd..8e8f5aac 100644
--- a/src/layout/par.rs
+++ b/src/layout/par.rs
@@ -8,12 +8,12 @@ pub struct NodePar {
/// The children are placed in lines along the `cross` direction. The lines
/// are stacked along the `main` direction.
pub dirs: LayoutDirs,
+ /// How to align this paragraph in its parent.
+ pub aligns: LayoutAligns,
/// The spacing to insert after each line.
pub line_spacing: Length,
/// The nodes to be arranged in a paragraph.
pub children: Vec<Node>,
- /// How to align this paragraph in _its_ parent.
- pub align: ChildAlign,
}
impl Layout for NodePar {
@@ -22,15 +22,17 @@ impl Layout for NodePar {
for child in &self.children {
match child.layout(ctx, &layouter.areas) {
Layouted::Spacing(spacing) => layouter.push_spacing(spacing),
- Layouted::Frame(frame, align) => layouter.push_frame(frame, align.cross),
- Layouted::Frames(frames, align) => {
+ Layouted::Frame(frame, aligns) => {
+ layouter.push_frame(frame, aligns.cross)
+ }
+ Layouted::Frames(frames, aligns) => {
for frame in frames {
- layouter.push_frame(frame, align.cross);
+ layouter.push_frame(frame, aligns.cross);
}
}
}
}
- Layouted::Frames(layouter.finish(), self.align)
+ Layouted::Frames(layouter.finish(), self.aligns)
}
}
diff --git a/src/layout/stack.rs b/src/layout/stack.rs
index 73bd49c1..8748c5c7 100644
--- a/src/layout/stack.rs
+++ b/src/layout/stack.rs
@@ -8,8 +8,8 @@ pub struct NodeStack {
/// The children are stacked along the `main` direction. The `cross`
/// direction is required for aligning the children.
pub dirs: LayoutDirs,
- /// How to align this stack in _its_ parent.
- pub align: ChildAlign,
+ /// How to align this stack in its parent.
+ pub aligns: LayoutAligns,
/// The nodes to be stacked.
pub children: Vec<Node>,
}
@@ -20,15 +20,15 @@ impl Layout for NodeStack {
for child in &self.children {
match child.layout(ctx, &layouter.areas) {
Layouted::Spacing(spacing) => layouter.push_spacing(spacing),
- Layouted::Frame(frame, align) => layouter.push_frame(frame, align),
- Layouted::Frames(frames, align) => {
+ Layouted::Frame(frame, aligns) => layouter.push_frame(frame, aligns),
+ Layouted::Frames(frames, aligns) => {
for frame in frames {
- layouter.push_frame(frame, align);
+ layouter.push_frame(frame, aligns);
}
}
}
}
- Layouted::Frames(layouter.finish(), self.align)
+ Layouted::Frames(layouter.finish(), self.aligns)
}
}
@@ -43,7 +43,7 @@ struct StackLayouter {
dirs: LayoutDirs,
areas: Areas,
finished: Vec<Frame>,
- frames: Vec<(Length, Frame, ChildAlign)>,
+ frames: Vec<(Length, Frame, LayoutAligns)>,
used: Gen<Length>,
ruler: Align,
}
@@ -68,8 +68,8 @@ impl StackLayouter {
self.used.main += capped;
}
- fn push_frame(&mut self, frame: Frame, align: ChildAlign) {
- if self.ruler > align.main {
+ fn push_frame(&mut self, frame: Frame, aligns: LayoutAligns) {
+ if self.ruler > aligns.main {
self.finish_area();
}
@@ -83,12 +83,12 @@ impl StackLayouter {
}
let size = frame.size.switch(self.dirs);
- self.frames.push((self.used.main, frame, align));
+ self.frames.push((self.used.main, frame, aligns));
*self.areas.current.get_mut(self.main) -= size.main;
self.used.main += size.main;
self.used.cross = self.used.cross.max(size.cross);
- self.ruler = align.main;
+ self.ruler = aligns.main;
}
fn finish_area(&mut self) {
@@ -103,11 +103,11 @@ impl StackLayouter {
let mut output = Frame::new(full_size.switch(self.dirs).to_size());
- for (before, frame, align) in std::mem::take(&mut self.frames) {
+ for (before, frame, aligns) in std::mem::take(&mut self.frames) {
let child_size = frame.size.switch(self.dirs);
// Align along the main axis.
- let main = align.main.resolve(if self.dirs.main.is_positive() {
+ let main = aligns.main.resolve(if self.dirs.main.is_positive() {
let after_with_self = self.used.main - before;
before .. full_size.main - after_with_self
} else {
@@ -117,7 +117,7 @@ impl StackLayouter {
});
// Align along the cross axis.
- let cross = align.cross.resolve(if self.dirs.cross.is_positive() {
+ let cross = aligns.cross.resolve(if self.dirs.cross.is_positive() {
Length::ZERO .. full_size.cross - child_size.cross
} else {
full_size.cross - child_size.cross .. Length::ZERO
diff --git a/src/layout/text.rs b/src/layout/text.rs
index ee85ee17..256a6e6d 100644
--- a/src/layout/text.rs
+++ b/src/layout/text.rs
@@ -9,12 +9,12 @@ use crate::shaping;
/// A text node.
#[derive(Clone, PartialEq)]
pub struct NodeText {
- /// The text.
- pub text: String,
- /// How to align this text node in its parent.
- pub align: ChildAlign,
/// The text direction.
pub dir: Dir,
+ /// How to align this text node in its parent.
+ pub aligns: LayoutAligns,
+ /// The text.
+ pub text: String,
/// The font size.
pub font_size: Length,
/// The families used for font fallback.
@@ -34,7 +34,7 @@ impl Layout for NodeText {
&self.families,
self.variant,
),
- self.align,
+ self.aligns,
)
}
}