diff options
| author | Laurenz <laurmaedje@gmail.com> | 2019-11-16 10:37:30 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2019-11-16 10:37:30 +0100 |
| commit | 261ef9e33a8548d4b7aa53e69e71866648982ae8 (patch) | |
| tree | 8c98eeb4a4bb2123b45baf1dd4de706a21d619e9 /src/layout/stacked.rs | |
| parent | 0917d89bb899380ba897382b4945c8426f25c66d (diff) | |
Generalize tree layouter 🌲
Diffstat (limited to 'src/layout/stacked.rs')
| -rw-r--r-- | src/layout/stacked.rs | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/src/layout/stacked.rs b/src/layout/stacked.rs index 419ec6b7..cc6caa5e 100644 --- a/src/layout/stacked.rs +++ b/src/layout/stacked.rs @@ -1,3 +1,4 @@ +use smallvec::smallvec; use super::*; /// Layouts boxes stack-like. @@ -66,7 +67,7 @@ impl StackLayouter { } /// Add multiple sublayouts from a multi-layout. - pub fn add_many(&mut self, layouts: MultiLayout) -> LayoutResult<()> { + pub fn add_multiple(&mut self, layouts: MultiLayout) -> LayoutResult<()> { for layout in layouts { self.add(layout)?; } @@ -135,7 +136,7 @@ impl StackLayouter { /// finishing this stack. Otherwise, the new layout only appears if new /// content is added to it. fn start_new_space(&mut self, include_empty: bool) { - self.active_space = (self.active_space + 1).min(self.ctx.spaces.len() - 1); + self.active_space = self.next_space(); self.usable = self.ctx.spaces[self.active_space].usable().generalized(self.ctx.axes); self.dimensions = start_dimensions(self.usable, self.ctx.axes); self.include_empty = include_empty; @@ -151,10 +152,20 @@ impl StackLayouter { self.usable } - /// The (specialized) remaining area for new layouts in the current space. - pub fn remaining(&self) -> Size2D { - Size2D::new(self.usable.x, self.usable.y - self.dimensions.y) - .specialized(self.ctx.axes) + /// The remaining spaces for new layouts in the current space. + pub fn remaining(&self, shrink_to_fit: bool) -> LayoutSpaces { + let mut spaces = smallvec![LayoutSpace { + dimensions: Size2D::new(self.usable.x, self.usable.y - self.dimensions.y) + .specialized(self.ctx.axes), + padding: SizeBox::zero(), + shrink_to_fit, + }]; + + for space in &self.ctx.spaces[self.next_space()..] { + spaces.push(space.usable_space(shrink_to_fit)); + } + + spaces } /// Whether this layouter is in its last space. @@ -162,6 +173,10 @@ impl StackLayouter { self.active_space == self.ctx.spaces.len() - 1 } + fn next_space(&self) -> usize { + (self.active_space + 1).min(self.ctx.spaces.len() - 1) + } + /// The combined size of the so-far included boxes with the other size. fn size_with(&self, other: Size2D) -> Size2D { Size2D { |
