From 5243878d810d4817c81acc9ae346d46757fcf602 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Mon, 12 Oct 2020 17:29:01 +0200 Subject: =?UTF-8?q?Less=20vecs=20in=20layouting=20=E2=9A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layout/stack.rs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'src/layout/stack.rs') diff --git a/src/layout/stack.rs b/src/layout/stack.rs index 9aeb80aa..228293bc 100644 --- a/src/layout/stack.rs +++ b/src/layout/stack.rs @@ -17,17 +17,20 @@ pub struct Stack { } impl Layout for Stack { - fn layout(&self, ctx: &mut LayoutContext, areas: &Areas) -> Vec { + fn layout(&self, ctx: &mut LayoutContext, areas: &Areas) -> Layouted { let mut layouter = StackLayouter::new(self, areas.clone()); for child in &self.children { - for layouted in child.layout(ctx, &layouter.areas) { - match layouted { - Layouted::Spacing(spacing) => layouter.spacing(spacing), - Layouted::Boxed(boxed, aligns) => layouter.boxed(boxed, aligns), + match child.layout(ctx, &layouter.areas) { + Layouted::Spacing(spacing) => layouter.spacing(spacing), + Layouted::Boxed(boxed, aligns) => layouter.boxed(boxed, aligns), + Layouted::Boxes(boxes) => { + for (boxed, aligns) in boxes { + layouter.boxed(boxed, aligns); + } } } } - layouter.finish() + Layouted::Boxes(layouter.finish()) } } @@ -42,7 +45,7 @@ struct StackLayouter<'a> { main: SpecAxis, dirs: Gen, areas: Areas, - layouted: Vec, + layouted: Vec<(BoxLayout, Gen)>, boxes: Vec<(Length, BoxLayout, Gen)>, used: Gen, ruler: Align, @@ -134,14 +137,14 @@ impl<'a> StackLayouter<'a> { output.push_layout(pos, layout); } - self.layouted.push(Layouted::Boxed(output, self.stack.aligns)); + self.layouted.push((output, self.stack.aligns)); self.areas.next(); self.used = Gen::ZERO; self.ruler = Align::Start; } - fn finish(mut self) -> Vec { + fn finish(mut self) -> Vec<(BoxLayout, Gen)> { self.finish_area(); self.layouted } -- cgit v1.2.3