diff options
| author | Laurenz <laurmaedje@gmail.com> | 2019-10-16 22:32:40 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2019-10-16 22:32:40 +0200 |
| commit | e87a34a4d0bf967427e2443f9f48026d09ccd5db (patch) | |
| tree | d1163980613526f9b211c710a9bb52b2893f0839 /src/layout/tree.rs | |
| parent | 58693486f97ddbb34595efa1a81a4e7b1d3204c9 (diff) | |
Rearrange layouting contexts ♻
Diffstat (limited to 'src/layout/tree.rs')
| -rw-r--r-- | src/layout/tree.rs | 29 |
1 files changed, 8 insertions, 21 deletions
diff --git a/src/layout/tree.rs b/src/layout/tree.rs index 7feed610..a1918ded 100644 --- a/src/layout/tree.rs +++ b/src/layout/tree.rs @@ -19,14 +19,12 @@ impl<'a, 'p> TreeLayouter<'a, 'p> { fn new(ctx: LayoutContext<'a, 'p>) -> TreeLayouter<'a, 'p> { TreeLayouter { ctx, - stack: StackLayouter::new(StackContext { - space: ctx.space, - extra_space: ctx.extra_space - }), + stack: StackLayouter::new(StackContext::from_layout_ctx(ctx)), flex: FlexLayouter::new(FlexContext { - space: flex_space(ctx.space), - extra_space: ctx.extra_space.map(|s| flex_space(s)), - flex_spacing: flex_spacing(&ctx.style), + space: ctx.space.usable_space(), + followup_spaces: ctx.followup_spaces.map(|s| s.usable_space()), + shrink_to_fit: true, + .. FlexContext::from_layout_ctx(ctx, flex_spacing(&ctx.style)) }), style: Cow::Borrowed(ctx.style), } @@ -119,15 +117,13 @@ impl<'a, 'p> TreeLayouter<'a, 'p> { fn layout_func(&mut self, func: &FuncCall) -> LayoutResult<()> { let mut ctx = self.ctx; ctx.style = &self.style; + ctx.shrink_to_fit = true; ctx.space.dimensions = self.stack.remaining(); ctx.space.padding = SizeBox::zero(); - ctx.space.shrink_to_fit = true; - if let Some(space) = ctx.extra_space.as_mut() { - space.dimensions = space.usable(); - space.padding = SizeBox::zero(); - space.shrink_to_fit = true; + if let Some(space) = ctx.followup_spaces.as_mut() { + *space = space.usable_space(); } let commands = func.body.layout(ctx)?; @@ -145,15 +141,6 @@ impl<'a, 'p> TreeLayouter<'a, 'p> { } } -fn flex_space(space: LayoutSpace) -> LayoutSpace { - LayoutSpace { - dimensions: space.usable(), - padding: SizeBox::zero(), - alignment: space.alignment, - shrink_to_fit: true, - } -} - fn flex_spacing(style: &TextStyle) -> Size { (style.line_spacing - 1.0) * Size::pt(style.font_size) } |
