diff options
Diffstat (limited to 'src/layout')
| -rw-r--r-- | src/layout/line.rs | 44 | ||||
| -rw-r--r-- | src/layout/mod.rs | 29 | ||||
| -rw-r--r-- | src/layout/stack.rs | 73 | ||||
| -rw-r--r-- | src/layout/tree.rs | 4 |
4 files changed, 75 insertions, 75 deletions
diff --git a/src/layout/line.rs b/src/layout/line.rs index 9de8348c..baef9fb0 100644 --- a/src/layout/line.rs +++ b/src/layout/line.rs @@ -12,7 +12,9 @@ use super::*; /// Performs the line layouting. pub struct LineLayouter { + /// The context used for line layouting. ctx: LineContext, + /// The underlying layouter that stacks the finished lines. stack: StackLayouter, /// The in-progress line. run: LineRun, @@ -36,27 +38,6 @@ pub struct LineContext { pub line_spacing: f64, } -/// A sequence of boxes with the same alignment. A real line can consist of -/// multiple runs with different alignments. -struct LineRun { - /// The so-far accumulated items of the run. - layouts: Vec<(f64, BoxLayout)>, - /// The summed width and maximal height of the run. - size: Size, - /// The alignment of all layouts in the line. - /// - /// When a new run is created the alignment is yet to be determined and - /// `None` as such. Once a layout is added, its alignment decides the - /// alignment for the whole run. - align: Option<LayoutAlign>, - /// The amount of space left by another run on the same line or `None` if - /// this is the only run so far. - usable: Option<f64>, - /// The spacing state. This influences how new spacing is handled, e.g. hard - /// spacing may override soft spacing. - last_spacing: LastSpacing, -} - impl LineLayouter { /// Create a new line layouter. pub fn new(ctx: LineContext) -> Self { @@ -259,6 +240,27 @@ impl LineLayouter { } } +/// A sequence of boxes with the same alignment. A real line can consist of +/// multiple runs with different alignments. +struct LineRun { + /// The so-far accumulated items of the run. + layouts: Vec<(f64, BoxLayout)>, + /// The summed width and maximal height of the run. + size: Size, + /// The alignment of all layouts in the line. + /// + /// When a new run is created the alignment is yet to be determined and + /// `None` as such. Once a layout is added, its alignment decides the + /// alignment for the whole run. + align: Option<LayoutAlign>, + /// The amount of space left by another run on the same line or `None` if + /// this is the only run so far. + usable: Option<f64>, + /// The spacing state. This influences how new spacing is handled, e.g. hard + /// spacing may override soft spacing. + last_spacing: LastSpacing, +} + impl LineRun { fn new() -> Self { Self { diff --git a/src/layout/mod.rs b/src/layout/mod.rs index 75d7b96b..52f7e0e6 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -46,7 +46,6 @@ pub async fn layout( }; let layouts = layout_tree(&tree, &mut ctx).await; - Pass::new(layouts, ctx.f) } @@ -177,12 +176,11 @@ pub enum Command { SetTextState(TextState), /// Update the page style. SetPageState(PageState), - - /// Update the alignment for future boxes added to this layouting process. - SetAlignment(LayoutAlign), /// Update the layouting system along which future boxes will be laid /// out. This ends the current line. SetSystem(LayoutSystem), + /// Update the alignment for future boxes added to this layouting process. + SetAlignment(LayoutAlign), } /// Defines how spacing interacts with surrounding spacing. @@ -211,26 +209,3 @@ impl SpacingKind { /// The standard spacing kind used for word spacing. pub const WORD: Self = Self::Soft(1); } - -/// The spacing kind of the most recently inserted item in a layouting process. -/// -/// Since the last inserted item may not be spacing at all, this can be `None`. -#[derive(Debug, Copy, Clone, PartialEq)] -enum LastSpacing { - /// The last item was hard spacing. - Hard, - /// The last item was soft spacing with the given width and level. - Soft(f64, u32), - /// The last item wasn't spacing. - None, -} - -impl LastSpacing { - /// The width of the soft space if this is a soft space or zero otherwise. - fn soft_or_zero(self) -> f64 { - match self { - LastSpacing::Soft(space, _) => space, - _ => 0.0, - } - } -} diff --git a/src/layout/stack.rs b/src/layout/stack.rs index e69dc071..dadc40b9 100644 --- a/src/layout/stack.rs +++ b/src/layout/stack.rs @@ -23,7 +23,9 @@ use super::*; /// Performs the stack layouting. pub struct StackLayouter { + /// The context used for stack layouting. ctx: StackContext, + /// The finished layouts. layouts: Vec<BoxLayout>, /// The in-progress space. space: Space, @@ -45,30 +47,6 @@ pub struct StackContext { pub repeat: bool, } -/// A layout space composed of subspaces which can have different systems and -/// alignments. -struct Space { - /// The index of this space in `ctx.spaces`. - index: usize, - /// Whether to include a layout for this space even if it would be empty. - hard: bool, - /// The so-far accumulated layouts. - layouts: Vec<(LayoutSystem, BoxLayout)>, - /// The specialized size of this space. - size: Size, - /// The specialized remaining space. - usable: Size, - /// The specialized extra-needed size to affect the size at all. - extra: Size, - /// Dictate which alignments for new boxes are still allowed and which - /// require a new space to be started. For example, after an `End`-aligned - /// item, no `Start`-aligned one can follow. - rulers: Sides<GenAlign>, - /// The spacing state. This influences how new spacing is handled, e.g. hard - /// spacing may override soft spacing. - last_spacing: LastSpacing, -} - impl StackLayouter { /// Create a new stack layouter. pub fn new(ctx: StackContext) -> Self { @@ -387,6 +365,30 @@ impl StackLayouter { } } +/// A layout space composed of subspaces which can have different systems and +/// alignments. +struct Space { + /// The index of this space in `ctx.spaces`. + index: usize, + /// Whether to include a layout for this space even if it would be empty. + hard: bool, + /// The so-far accumulated layouts. + layouts: Vec<(LayoutSystem, BoxLayout)>, + /// The specialized size of this space. + size: Size, + /// The specialized remaining space. + usable: Size, + /// The specialized extra-needed size to affect the size at all. + extra: Size, + /// Dictate which alignments for new boxes are still allowed and which + /// require a new space to be started. For example, after an `End`-aligned + /// item, no `Start`-aligned one can follow. + rulers: Sides<GenAlign>, + /// The spacing state. This influences how new spacing is handled, e.g. hard + /// spacing may override soft spacing. + last_spacing: LastSpacing, +} + impl Space { fn new(index: usize, hard: bool, usable: Size) -> Self { Self { @@ -401,3 +403,26 @@ impl Space { } } } + +/// The spacing kind of the most recently inserted item in a layouting process. +/// +/// Since the last inserted item may not be spacing at all, this can be `None`. +#[derive(Debug, Copy, Clone, PartialEq)] +pub(crate) enum LastSpacing { + /// The last item was hard spacing. + Hard, + /// The last item was soft spacing with the given width and level. + Soft(f64, u32), + /// The last item wasn't spacing. + None, +} + +impl LastSpacing { + /// The width of the soft space if this is a soft space or zero otherwise. + fn soft_or_zero(self) -> f64 { + match self { + LastSpacing::Soft(space, _) => space, + _ => 0.0, + } + } +} diff --git a/src/layout/tree.rs b/src/layout/tree.rs index 5468a7cd..4e15fb12 100644 --- a/src/layout/tree.rs +++ b/src/layout/tree.rs @@ -3,9 +3,7 @@ use super::*; use crate::eval::Eval; use crate::shaping; -use crate::syntax::{ - Deco, Expr, NodeHeading, NodeRaw, Span, SpanWith, Spanned, SynNode, SynTree, -}; +use crate::syntax::*; use crate::DynFuture; /// Layout a syntax tree in a given context. |
