summaryrefslogtreecommitdiff
path: root/src/layout
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2020-08-02 16:31:34 +0200
committerLaurenz <laurmaedje@gmail.com>2020-08-02 16:31:34 +0200
commit533374db14087ac54fdc86afa5f009487ac1b850 (patch)
tree0970eb1ca893fe45369d622b5bc1f226f0f66004 /src/layout
parent2188ef6b899cc10c84ed985e9ad9049fcc3eb662 (diff)
Refactor argument parsing 🔬
Diffstat (limited to 'src/layout')
-rw-r--r--src/layout/line.rs32
-rw-r--r--src/layout/mod.rs282
-rw-r--r--src/layout/model.rs31
-rw-r--r--src/layout/stack.rs40
-rw-r--r--src/layout/text.rs4
5 files changed, 224 insertions, 165 deletions
diff --git a/src/layout/line.rs b/src/layout/line.rs
index 0ef58878..aafdab60 100644
--- a/src/layout/line.rs
+++ b/src/layout/line.rs
@@ -32,7 +32,7 @@ pub struct LineContext {
pub axes: LayoutAxes,
/// Which alignment to set on the resulting layout. This affects how it will
/// be positioned in a parent box.
- pub alignment: LayoutAlignment,
+ pub align: LayoutAlign,
/// Whether to have repeated spaces or to use only the first and only once.
pub repeat: bool,
/// Whether to output a command which renders a debugging box showing the
@@ -56,7 +56,7 @@ struct LineRun {
/// When a new run is created the alignment is yet to be determined. Once a
/// layout is added, it is decided which alignment the run has and all
/// further elements of the run must have this alignment.
- alignment: Option<LayoutAlignment>,
+ align: Option<LayoutAlign>,
/// If another line run with different alignment already took up some space
/// of the line, this run has less space and how much is stored here.
usable: Option<f64>,
@@ -71,7 +71,7 @@ impl LineLayouter {
stack: StackLayouter::new(StackContext {
spaces: ctx.spaces.clone(),
axes: ctx.axes,
- alignment: ctx.alignment,
+ align: ctx.align,
repeat: ctx.repeat,
debug: ctx.debug,
}),
@@ -84,27 +84,27 @@ impl LineLayouter {
pub fn add(&mut self, layout: Layout) {
let axes = self.ctx.axes;
- if let Some(alignment) = self.run.alignment {
- if layout.alignment.secondary != alignment.secondary {
+ if let Some(align) = self.run.align {
+ if layout.align.secondary != align.secondary {
// TODO: Issue warning for non-fitting alignment in
// non-repeating context.
- let fitting = self.stack.is_fitting_alignment(layout.alignment);
+ let fitting = self.stack.is_fitting_alignment(layout.align);
if !fitting && self.ctx.repeat {
self.finish_space(true);
} else {
self.finish_line();
}
- } else if layout.alignment.primary < alignment.primary {
+ } else if layout.align.primary < align.primary {
self.finish_line();
- } else if layout.alignment.primary > alignment.primary {
+ } else if layout.align.primary > align.primary {
let mut rest_run = LineRun::new();
let usable = self.stack.usable().primary(axes);
- rest_run.usable = Some(match layout.alignment.primary {
- Alignment::Origin => unreachable!("origin > x"),
- Alignment::Center => usable - 2.0 * self.run.size.x,
- Alignment::End => usable - self.run.size.x,
+ rest_run.usable = Some(match layout.align.primary {
+ GenAlign::Start => unreachable!("start > x"),
+ GenAlign::Center => usable - 2.0 * self.run.size.x,
+ GenAlign::End => usable - self.run.size.x,
});
rest_run.size.y = self.run.size.y;
@@ -133,7 +133,7 @@ impl LineLayouter {
}
}
- self.run.alignment = Some(layout.alignment);
+ self.run.align = Some(layout.align);
self.run.layouts.push((self.run.size.x, layout));
self.run.size.x += size.x;
@@ -269,8 +269,8 @@ impl LineLayouter {
self.stack.add(Layout {
dimensions: self.run.size.specialized(self.ctx.axes),
- alignment: self.run.alignment
- .unwrap_or(LayoutAlignment::new(Origin, Origin)),
+ align: self.run.align
+ .unwrap_or(LayoutAlign::new(Start, Start)),
actions: actions.into_vec(),
});
@@ -292,7 +292,7 @@ impl LineRun {
LineRun {
layouts: vec![],
size: Size::ZERO,
- alignment: None,
+ align: None,
usable: None,
last_spacing: LastSpacing::Hard,
}
diff --git a/src/layout/mod.rs b/src/layout/mod.rs
index a6af0f82..510f504a 100644
--- a/src/layout/mod.rs
+++ b/src/layout/mod.rs
@@ -11,20 +11,20 @@ use self::prelude::*;
pub mod line;
pub mod stack;
pub mod text;
-
pub_use_mod!(actions);
pub_use_mod!(model);
/// Basic types used across the layouting engine.
pub mod prelude {
pub use super::{
- LayoutContext, layout, LayoutSpace, Commands,
- LayoutAxes, LayoutAlignment, LayoutExpansion
+ layout, LayoutContext, LayoutSpace, Command, Commands,
+ LayoutAxes, LayoutAlign, LayoutExpansion,
};
- pub use super::GenericAxis::{self, *};
- pub use super::SpecificAxis::{self, *};
- pub use super::Direction::{self, *};
- pub use super::Alignment::{self, *};
+ pub use super::Dir::{self, *};
+ pub use super::GenAxis::{self, *};
+ pub use super::SpecAxis::{self, *};
+ pub use super::GenAlign::{self, *};
+ pub use super::SpecAlign::{self, *};
}
/// A collection of layouts.
@@ -37,7 +37,7 @@ pub struct Layout {
pub dimensions: Size,
/// How to align this layout in a parent container.
#[serde(skip)]
- pub alignment: LayoutAlignment,
+ pub align: LayoutAlign,
/// The actions composing this layout.
pub actions: Vec<LayoutAction>,
}
@@ -95,82 +95,31 @@ impl LayoutSpace {
}
}
-/// The two generic layouting axes.
-#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
-pub enum GenericAxis {
- /// The primary axis along which words are laid out.
- Primary,
- /// The secondary axis along which lines and paragraphs are laid out.
- Secondary,
-}
-
-impl GenericAxis {
- /// The specific version of this axis in the given system of axes.
- pub fn to_specific(self, axes: LayoutAxes) -> SpecificAxis {
- axes.get(self).axis()
- }
-}
-
-impl Display for GenericAxis {
- fn fmt(&self, f: &mut Formatter) -> fmt::Result {
- match self {
- Primary => write!(f, "primary"),
- Secondary => write!(f, "secondary"),
- }
- }
-}
-
-/// The two specific layouting axes.
-#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
-pub enum SpecificAxis {
- /// The horizontal layouting axis.
- Horizontal,
- /// The vertical layouting axis.
- Vertical,
-}
-
-impl SpecificAxis {
- /// The generic version of this axis in the given system of axes.
- pub fn to_generic(self, axes: LayoutAxes) -> GenericAxis {
- if self == axes.primary.axis() { Primary } else { Secondary }
- }
-}
-
-impl Display for SpecificAxis {
- fn fmt(&self, f: &mut Formatter) -> fmt::Result {
- match self {
- Horizontal => write!(f, "horizontal"),
- Vertical => write!(f, "vertical"),
- }
- }
-}
-
-/// Specifies along which directions content is laid out.
+/// Specifies along which axes content is laid out.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub struct LayoutAxes {
/// The primary layouting direction.
- pub primary: Direction,
+ pub primary: Dir,
/// The secondary layouting direction.
- pub secondary: Direction,
+ pub secondary: Dir,
}
impl LayoutAxes {
/// Create a new instance from the two values.
///
/// # Panics
- /// This function panics if the directions are aligned, that is, they are
+ /// This function panics if the axes are aligned, that is, they are
/// on the same axis.
- pub fn new(primary: Direction, secondary: Direction) -> LayoutAxes {
+ pub fn new(primary: Dir, secondary: Dir) -> LayoutAxes {
if primary.axis() == secondary.axis() {
- panic!("LayoutAxes::new: invalid aligned axes \
- {} and {}", primary, secondary);
+ panic!("invalid aligned axes {} and {}", primary, secondary);
}
LayoutAxes { primary, secondary }
}
/// Return the direction of the specified generic axis.
- pub fn get(self, axis: GenericAxis) -> Direction {
+ pub fn get(self, axis: GenAxis) -> Dir {
match axis {
Primary => self.primary,
Secondary => self.secondary,
@@ -178,7 +127,7 @@ impl LayoutAxes {
}
/// Borrow the direction of the specified generic axis mutably.
- pub fn get_mut(&mut self, axis: GenericAxis) -> &mut Direction {
+ pub fn get_mut(&mut self, axis: GenAxis) -> &mut Dir {
match axis {
Primary => &mut self.primary,
Secondary => &mut self.secondary,
@@ -188,30 +137,29 @@ impl LayoutAxes {
/// Directions along which content is laid out.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
-#[allow(missing_docs)]
-pub enum Direction {
- LeftToRight,
- RightToLeft,
- TopToBottom,
- BottomToTop,
+pub enum Dir {
+ LTT,
+ RTL,
+ TTB,
+ BTT,
}
-impl Direction {
+impl Dir {
/// The specific axis this direction belongs to.
- pub fn axis(self) -> SpecificAxis {
+ pub fn axis(self) -> SpecAxis {
match self {
- LeftToRight | RightToLeft => Horizontal,
- TopToBottom | BottomToTop => Vertical,
+ LTT | RTL => Horizontal,
+ TTB | BTT => Vertical,
}
}
/// Whether this axis points into the positive coordinate direction.
///
- /// The positive directions are left-to-right and top-to-bottom.
+ /// The positive axes are left-to-right and top-to-bottom.
pub fn is_positive(self) -> bool {
match self {
- LeftToRight | TopToBottom => true,
- RightToLeft | BottomToTop => false,
+ LTT | TTB => true,
+ RTL | BTT => false,
}
}
@@ -224,44 +172,94 @@ impl Direction {
}
/// The inverse axis.
- pub fn inv(self) -> Direction {
+ pub fn inv(self) -> Dir {
match self {
- LeftToRight => RightToLeft,
- RightToLeft => LeftToRight,
- TopToBottom => BottomToTop,
- BottomToTop => TopToBottom,
+ LTT => RTL,
+ RTL => LTT,
+ TTB => BTT,
+ BTT => TTB,
}
}
}
-impl Display for Direction {
+impl Display for Dir {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
- match self {
- LeftToRight => write!(f, "left-to-right"),
- RightToLeft => write!(f, "right-to-left"),
- TopToBottom => write!(f, "top-to-bottom"),
- BottomToTop => write!(f, "bottom-to-top"),
- }
+ f.pad(match self {
+ LTT => "ltr",
+ RTL => "rtl",
+ TTB => "ttb",
+ BTT => "btt",
+ })
+ }
+}
+
+/// The two generic layouting axes.
+#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
+pub enum GenAxis {
+ /// The primary axis along which words are laid out.
+ Primary,
+ /// The secondary axis along which lines and paragraphs are laid out.
+ Secondary,
+}
+
+impl GenAxis {
+ /// The specific version of this axis in the given system of axes.
+ pub fn to_specific(self, axes: LayoutAxes) -> SpecAxis {
+ axes.get(self).axis()
+ }
+}
+
+impl Display for GenAxis {
+ fn fmt(&self, f: &mut Formatter) -> fmt::Result {
+ f.pad(match self {
+ Primary => "primary",
+ Secondary => "secondary",
+ })
+ }
+}
+
+/// The two specific layouting axes.
+#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
+pub enum SpecAxis {
+ /// The horizontal layouting axis.
+ Horizontal,
+ /// The vertical layouting axis.
+ Vertical,
+}
+
+impl SpecAxis {
+ /// The generic version of this axis in the given system of axes.
+ pub fn to_generic(self, axes: LayoutAxes) -> GenAxis {
+ if self == axes.primary.axis() { Primary } else { Secondary }
+ }
+}
+
+impl Display for SpecAxis {
+ fn fmt(&self, f: &mut Formatter) -> fmt::Result {
+ f.pad(match self {
+ Horizontal => "horizontal",
+ Vertical => "vertical",
+ })
}
}
/// Specifies where to align a layout in a parent container.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
-pub struct LayoutAlignment {
+pub struct LayoutAlign {
/// The alignment along the primary axis.
- pub primary: Alignment,
+ pub primary: GenAlign,
/// The alignment along the secondary axis.
- pub secondary: Alignment,
+ pub secondary: GenAlign,
}
-impl LayoutAlignment {
+impl LayoutAlign {
/// Create a new instance from the two values.
- pub fn new(primary: Alignment, secondary: Alignment) -> LayoutAlignment {
- LayoutAlignment { primary, secondary }
+ pub fn new(primary: GenAlign, secondary: GenAlign) -> LayoutAlign {
+ LayoutAlign { primary, secondary }
}
/// Return the alignment of the specified generic axis.
- pub fn get(self, axis: GenericAxis) -> Alignment {
+ pub fn get(self, axis: GenAxis) -> GenAlign {
match axis {
Primary => self.primary,
Secondary => self.secondary,
@@ -269,7 +267,7 @@ impl LayoutAlignment {
}
/// Borrow the alignment of the specified generic axis mutably.
- pub fn get_mut(&mut self, axis: GenericAxis) -> &mut Alignment {
+ pub fn get_mut(&mut self, axis: GenAxis) -> &mut GenAlign {
match axis {
Primary => &mut self.primary,
Secondary => &mut self.secondary,
@@ -277,28 +275,88 @@ impl LayoutAlignment {
}
}
-/// Where to align content.
+/// Where to align content along a generic context.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
-pub enum Alignment {
- /// Align content at the start of the axis.
- Origin,
- /// Align content centered on the axis.
+pub enum GenAlign {
+ Start,
Center,
- /// Align content at the end of the axis.
End,
}
-impl Alignment {
+impl GenAlign {
/// The inverse alignment.
- pub fn inv(self) -> Alignment {
+ pub fn inv(self) -> GenAlign {
match self {
- Origin => End,
+ Start => End,
Center => Center,
- End => Origin,
+ End => Start,
+ }
+ }
+}
+
+impl Display for GenAlign {
+ fn fmt(&self, f: &mut Formatter) -> fmt::Result {
+ f.pad(match self {
+ Start => "start",
+ Center => "center",
+ End => "end",
+ })
+ }
+}
+
+/// Where to align content in a specific context.
+#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
+pub enum SpecAlign {
+ Left,
+ Right,
+ Top,
+ Bottom,
+ Center,
+}
+
+impl SpecAlign {
+ /// The specific axis this alignment refers to.
+ ///
+ /// Returns `None` if this is center.
+ pub fn axis(self) -> Option<SpecAxis> {
+ match self {
+ Self::Left => Some(Horizontal),
+ Self::Right => Some(Horizontal),
+ Self::Top => Some(Vertical),
+ Self::Bottom => Some(Vertical),
+ Self::Center => None,
+ }
+ }
+
+ /// Convert this to a generic alignment.
+ pub fn to_generic(self, axes: LayoutAxes) -> GenAlign {
+ let get = |spec: SpecAxis, align: GenAlign| {
+ let axis = spec.to_generic(axes);
+ if axes.get(axis).is_positive() { align } else { align.inv() }
+ };
+
+ match self {
+ Self::Left => get(Horizontal, Start),
+ Self::Right => get(Horizontal, End),
+ Self::Top => get(Vertical, Start),
+ Self::Bottom => get(Vertical, End),
+ Self::Center => GenAlign::Center,
}
}
}
+impl Display for SpecAlign {
+ fn fmt(&self, f: &mut Formatter) -> fmt::Result {
+ f.pad(match self {
+ Self::Left => "left",
+ Self::Right => "right",
+ Self::Top => "top",
+ Self::Bottom => "bottom",
+ Self::Center => "center",
+ })
+ }
+}
+
/// Specifies whether to expand a layout to the full size of the space it is
/// laid out in or to shrink it to fit the content.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
@@ -316,7 +374,7 @@ impl LayoutExpansion {
}
/// Return the expansion value for the given specific axis.
- pub fn get(self, axis: SpecificAxis) -> bool {
+ pub fn get(self, axis: SpecAxis) -> bool {
match axis {
Horizontal => self.horizontal,
Vertical => self.vertical,
@@ -324,7 +382,7 @@ impl LayoutExpansion {
}
/// Borrow the expansion value for the given specific axis mutably.
- pub fn get_mut(&mut self, axis: SpecificAxis) -> &mut bool {
+ pub fn get_mut(&mut self, axis: SpecAxis) -> &mut bool {
match axis {
Horizontal => &mut self.horizontal,
Vertical => &mut self.vertical,
diff --git a/src/layout/model.rs b/src/layout/model.rs
index c78c733e..08a9ec0e 100644
--- a/src/layout/model.rs
+++ b/src/layout/model.rs
@@ -10,7 +10,8 @@ use crate::{Pass, Feedback};
use crate::SharedFontLoader;
use crate::style::{LayoutStyle, PageStyle, TextStyle};
use crate::geom::Size;
-use crate::syntax::{Model, SyntaxModel, Node, Decoration};
+use crate::syntax::decoration::Decoration;
+use crate::syntax::model::{Model, SyntaxModel, Node};
use crate::syntax::span::{Span, Spanned};
use super::line::{LineLayouter, LineContext};
use super::text::{layout_text, TextContext};
@@ -42,7 +43,7 @@ pub struct LayoutContext<'a> {
/// The initial axes along which content is laid out.
pub axes: LayoutAxes,
/// The alignment of the finished layout.
- pub alignment: LayoutAlignment,
+ pub align: LayoutAlign,
/// Whether the layout that is to be created will be nested in a parent
/// container.
pub nested: bool,
@@ -74,7 +75,7 @@ pub enum Command<'a> {
/// Add spacing of given [kind](super::SpacingKind) along the primary or
/// secondary axis. The spacing kind defines how the spacing interacts with
/// surrounding spacing.
- AddSpacing(f64, SpacingKind, GenericAxis),
+ AddSpacing(f64, SpacingKind, GenAxis),
/// Start a new line.
BreakLine,
@@ -90,9 +91,9 @@ pub enum Command<'a> {
SetPageStyle(PageStyle),
/// Update the alignment for future boxes added to this layouting process.
- SetAlignment(LayoutAlignment),
- /// Update the layouting axes along which future boxes will be laid out.
- /// This finishes the current line.
+ SetAlignment(LayoutAlign),
+ /// Update the layouting axes along which future boxes will be laid
+ /// out. This finishes the current line.
SetAxes(LayoutAxes),
}
@@ -115,7 +116,7 @@ impl<'a> ModelLayouter<'a> {
layouter: LineLayouter::new(LineContext {
spaces: ctx.spaces.clone(),
axes: ctx.axes,
- alignment: ctx.alignment,
+ align: ctx.align,
repeat: ctx.repeat,
debug: ctx.debug && ctx.nested,
line_spacing: ctx.style.text.line_spacing(),
@@ -127,10 +128,10 @@ impl<'a> ModelLayouter<'a> {
}
/// Flatly layout a model into this layouting process.
- pub fn layout<'r>(
+ pub async fn layout<'r>(
&'r mut self,
model: Spanned<&'r dyn Model>
- ) -> DynFuture<'r, ()> { Box::pin(async move {
+ ) {
// Execute the model's layout function which generates the commands.
let layouted = model.v.layout(LayoutContext {
style: &self.style,
@@ -145,14 +146,14 @@ impl<'a> ModelLayouter<'a> {
for command in layouted.output {
self.execute_command(command, model.span).await;
}
- }) }
+ }
/// Layout a syntax model by directly processing the nodes instead of using
/// the command based architecture.
- pub fn layout_syntax_model<'r>(
+ pub async fn layout_syntax_model<'r>(
&'r mut self,
model: &'r SyntaxModel
- ) -> DynFuture<'r, ()> { Box::pin(async move {
+ ) {
use Node::*;
for Spanned { v: node, span } in &model.nodes {
@@ -213,7 +214,7 @@ impl<'a> ModelLayouter<'a> {
}
}
}
- }) }
+ }
/// Compute the finished list of boxes.
pub fn finish(self) -> Pass<MultiLayout> {
@@ -280,7 +281,7 @@ impl<'a> ModelLayouter<'a> {
}
}
- SetAlignment(alignment) => self.ctx.alignment = alignment,
+ SetAlignment(align) => self.ctx.align = align,
SetAxes(axes) => {
self.layouter.set_axes(axes);
self.ctx.axes = axes;
@@ -294,7 +295,7 @@ impl<'a> ModelLayouter<'a> {
loader: &self.ctx.loader,
style: &self.style.text,
axes: self.ctx.axes,
- alignment: self.ctx.alignment,
+ align: self.ctx.align,
}).await)
}
diff --git a/src/layout/stack.rs b/src/layout/stack.rs
index 2dd67ea9..e684a6ab 100644
--- a/src/layout/stack.rs
+++ b/src/layout/stack.rs
@@ -46,7 +46,7 @@ pub struct StackContext {
pub axes: LayoutAxes,
/// Which alignment to set on the resulting layout. This affects how it will
/// be positioned in a parent box.
- pub alignment: LayoutAlignment,
+ pub align: LayoutAlign,
/// Whether to have repeated spaces or to use only the first and only once.
pub repeat: bool,
/// Whether to output a command which renders a debugging box showing the
@@ -72,7 +72,7 @@ struct Space {
extra: Size,
/// The rulers of a space dictate which alignments for new boxes are still
/// allowed and which require a new space to be started.
- rulers: Value4<Alignment>,
+ rulers: Value4<GenAlign>,
/// The last added spacing if the last added thing was spacing.
last_spacing: LastSpacing,
}
@@ -93,7 +93,7 @@ impl StackLayouter {
// If the alignment cannot be fitted in this space, finish it.
// TODO: Issue warning for non-fitting alignment in
// non-repeating context.
- if !self.update_rulers(layout.alignment) && self.ctx.repeat {
+ if !self.update_rulers(layout.align) && self.ctx.repeat {
self.finish_space(true);
}
@@ -139,7 +139,7 @@ impl StackLayouter {
self.update_metrics(dimensions);
self.space.layouts.push((self.ctx.axes, Layout {
dimensions: dimensions.specialized(self.ctx.axes),
- alignment: LayoutAlignment::new(Origin, Origin),
+ align: LayoutAlign::new(Start, Start),
actions: vec![]
}));
@@ -183,26 +183,26 @@ impl StackLayouter {
/// Update the rulers to account for the new layout. Returns true if a
/// space break is necessary.
- fn update_rulers(&mut self, alignment: LayoutAlignment) -> bool {
- let allowed = self.is_fitting_alignment(alignment);
+ fn update_rulers(&mut self, align: LayoutAlign) -> bool {
+ let allowed = self.is_fitting_alignment(align);
if allowed {
- *self.space.rulers.get_mut(self.ctx.axes.secondary, Origin)
- = alignment.secondary;
+ *self.space.rulers.get_mut(self.ctx.axes.secondary, Start)
+ = align.secondary;
}
allowed
}
/// Whether a layout with the given alignment can still be layouted in the
/// active space.
- pub fn is_fitting_alignment(&mut self, alignment: LayoutAlignment) -> bool {
- self.is_fitting_axis(self.ctx.axes.primary, alignment.primary)
- && self.is_fitting_axis(self.ctx.axes.secondary, alignment.secondary)
+ pub fn is_fitting_alignment(&mut self, align: LayoutAlign) -> bool {
+ self.is_fitting_axis(self.ctx.axes.primary, align.primary)
+ && self.is_fitting_axis(self.ctx.axes.secondary, align.secondary)
}
/// Whether the given alignment is still allowed according to the rulers.
- fn is_fitting_axis(&mut self, direction: Direction, alignment: Alignment) -> bool {
- alignment >= *self.space.rulers.get_mut(direction, Origin)
- && alignment <= self.space.rulers.get_mut(direction, End).inv()
+ fn is_fitting_axis(&mut self, dir: Dir, align: GenAlign) -> bool {
+ align >= *self.space.rulers.get_mut(dir, Start)
+ && align <= self.space.rulers.get_mut(dir, End).inv()
}
/// Change the layouting axes used by this layouter.
@@ -326,7 +326,7 @@ impl StackLayouter {
// layout uses up space from the origin to the end. Thus, it reduces
// the usable space for following layouts at it's origin by its
// extent along the secondary axis.
- *bound.get_mut(axes.secondary, Origin)
+ *bound.get_mut(axes.secondary, Start)
+= axes.secondary.factor() * layout.dimensions.secondary(*axes);
}
@@ -342,7 +342,7 @@ impl StackLayouter {
for (bound, entry) in bounds.iter_mut().zip(&self.space.layouts).rev() {
let (axes, layout) = entry;
- // When the axes get rotated, the the maximal primary size
+ // When the axes are rotated, the the maximal primary size
// (`extent.x`) dictates how much secondary extent the whole run
// had. This value is thus stored in `extent.y`. The primary extent
// is reset for this new axis-aligned run.
@@ -377,7 +377,7 @@ impl StackLayouter {
let layouts = std::mem::replace(&mut self.space.layouts, vec![]);
for ((axes, layout), bound) in layouts.into_iter().zip(bounds) {
let size = layout.dimensions.specialized(axes);
- let alignment = layout.alignment;
+ let align = layout.align;
// The space in which this layout is aligned is given by the
// distances between the borders of it's bounding box.
@@ -385,7 +385,7 @@ impl StackLayouter {
Size::new(bound.right - bound.left, bound.bottom - bound.top)
.generalized(axes);
- let local = usable.anchor(alignment, axes) - size.anchor(alignment, axes);
+ let local = usable.anchor(align, axes) - size.anchor(align, axes);
let pos = Size::new(bound.left, bound.top) + local.specialized(axes);
actions.add_layout(pos, layout);
@@ -393,7 +393,7 @@ impl StackLayouter {
self.layouts.push(Layout {
dimensions,
- alignment: self.ctx.alignment,
+ align: self.ctx.align,
actions: actions.into_vec(),
});
@@ -424,7 +424,7 @@ impl Space {
size: Size::ZERO,
usable,
extra: Size::ZERO,
- rulers: Value4::with_all(Origin),
+ rulers: Value4::with_all(Start),
last_spacing: LastSpacing::Hard,
}
}
diff --git a/src/layout/text.rs b/src/layout/text.rs
index 30995be0..6698a0fa 100644
--- a/src/layout/text.rs
+++ b/src/layout/text.rs
@@ -34,7 +34,7 @@ pub struct TextContext<'a> {
/// primary-horizontal layouting is supported.
pub axes: LayoutAxes,
/// The alignment of the finished layout.
- pub alignment: LayoutAlignment,
+ pub align: LayoutAlign,
}
/// Layouts text into a box.
@@ -75,7 +75,7 @@ impl<'a> TextLayouter<'a> {
Layout {
dimensions: Size::new(self.width, self.ctx.style.font_size()),
- alignment: self.ctx.alignment,
+ align: self.ctx.align,
actions: self.actions.into_vec(),
}
}