From 335fa2d118718b4dba539294a8ef6c96c5bbf09e Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sun, 4 Oct 2020 23:31:35 +0200 Subject: =?UTF-8?q?Small=20improvements=20=F0=9F=8D=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layout/stack.rs | 73 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 49 insertions(+), 24 deletions(-) (limited to 'src/layout/stack.rs') 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, /// 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, - /// 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, + /// 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, + } + } +} -- cgit v1.2.3