summaryrefslogtreecommitdiff
path: root/src
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
parentffcb8cd97a7107bfd66805b1073c5ef3e0dd59a7 (diff)
Rename ChildAlign to LayoutAligns ✏
Diffstat (limited to 'src')
-rw-r--r--src/exec/context.rs22
-rw-r--r--src/exec/mod.rs2
-rw-r--r--src/exec/state.rs14
-rw-r--r--src/geom/align.rs4
-rw-r--r--src/geom/dir.rs2
-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
-rw-r--r--src/library/align.rs14
-rw-r--r--src/library/image.rs8
11 files changed, 62 insertions, 60 deletions
diff --git a/src/exec/context.rs b/src/exec/context.rs
index 4d2047a6..3b0fd897 100644
--- a/src/exec/context.rs
+++ b/src/exec/context.rs
@@ -5,7 +5,7 @@ use fontdock::FontStyle;
use super::*;
use crate::diag::{Diag, DiagSet};
-use crate::geom::{ChildAlign, Dir, Gen, LayoutDirs, Length, Linear, Sides, Size};
+use crate::geom::{Dir, Gen, LayoutAligns, LayoutDirs, Length, Linear, Sides, Size};
use crate::layout::{
Node, NodePad, NodePages, NodePar, NodeSpacing, NodeStack, NodeText, Tree,
};
@@ -108,7 +108,7 @@ impl<'a> ExecContext<'a> {
/// Execute a template and return the result as a stack node.
pub fn exec(&mut self, template: &ValueTemplate) -> Node {
let dirs = self.state.dirs;
- let align = self.state.align;
+ let aligns = self.state.aligns;
self.start_group(ContentGroup);
self.start_par_group();
@@ -116,7 +116,7 @@ impl<'a> ExecContext<'a> {
self.end_par_group();
let children = self.end_group::<ContentGroup>().1;
- NodeStack { dirs, align, children }.into()
+ NodeStack { dirs, aligns, children }.into()
}
/// Start a page group based on the active page state.
@@ -130,7 +130,7 @@ impl<'a> ExecContext<'a> {
size: self.state.page.size,
padding: self.state.page.margins(),
dirs: self.state.dirs,
- align: self.state.align,
+ aligns: self.state.aligns,
softness,
});
self.start_par_group();
@@ -156,7 +156,7 @@ impl<'a> ExecContext<'a> {
padding: group.padding,
child: NodeStack {
dirs: group.dirs,
- align: group.align,
+ aligns: group.aligns,
children,
}
.into(),
@@ -172,7 +172,7 @@ impl<'a> ExecContext<'a> {
let em = self.state.font.font_size();
self.start_group(ParGroup {
dirs: self.state.dirs,
- align: self.state.align,
+ aligns: self.state.aligns,
line_spacing: self.state.par.line_spacing.resolve(em),
});
}
@@ -183,7 +183,7 @@ impl<'a> ExecContext<'a> {
if !children.is_empty() {
self.push(NodePar {
dirs: group.dirs,
- align: group.align,
+ aligns: group.aligns,
line_spacing: group.line_spacing,
children,
});
@@ -275,7 +275,7 @@ impl<'a> ExecContext<'a> {
NodeText {
text,
- align: self.state.align,
+ aligns: self.state.aligns,
dir: self.state.dirs.cross,
font_size: self.state.font.font_size(),
families: Rc::clone(&self.state.font.families),
@@ -296,10 +296,10 @@ pub enum Softness {
/// A group for a page run.
#[derive(Debug)]
struct PageGroup {
+ dirs: LayoutDirs,
+ aligns: LayoutAligns,
size: Size,
padding: Sides<Linear>,
- dirs: LayoutDirs,
- align: ChildAlign,
softness: Softness,
}
@@ -311,6 +311,6 @@ struct ContentGroup;
#[derive(Debug)]
struct ParGroup {
dirs: LayoutDirs,
- align: ChildAlign,
+ aligns: LayoutAligns,
line_spacing: Length,
}
diff --git a/src/exec/mod.rs b/src/exec/mod.rs
index 79ad81e7..58b5cdc0 100644
--- a/src/exec/mod.rs
+++ b/src/exec/mod.rs
@@ -126,7 +126,7 @@ impl Exec for NodeRaw {
height: None,
child: NodeStack {
dirs: ctx.state.dirs,
- align: ctx.state.align,
+ aligns: ctx.state.aligns,
children,
}
.into(),
diff --git a/src/exec/state.rs b/src/exec/state.rs
index 3293662a..65f26439 100644
--- a/src/exec/state.rs
+++ b/src/exec/state.rs
@@ -3,33 +3,33 @@ use std::rc::Rc;
use fontdock::{fallback, FallbackTree, FontStretch, FontStyle, FontVariant, FontWeight};
use crate::geom::{
- Align, ChildAlign, Dir, LayoutDirs, Length, Linear, Relative, Sides, Size,
+ Align, Dir, LayoutAligns, LayoutDirs, Length, Linear, Relative, Sides, Size,
};
use crate::paper::{Paper, PaperClass, PAPER_A4};
/// The evaluation state.
#[derive(Debug, Clone, PartialEq)]
pub struct State {
+ /// The current directions along which layouts are placed in their parents.
+ pub dirs: LayoutDirs,
+ /// The current alignments of layouts in their parents.
+ pub aligns: LayoutAligns,
/// The current page settings.
pub page: PageState,
/// The current paragraph settings.
pub par: ParState,
/// The current font settings.
pub font: FontState,
- /// The current layouting directions.
- pub dirs: LayoutDirs,
- /// The current alignments of an item in its parent.
- pub align: ChildAlign,
}
impl Default for State {
fn default() -> Self {
Self {
+ dirs: LayoutDirs::new(Dir::TTB, Dir::LTR),
+ aligns: LayoutAligns::new(Align::Start, Align::Start),
page: PageState::default(),
par: ParState::default(),
font: FontState::default(),
- dirs: LayoutDirs::new(Dir::TTB, Dir::LTR),
- align: ChildAlign::new(Align::Start, Align::Start),
}
}
}
diff --git a/src/geom/align.rs b/src/geom/align.rs
index 8f02a4ea..e13da378 100644
--- a/src/geom/align.rs
+++ b/src/geom/align.rs
@@ -1,7 +1,7 @@
use super::*;
-/// The alignment of a child in a container.
-pub type ChildAlign = Gen<Align>;
+/// The alignments of a layout in its parent.
+pub type LayoutAligns = Gen<Align>;
/// Where to align something along a directed axis.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)]
diff --git a/src/geom/dir.rs b/src/geom/dir.rs
index c5eaa3a6..3eddd7d3 100644
--- a/src/geom/dir.rs
+++ b/src/geom/dir.rs
@@ -1,6 +1,6 @@
use super::*;
-/// The directions along which nodes are layouted.
+/// The directions along which layouts are placed in their parent.
pub type LayoutDirs = Gen<Dir>;
/// The four directions into which content can be laid out.
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,
)
}
}
diff --git a/src/library/align.rs b/src/library/align.rs
index d16e697d..07566f2d 100644
--- a/src/library/align.rs
+++ b/src/library/align.rs
@@ -54,7 +54,7 @@ pub fn align(ctx: &mut EvalContext, args: &mut ValueArgs) -> Value {
} else if had.get(gen_axis) {
ctx.diag(error!(span, "duplicate alignment for {} axis", axis));
} else {
- *ctx.state.align.get_mut(gen_axis) = gen_align;
+ *ctx.state.aligns.get_mut(gen_axis) = gen_align;
*had.get_mut(gen_axis) = true;
}
} else {
@@ -67,8 +67,8 @@ pub fn align(ctx: &mut EvalContext, args: &mut ValueArgs) -> Value {
} else if had_center {
// Both this and the previous one are unspecified `center`
// alignments. Both axes should be centered.
- ctx.state.align.main = Align::Center;
- ctx.state.align.cross = Align::Center;
+ ctx.state.aligns.main = Align::Center;
+ ctx.state.aligns.cross = Align::Center;
had = Gen::uniform(true);
} else {
had_center = true;
@@ -79,10 +79,10 @@ pub fn align(ctx: &mut EvalContext, args: &mut ValueArgs) -> Value {
// `center` alignment.
if had_center && (had.main || had.cross) {
if had.main {
- ctx.state.align.cross = Align::Center;
+ ctx.state.aligns.cross = Align::Center;
had.cross = true;
} else {
- ctx.state.align.main = Align::Center;
+ ctx.state.aligns.main = Align::Center;
had.main = true;
}
had_center = false;
@@ -92,10 +92,10 @@ pub fn align(ctx: &mut EvalContext, args: &mut ValueArgs) -> Value {
// If `had_center` wasn't flushed by now, it's the only argument and then we
// default to applying it to the cross axis.
if had_center {
- ctx.state.align.cross = Align::Center;
+ ctx.state.aligns.cross = Align::Center;
}
- if ctx.state.align.main != snapshot.align.main {
+ if ctx.state.aligns.main != snapshot.aligns.main {
ctx.end_par_group();
ctx.start_par_group();
}
diff --git a/src/library/image.rs b/src/library/image.rs
index 06908ce8..d9c0a0a7 100644
--- a/src/library/image.rs
+++ b/src/library/image.rs
@@ -25,7 +25,7 @@ pub fn image(ctx: &mut EvalContext, args: &mut ValueArgs) -> Value {
dimensions,
width,
height,
- align: ctx.state.align,
+ aligns: ctx.state.aligns,
});
} else {
ctx.diag(error!(path.span, "failed to load image"));
@@ -37,6 +37,8 @@ pub fn image(ctx: &mut EvalContext, args: &mut ValueArgs) -> Value {
/// An image node.
#[derive(Debug, Clone, PartialEq)]
struct NodeImage {
+ /// How to align this image node in its parent.
+ aligns: LayoutAligns,
/// The resource id of the image file.
res: ResourceId,
/// The pixel dimensions of the image.
@@ -45,8 +47,6 @@ struct NodeImage {
width: Option<Linear>,
/// The fixed height, if any.
height: Option<Linear>,
- /// How to align this image node in its parent.
- align: ChildAlign,
}
impl Layout for NodeImage {
@@ -81,7 +81,7 @@ impl Layout for NodeImage {
let mut frame = Frame::new(size);
frame.push(Point::ZERO, Element::Image(Image { res: self.res, size }));
- Layouted::Frame(frame, self.align)
+ Layouted::Frame(frame, self.aligns)
}
}