summaryrefslogtreecommitdiff
path: root/src/layout
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2019-12-05 19:48:37 +0100
committerLaurenz <laurmaedje@gmail.com>2019-12-05 19:48:37 +0100
commit72a9631b038d1a60e4e4a78e92cd69e6f8ce4316 (patch)
tree17614efc2e21dd0b8caa24beaaaee7c40c150281 /src/layout
parentf72b1505bebf8d2fe1a60d386a3a3c3b67d4f903 (diff)
Move arg parser into `FuncArgs` and create (incomplete) consistent map 🧭
Diffstat (limited to 'src/layout')
-rw-r--r--src/layout/flex.rs127
-rw-r--r--src/layout/mod.rs34
-rw-r--r--src/layout/stack.rs57
-rw-r--r--src/layout/tree.rs6
4 files changed, 51 insertions, 173 deletions
diff --git a/src/layout/flex.rs b/src/layout/flex.rs
index 46d66951..13901968 100644
--- a/src/layout/flex.rs
+++ b/src/layout/flex.rs
@@ -50,7 +50,7 @@ impl PartialLine {
usable,
content: vec![],
dimensions: Size2D::zero(),
- space: LastSpacing::Forbidden,
+ space: LastSpacing::Hard,
}
}
}
@@ -72,7 +72,7 @@ impl FlexLayouter {
let stack = StackLayouter::new(StackContext {
spaces: ctx.spaces,
axes: ctx.axes,
- expand: ctx.expand,
+ alignment: ctx.alignment,
});
let usable = stack.primary_usable();
@@ -167,130 +167,27 @@ impl FlexLayouter {
}
fn finish_line(&mut self) -> LayoutResult<Size2D> {
- self.finish_partial_line();
-
- if self.axes.primary.needs_expansion() {
- self.line.combined_dimensions.x = self.line.usable;
- }
-
- self.stack.add(Layout {
- dimensions: self.axes.specialize(self.line.combined_dimensions),
- actions: self.line.actions.to_vec(),
- debug_render: false,
- })?;
-
- self.stack.add_spacing(self.flex_spacing, SpacingKind::Independent);
-
- let remaining = self.axes.specialize(Size2D {
- x: self.part.usable
- - self.part.dimensions.x
- - self.part.space.soft_or_zero(),
- y: self.line.combined_dimensions.y,
- });
-
- self.start_line();
-
- Ok(remaining)
+ unimplemented!()
}
fn start_line(&mut self) {
- let usable = self.stack.primary_usable();
- self.line = FlexLine::new(usable);
- self.part = PartialLine::new(usable);
+ unimplemented!()
}
+ #[allow(dead_code)]
fn finish_partial_line(&mut self) {
- let factor = self.axes.primary.axis.factor();
- let anchor =
- self.axes.primary.anchor(self.line.usable)
- - self.axes.primary.anchor(self.part.dimensions.x);
-
- for (offset, layout) in self.part.content.drain(..) {
- let pos = self.axes.specialize(Size2D::with_x(anchor + factor * offset));
- self.line.actions.add_layout(pos, layout);
- }
-
- self.line.combined_dimensions.x = match self.axes.primary.alignment {
- Alignment::Origin => self.part.dimensions.x,
- Alignment::Center => self.part.usable / 2 + self.part.dimensions.x / 2,
- Alignment::End => self.part.usable,
- };
-
- self.line.combined_dimensions.y.max_eq(self.part.dimensions.y);
+ unimplemented!()
}
- fn layout_box(&mut self, boxed: Layout) -> LayoutResult<()> {
- let size = self.axes.generalize(boxed.dimensions);
- let new_dimension = self.part.dimensions.x
- + size.x
- + self.part.space.soft_or_zero();
-
- if new_dimension > self.part.usable {
- self.finish_line()?;
-
- while size.x > self.line.usable {
- if self.stack.space_is_last() {
- error!("box of size {} does not fit into line of size {}",
- size.x, self.line.usable);
- }
-
- self.stack.finish_space(true);
- }
- }
-
- if let LastSpacing::Soft(space) = self.part.space {
- self.layout_space(space, SpacingKind::Hard);
- }
-
- let offset = self.part.dimensions.x;
- self.part.content.push((offset, boxed));
-
- self.part.dimensions.x += size.x;
- self.part.dimensions.y.max_eq(size.y);
- self.part.space = LastSpacing::Allowed;
-
- Ok(())
+ fn layout_box(&mut self, _boxed: Layout) -> LayoutResult<()> {
+ unimplemented!()
}
- fn layout_space(&mut self, space: Size, kind: SpacingKind) {
- if kind == SpacingKind::Soft {
- if self.part.space != LastSpacing::Forbidden {
- self.part.space = LastSpacing::Soft(space);
- }
- } else {
- if self.part.dimensions.x + space > self.part.usable {
- self.part.dimensions.x = self.part.usable;
- } else {
- self.part.dimensions.x += space;
- }
-
- if kind == SpacingKind::Hard {
- self.part.space = LastSpacing::Forbidden;
- }
- }
+ fn layout_space(&mut self, _space: Size, _kind: SpacingKind) {
+ unimplemented!()
}
- fn layout_set_axes(&mut self, axes: LayoutAxes) {
- if axes.primary != self.axes.primary {
- self.finish_partial_line();
-
- let extent = self.line.combined_dimensions.x;
- let usable = self.line.usable;
-
- let new_usable = match axes.primary.alignment {
- Alignment::Origin if extent == Size::zero() => usable,
- Alignment::Center if extent < usable / 2 => usable - 2 * extent,
- Alignment::End => usable - extent,
- _ => Size::zero(),
- };
-
- self.part = PartialLine::new(new_usable);
- }
-
- if axes.secondary != self.axes.secondary {
- self.stack.set_axes(axes);
- }
-
- self.axes = axes;
+ fn layout_set_axes(&mut self, _axes: LayoutAxes) {
+ unimplemented!()
}
}
diff --git a/src/layout/mod.rs b/src/layout/mod.rs
index 690e91b7..e31d2c17 100644
--- a/src/layout/mod.rs
+++ b/src/layout/mod.rs
@@ -10,7 +10,7 @@ use crate::TypesetResult;
use crate::func::Command;
use crate::size::{Size, Size2D, SizeBox};
use crate::style::{LayoutStyle, TextStyle};
-use crate::syntax::{FuncCall, Node, SyntaxTree};
+use crate::syntax::{Node, SyntaxTree, FuncCall};
mod actions;
mod tree;
@@ -137,6 +137,19 @@ impl LayoutAxes {
self.generalize(size)
}
+ /// Return the specified generic axis.
+ pub fn get_generic(&self, axis: GenericAxisKind) -> Axis {
+ match axis {
+ GenericAxisKind::Primary => self.primary,
+ GenericAxisKind::Secondary => self.secondary,
+ }
+ }
+
+ /// Return the specified specific axis.
+ pub fn get_specific(&self, axis: SpecificAxisKind) -> Axis {
+ self.get_generic(axis.generic(*self))
+ }
+
/// Returns the generic axis kind which is the horizontal axis.
pub fn horizontal(&self) -> GenericAxisKind {
match self.primary.is_horizontal() {
@@ -237,6 +250,14 @@ pub enum GenericAxisKind {
}
impl GenericAxisKind {
+ /// The specific version of this axis in the given system of axes.
+ pub fn specific(&self, axes: LayoutAxes) -> SpecificAxisKind {
+ match self {
+ GenericAxisKind::Primary => axes.primary(),
+ GenericAxisKind::Secondary => axes.secondary(),
+ }
+ }
+
/// The other axis.
pub fn inv(&self) -> GenericAxisKind {
match self {
@@ -254,6 +275,14 @@ pub enum SpecificAxisKind {
}
impl SpecificAxisKind {
+ /// The generic version of this axis in the given system of axes.
+ pub fn generic(&self, axes: LayoutAxes) -> GenericAxisKind {
+ match self {
+ SpecificAxisKind::Horizontal => axes.horizontal(),
+ SpecificAxisKind::Vertical => axes.vertical(),
+ }
+ }
+
/// The other axis.
pub fn inv(&self) -> SpecificAxisKind {
match self {
@@ -330,6 +359,7 @@ enum LastSpacing {
}
impl LastSpacing {
+ #[allow(dead_code)]
fn soft_or_zero(&self) -> Size {
match self {
LastSpacing::Soft(space, _) => *space,
@@ -339,7 +369,7 @@ impl LastSpacing {
}
/// Layout components that can be serialized.
-trait Serialize {
+pub trait Serialize {
/// Serialize the data structure into an output writable.
fn serialize<W: Write>(&self, f: &mut W) -> io::Result<()>;
}
diff --git a/src/layout/stack.rs b/src/layout/stack.rs
index 176aa261..3f9af350 100644
--- a/src/layout/stack.rs
+++ b/src/layout/stack.rs
@@ -244,51 +244,12 @@ impl StackLayouter {
self.layouts
}
- pub fn finish_space(&mut self, hard: bool) {
- self.finish_subspace();
-
- let space = self.ctx.spaces[self.space.index];
-
- self.layouts.push(Layout {
- dimensions: match self.ctx.expand {
- true => space.dimensions,
- false => self.space.combined_dimensions.padded(space.padding),
- },
- baseline: None,
- alignment: self.ctx.alignment,
- actions: actions.to_vec(),
- });
-
- self.start_space(self.next_space(), hard);
+ pub fn finish_space(&mut self, _hard: bool) {
+ unimplemented!()
}
fn finish_subspace(&mut self) {
- let factor = self.ctx.axes.secondary.axis.factor();
- let anchor =
- self.ctx.axes.anchor(self.sub.usable)
- - self.ctx.axes.anchor(Size2D::with_y(self.sub.dimensions.y));
-
- for (offset, layout_anchor, layout) in self.sub.boxes.drain(..) {
- let pos = self.sub.origin
- + self.ctx.axes.specialize(
- anchor + Size2D::new(-layout_anchor, factor * offset)
- );
-
- self.space.actions.add_layout(pos, layout);
- }
-
- if self.ctx.axes.primary.needs_expansion() {
- self.sub.dimensions.x = self.sub.usable.x;
- }
-
- if self.ctx.axes.secondary.needs_expansion() {
- self.sub.dimensions.y = self.sub.usable.y;
- }
-
- let space = self.ctx.spaces[self.space.index];
- let origin = self.sub.origin;
- let dimensions = self.ctx.axes.specialize(self.sub.dimensions);
- self.space.combined_dimensions.max_eq(origin - space.start() + dimensions);
+ unimplemented!()
}
/// Start a new space with the given index.
@@ -304,17 +265,7 @@ impl StackLayouter {
/// The remaining sub
fn remaining_subspace(&self) -> (Size2D, Size2D) {
- let new_origin = self.sub.origin + match self.ctx.axes.secondary.axis.is_positive() {
- true => self.ctx.axes.specialize(Size2D::with_y(self.sub.dimensions.y)),
- false => Size2D::zero(),
- };
-
- let new_usable = self.ctx.axes.specialize(Size2D {
- x: self.sub.usable.x,
- y: self.sub.usable.y - self.sub.dimensions.y - self.sub.space.soft_or_zero(),
- });
-
- (new_origin, new_usable)
+ unimplemented!()
}
fn next_space(&self) -> usize {
diff --git a/src/layout/tree.rs b/src/layout/tree.rs
index c9d40e93..4370ceab 100644
--- a/src/layout/tree.rs
+++ b/src/layout/tree.rs
@@ -1,5 +1,5 @@
-use super::*;
use smallvec::smallvec;
+use super::*;
pub fn layout_tree(tree: &SyntaxTree, ctx: LayoutContext) -> LayoutResult<MultiLayout> {
let mut layouter = TreeLayouter::new(ctx);
@@ -31,7 +31,7 @@ impl<'a, 'p> TreeLayouter<'a, 'p> {
fn layout(&mut self, tree: &SyntaxTree) -> LayoutResult<()> {
for node in &tree.nodes {
- match &node.val {
+ match &node.v {
Node::Text(text) => self.layout_text(text)?,
Node::Space => self.layout_space(),
@@ -75,7 +75,7 @@ impl<'a, 'p> TreeLayouter<'a, 'p> {
fn layout_func(&mut self, func: &FuncCall) -> LayoutResult<()> {
let spaces = self.flex.remaining();
- let commands = func.body.val.layout(LayoutContext {
+ let commands = func.call.layout(LayoutContext {
loader: self.ctx.loader,
style: &self.style,
top_level: false,