summaryrefslogtreecommitdiff
path: root/src/layout/tree.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2019-12-01 19:18:06 +0100
committerLaurenz <laurmaedje@gmail.com>2019-12-01 19:18:38 +0100
commitace57c34206a13b4bc3885b944cc51e274f30b0f (patch)
tree2f1e1e8e4ac5c3867492d5a59c49045058e16123 /src/layout/tree.rs
parent5782b82770f6923677942c3b4e2bf4f7258e47d8 (diff)
First half of stack update 🌓
Diffstat (limited to 'src/layout/tree.rs')
-rw-r--r--src/layout/tree.rs41
1 files changed, 22 insertions, 19 deletions
diff --git a/src/layout/tree.rs b/src/layout/tree.rs
index 9a818963..efa0c7b7 100644
--- a/src/layout/tree.rs
+++ b/src/layout/tree.rs
@@ -19,10 +19,10 @@ impl<'a, 'p> TreeLayouter<'a, 'p> {
fn new(ctx: LayoutContext<'a, 'p>) -> TreeLayouter<'a, 'p> {
TreeLayouter {
flex: FlexLayouter::new(FlexContext {
- flex_spacing: flex_spacing(&ctx.style.text),
spaces: ctx.spaces.clone(),
axes: ctx.axes,
- expand: ctx.expand,
+ alignment: ctx.alignment,
+ flex_spacing: flex_spacing(&ctx.style.text),
}),
style: ctx.style.clone(),
ctx,
@@ -52,6 +52,7 @@ impl<'a, 'p> TreeLayouter<'a, 'p> {
let layout = layout_text(text, TextContext {
loader: &self.ctx.loader,
style: &self.style.text,
+ alignment: self.ctx.alignment,
})?;
Ok(self.flex.add(layout))
@@ -90,23 +91,25 @@ impl<'a, 'p> TreeLayouter<'a, 'p> {
}
fn execute(&mut self, command: Command) -> LayoutResult<()> {
- match command {
- Command::LayoutTree(tree) => self.layout(tree)?,
+ use Command::*;
- Command::Add(layout) => self.flex.add(layout),
- Command::AddMultiple(layouts) => self.flex.add_multiple(layouts),
-
- Command::AddPrimarySpace(space) => self.flex.add_primary_space(space, SpacingKind::Hard),
- Command::AddSecondarySpace(space) => self.flex.add_secondary_space(space, SpacingKind::Hard)?,
+ match command {
+ LayoutTree(tree) => self.layout(tree)?,
- Command::FinishLine => self.flex.add_break(),
- Command::FinishRun => { self.flex.finish_run()?; },
- Command::FinishSpace => self.flex.finish_space(true)?,
+ Add(layout) => self.flex.add(layout),
+ AddMultiple(layouts) => self.flex.add_multiple(layouts),
+ AddSpacing(space, kind, axis) => match axis {
+ AxisKind::Primary => self.flex.add_primary_space(space, kind),
+ AxisKind::Secondary => self.flex.add_secondary_space(space, kind)?,
+ }
- Command::BreakParagraph => self.layout_paragraph()?,
+ FinishLine => self.flex.add_break(),
+ FinishRun => { self.flex.finish_run()?; },
+ FinishSpace => self.flex.finish_space(true)?,
+ BreakParagraph => self.layout_paragraph()?,
- Command::SetTextStyle(style) => self.style.text = style,
- Command::SetPageStyle(style) => {
+ SetTextStyle(style) => self.style.text = style,
+ SetPageStyle(style) => {
if !self.ctx.top_level {
lerr!("page style cannot only be altered in the top-level context");
}
@@ -115,13 +118,13 @@ impl<'a, 'p> TreeLayouter<'a, 'p> {
self.flex.set_spaces(smallvec![
LayoutSpace {
dimensions: style.dimensions,
- expand: (true, true),
padding: style.margins,
+ expand: (true, true),
}
], true);
- },
-
- Command::SetAxes(axes) => {
+ }
+ SetAlignment(alignment) => self.ctx.alignment = alignment,
+ SetAxes(axes) => {
self.flex.set_axes(axes);
self.ctx.axes = axes;
}