diff options
| author | Laurenz <laurmaedje@gmail.com> | 2019-10-16 21:58:22 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2019-10-16 21:58:22 +0200 |
| commit | 58693486f97ddbb34595efa1a81a4e7b1d3204c9 (patch) | |
| tree | 4e8c066928361df07d238c00c1cea997c4cdabc9 /src/layout/stacked.rs | |
| parent | f2f05e07b0ff2d98e3c822b2618d02281ed1078c (diff) | |
Allow center alignment 📐
Diffstat (limited to 'src/layout/stacked.rs')
| -rw-r--r-- | src/layout/stacked.rs | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/layout/stacked.rs b/src/layout/stacked.rs index 367a03d7..3a29f722 100644 --- a/src/layout/stacked.rs +++ b/src/layout/stacked.rs @@ -73,6 +73,7 @@ impl StackLayouter { let position = match self.space.alignment { Alignment::Left => self.cursor, Alignment::Right => self.cursor - Size2D::with_x(layout.dimensions.x), + Alignment::Center => self.cursor - Size2D::with_x(layout.dimensions.x / 2), }; self.cursor.y += layout.dimensions.y; @@ -172,9 +173,9 @@ impl StackLayouter { } } - /// Whether this layouter contains any items. - pub fn is_empty(&self) -> bool { - self.layouts.is_empty() && self.actions.is_empty() + /// Whether the active space of this layouter contains no content. + pub fn current_space_is_empty(&self) -> bool { + !self.started || self.actions.is_empty() } fn overflows(&self, dimensions: Size2D) -> bool { @@ -185,7 +186,7 @@ impl StackLayouter { fn start_dimensions(space: LayoutSpace) -> Size2D { match space.alignment { Alignment::Left => Size2D::zero(), - Alignment::Right => Size2D::with_x(space.usable().x), + Alignment::Right | Alignment::Center => Size2D::with_x(space.usable().x), } } @@ -197,6 +198,7 @@ fn start_cursor(space: LayoutSpace) -> Size2D { x: match space.alignment { Alignment::Left => space.padding.left, Alignment::Right => space.dimensions.x - space.padding.right, + Alignment::Center => space.padding.left + (space.usable().x / 2), }, y: space.padding.top, } |
