More optimization

This commit is contained in:
Emil Ernerfeldt 2022-03-31 14:19:10 +02:00
parent dc8c5aaa2b
commit c2a0f64c81

View file

@ -80,7 +80,7 @@ impl<'a> StripBuilder<'a> {
strip(Strip { strip(Strip {
layout: &mut layout, layout: &mut layout,
direction: CellDirection::Horizontal, direction: CellDirection::Horizontal,
sizes: widths, sizes: &widths,
}); });
layout.allocate_rect() layout.allocate_rect()
} }
@ -101,7 +101,7 @@ impl<'a> StripBuilder<'a> {
strip(Strip { strip(Strip {
layout: &mut layout, layout: &mut layout,
direction: CellDirection::Vertical, direction: CellDirection::Vertical,
sizes: heights, sizes: &heights,
}); });
layout.allocate_rect() layout.allocate_rect()
} }
@ -112,20 +112,17 @@ impl<'a> StripBuilder<'a> {
pub struct Strip<'a, 'b> { pub struct Strip<'a, 'b> {
layout: &'b mut StripLayout<'a>, layout: &'b mut StripLayout<'a>,
direction: CellDirection, direction: CellDirection,
sizes: Vec<f32>, sizes: &'b [f32],
} }
impl<'a, 'b> Strip<'a, 'b> { impl<'a, 'b> Strip<'a, 'b> {
fn next_cell_size(&mut self) -> (CellSize, CellSize) { fn next_cell_size(&mut self) -> (CellSize, CellSize) {
let size = self.sizes[0];
self.sizes = &self.sizes[1..];
match self.direction { match self.direction {
CellDirection::Horizontal => ( CellDirection::Horizontal => (CellSize::Absolute(size), CellSize::Remainder),
CellSize::Absolute(self.sizes.remove(0)), CellDirection::Vertical => (CellSize::Remainder, CellSize::Absolute(size)),
CellSize::Remainder,
),
CellDirection::Vertical => (
CellSize::Remainder,
CellSize::Absolute(self.sizes.remove(0)),
),
} }
} }