diff options
| author | Laurenz <laurmaedje@gmail.com> | 2020-10-12 17:29:01 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2020-10-12 17:29:01 +0200 |
| commit | 5243878d810d4817c81acc9ae346d46757fcf602 (patch) | |
| tree | 4a8be00ab7262030a6ba8c6638b969a03ac1d9b5 /src/layout/mod.rs | |
| parent | 38157b0e0cbab22dc3f5fa5cc66d9b673a18a55b (diff) | |
Less vecs in layouting ⚡
Diffstat (limited to 'src/layout/mod.rs')
| -rw-r--r-- | src/layout/mod.rs | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/layout/mod.rs b/src/layout/mod.rs index 643f1a43..de112083 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -38,7 +38,7 @@ pub struct LayoutContext { /// Layout a node. pub trait Layout { /// Layout the node in the given layout context. - fn layout(&self, ctx: &mut LayoutContext, areas: &Areas) -> Vec<Layouted>; + fn layout(&self, ctx: &mut LayoutContext, areas: &Areas) -> Layouted; } /// A sequence of areas to layout into. @@ -129,14 +129,17 @@ pub enum Layouted { Spacing(Length), /// A box that should be added to and aligned in the parent. Boxed(BoxLayout, Gen<Align>), + /// Multiple boxes. + Boxes(Vec<(BoxLayout, Gen<Align>)>), } impl Layouted { /// Return the box if this if its a box variant. - pub fn into_boxed(self) -> Option<BoxLayout> { + pub fn into_boxes(self) -> Vec<BoxLayout> { match self { - Self::Spacing(_) => None, - Self::Boxed(boxed, _) => Some(boxed), + Self::Spacing(_) => vec![], + Self::Boxed(boxed, _) => vec![boxed], + Self::Boxes(boxes) => boxes.into_iter().map(|p| p.0).collect(), } } } |
