summaryrefslogtreecommitdiff
path: root/src/layout
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2020-10-13 13:51:58 +0200
committerLaurenz <laurmaedje@gmail.com>2020-10-13 13:51:58 +0200
commit91e512069396f1de616ec2b0fe0cd31a76e7f2e9 (patch)
tree204ef6032dd4d22b38236d4d85fc95c97e7a9f37 /src/layout
parent8680fcd4903b451909a5932e8b948a68c9aacb16 (diff)
BoxAlign and Flow aliases ✏
Diffstat (limited to 'src/layout')
-rw-r--r--src/layout/mod.rs4
-rw-r--r--src/layout/par.rs42
-rw-r--r--src/layout/stack.rs46
-rw-r--r--src/layout/text.rs12
4 files changed, 52 insertions, 52 deletions
diff --git a/src/layout/mod.rs b/src/layout/mod.rs
index 362e5a7f..4dd6184f 100644
--- a/src/layout/mod.rs
+++ b/src/layout/mod.rs
@@ -128,9 +128,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.
- Layout(BoxLayout, Gen<Align>),
+ Layout(BoxLayout, BoxAlign),
/// Multiple layouts.
- Layouts(Vec<BoxLayout>, Gen<Align>),
+ Layouts(Vec<BoxLayout>, BoxAlign),
}
impl Layouted {
diff --git a/src/layout/par.rs b/src/layout/par.rs
index bd38442d..723f27cb 100644
--- a/src/layout/par.rs
+++ b/src/layout/par.rs
@@ -7,15 +7,15 @@ pub struct Par {
///
/// The children are placed in lines along the `cross` direction. The lines
/// are stacked along the `main` direction.
- pub dirs: Gen<Dir>,
- /// How to align this paragraph in _its_ parent.
- pub aligns: Gen<Align>,
+ pub flow: Flow,
/// 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>,
+ /// How to align this paragraph in _its_ parent.
+ pub align: BoxAlign,
}
impl Layout for Par {
@@ -24,17 +24,17 @@ impl Layout for Par {
for child in &self.children {
match child.layout(ctx, &layouter.areas) {
Layouted::Spacing(spacing) => layouter.push_spacing(spacing),
- Layouted::Layout(layout, aligns) => {
- layouter.push_layout(layout, aligns.cross)
+ Layouted::Layout(layout, align) => {
+ layouter.push_layout(layout, align.cross)
}
- Layouted::Layouts(layouts, aligns) => {
+ Layouted::Layouts(layouts, align) => {
for layout in layouts {
- layouter.push_layout(layout, aligns.cross);
+ layouter.push_layout(layout, align.cross);
}
}
}
}
- Layouted::Layouts(layouter.finish(), self.aligns)
+ Layouted::Layouts(layouter.finish(), self.align)
}
}
@@ -48,7 +48,7 @@ struct ParLayouter<'a> {
par: &'a Par,
main: SpecAxis,
cross: SpecAxis,
- dirs: Gen<Dir>,
+ flow: Flow,
areas: Areas,
finished: Vec<BoxLayout>,
lines: Vec<(Length, BoxLayout, Align)>,
@@ -62,9 +62,9 @@ impl<'a> ParLayouter<'a> {
fn new(par: &'a Par, areas: Areas) -> Self {
Self {
par,
- main: par.dirs.main.axis(),
- cross: par.dirs.cross.axis(),
- dirs: par.dirs,
+ main: par.flow.main.axis(),
+ cross: par.flow.cross.axis(),
+ flow: par.flow,
areas,
finished: vec![],
lines: vec![],
@@ -105,7 +105,7 @@ impl<'a> ParLayouter<'a> {
}
}
- let size = layout.size.switch(self.dirs);
+ let size = layout.size.switch(self.flow);
self.run.push((self.run_size.cross, layout, align));
self.run_size.cross += size.cross;
@@ -119,13 +119,13 @@ impl<'a> ParLayouter<'a> {
Expansion::Fit => self.run_size.cross,
});
- let mut output = BoxLayout::new(full_size.switch(self.dirs).to_size());
+ let mut output = BoxLayout::new(full_size.switch(self.flow).to_size());
for (before, layout, align) in std::mem::take(&mut self.run) {
let child_cross_size = layout.size.get(self.cross);
// Position along the cross axis.
- let cross = align.resolve(if self.dirs.cross.is_positive() {
+ let cross = align.resolve(if self.flow.cross.is_positive() {
let after_with_self = self.run_size.cross - before;
before .. full_size.cross - after_with_self
} else {
@@ -134,7 +134,7 @@ impl<'a> ParLayouter<'a> {
full_size.cross - before_with_self .. after
});
- let pos = Gen::new(Length::ZERO, cross).switch(self.dirs).to_point();
+ let pos = Gen::new(Length::ZERO, cross).switch(self.flow).to_point();
output.push_layout(pos, layout);
}
@@ -151,26 +151,26 @@ impl<'a> ParLayouter<'a> {
fn finish_area(&mut self) {
let size = self.lines_size;
- let mut output = BoxLayout::new(size.switch(self.dirs).to_size());
+ let mut output = BoxLayout::new(size.switch(self.flow).to_size());
for (before, run, cross_align) in std::mem::take(&mut self.lines) {
- let child_size = run.size.switch(self.dirs);
+ let child_size = run.size.switch(self.flow);
// Position along the main axis.
- let main = if self.dirs.main.is_positive() {
+ let main = if self.flow.main.is_positive() {
before
} else {
size.main - (before + child_size.main)
};
// Align along the cross axis.
- let cross = cross_align.resolve(if self.dirs.cross.is_positive() {
+ let cross = cross_align.resolve(if self.flow.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.dirs).to_point();
+ let pos = Gen::new(main, cross).switch(self.flow).to_point();
output.push_layout(pos, run);
}
diff --git a/src/layout/stack.rs b/src/layout/stack.rs
index 7e1bb2c5..9d2540e9 100644
--- a/src/layout/stack.rs
+++ b/src/layout/stack.rs
@@ -1,15 +1,15 @@
use super::*;
-/// A node that stacks and aligns its children.
+/// A node that stacks and align its children.
#[derive(Debug, Clone, PartialEq)]
pub struct Stack {
/// The `main` and `cross` directions of this stack.
///
/// The children are stacked along the `main` direction. The `cross`
/// direction is required for aligning the children.
- pub dirs: Gen<Dir>,
+ pub flow: Flow,
/// How to align this stack in _its_ parent.
- pub aligns: Gen<Align>,
+ pub align: BoxAlign,
/// Whether to expand the axes to fill the area or to fit the content.
pub expansion: Gen<Expansion>,
/// The nodes to be stacked.
@@ -22,15 +22,15 @@ impl Layout for Stack {
for child in &self.children {
match child.layout(ctx, &layouter.areas) {
Layouted::Spacing(spacing) => layouter.push_spacing(spacing),
- Layouted::Layout(layout, aligns) => layouter.push_layout(layout, aligns),
- Layouted::Layouts(layouts, aligns) => {
+ Layouted::Layout(layout, align) => layouter.push_layout(layout, align),
+ Layouted::Layouts(layouts, align) => {
for layout in layouts {
- layouter.push_layout(layout, aligns);
+ layouter.push_layout(layout, align);
}
}
}
}
- Layouted::Layouts(layouter.finish(), self.aligns)
+ Layouted::Layouts(layouter.finish(), self.align)
}
}
@@ -43,10 +43,10 @@ impl From<Stack> for LayoutNode {
struct StackLayouter<'a> {
stack: &'a Stack,
main: SpecAxis,
- dirs: Gen<Dir>,
+ flow: Flow,
areas: Areas,
finished: Vec<BoxLayout>,
- layouts: Vec<(Length, BoxLayout, Gen<Align>)>,
+ layouts: Vec<(Length, BoxLayout, BoxAlign)>,
used: Gen<Length>,
ruler: Align,
}
@@ -55,8 +55,8 @@ impl<'a> StackLayouter<'a> {
fn new(stack: &'a Stack, areas: Areas) -> Self {
Self {
stack,
- main: stack.dirs.main.axis(),
- dirs: stack.dirs,
+ main: stack.flow.main.axis(),
+ flow: stack.flow,
areas,
finished: vec![],
layouts: vec![],
@@ -72,8 +72,8 @@ impl<'a> StackLayouter<'a> {
self.used.main += capped;
}
- fn push_layout(&mut self, layout: BoxLayout, aligns: Gen<Align>) {
- if self.ruler > aligns.main {
+ fn push_layout(&mut self, layout: BoxLayout, align: BoxAlign) {
+ if self.ruler > align.main {
self.finish_area();
}
@@ -87,18 +87,18 @@ impl<'a> StackLayouter<'a> {
}
}
- let size = layout.size.switch(self.dirs);
- self.layouts.push((self.used.main, layout, aligns));
+ let size = layout.size.switch(self.flow);
+ self.layouts.push((self.used.main, layout, align));
*self.areas.current.rem.get_mut(self.main) -= size.main;
self.used.main += size.main;
self.used.cross = self.used.cross.max(size.cross);
- self.ruler = aligns.main;
+ self.ruler = align.main;
}
fn finish_area(&mut self) {
let full_size = {
- let full = self.areas.current.full.switch(self.dirs);
+ let full = self.areas.current.full.switch(self.flow);
Gen::new(
match self.stack.expansion.main {
Expansion::Fill => full.main,
@@ -111,13 +111,13 @@ impl<'a> StackLayouter<'a> {
)
};
- let mut output = BoxLayout::new(full_size.switch(self.dirs).to_size());
+ let mut output = BoxLayout::new(full_size.switch(self.flow).to_size());
- for (before, layout, aligns) in std::mem::take(&mut self.layouts) {
- let child_size = layout.size.switch(self.dirs);
+ for (before, layout, align) in std::mem::take(&mut self.layouts) {
+ let child_size = layout.size.switch(self.flow);
// Align along the main axis.
- let main = aligns.main.resolve(if self.dirs.main.is_positive() {
+ let main = align.main.resolve(if self.flow.main.is_positive() {
let after_with_self = self.used.main - before;
before .. full_size.main - after_with_self
} else {
@@ -127,13 +127,13 @@ impl<'a> StackLayouter<'a> {
});
// Align along the cross axis.
- let cross = aligns.cross.resolve(if self.dirs.cross.is_positive() {
+ let cross = align.cross.resolve(if self.flow.cross.is_positive() {
Length::ZERO .. full_size.cross - child_size.cross
} else {
full_size.cross - child_size.cross .. Length::ZERO
});
- let pos = Gen::new(main, cross).switch(self.dirs).to_point();
+ let pos = Gen::new(main, cross).switch(self.flow).to_point();
output.push_layout(pos, layout);
}
diff --git a/src/layout/text.rs b/src/layout/text.rs
index 0ded4f9d..fc319fa5 100644
--- a/src/layout/text.rs
+++ b/src/layout/text.rs
@@ -11,16 +11,16 @@ use crate::shaping;
pub struct Text {
/// The text.
pub text: String,
- /// The font size.
- pub font_size: Length,
+ /// How to align this text node in its parent.
+ pub align: BoxAlign,
/// The text direction.
pub dir: Dir,
+ /// The font size.
+ pub font_size: Length,
/// The families used for font fallback.
pub families: Rc<FallbackTree>,
/// The font variant,
pub variant: FontVariant,
- /// How to align this text node in its parent.
- pub aligns: Gen<Align>,
}
impl Layout for Text {
@@ -30,12 +30,12 @@ impl Layout for Text {
shaping::shape(
&mut loader,
&self.text,
- self.font_size,
self.dir,
+ self.font_size,
&self.families,
self.variant,
),
- self.aligns,
+ self.align,
)
}
}