diff options
| author | Laurenz <laurmaedje@gmail.com> | 2019-11-18 12:57:14 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2019-11-18 12:57:14 +0100 |
| commit | 1eb25f86dd6763c4f2d7e60b6d09af60ada50af6 (patch) | |
| tree | 104c16bc4ec779d8b5eeca819f6357af6c5a0d7a /src/layout/tree.rs | |
| parent | 14259c7d09c12327b18aba21cc577e68ad283eda (diff) | |
Double-try spaces for functions 🌑🌕
Diffstat (limited to 'src/layout/tree.rs')
| -rw-r--r-- | src/layout/tree.rs | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/layout/tree.rs b/src/layout/tree.rs index b60ead9c..177a6308 100644 --- a/src/layout/tree.rs +++ b/src/layout/tree.rs @@ -65,12 +65,24 @@ impl<'a, 'p> TreeLayouter<'a, 'p> { /// Layout a function. fn layout_func(&mut self, func: &FuncCall) -> LayoutResult<()> { - let commands = func.body.val.layout(LayoutContext { + let (flex_spaces, stack_spaces) = self.flex.remaining()?; + + let ctx = |spaces| LayoutContext { style: &self.style, - spaces: self.flex.remaining()?, + spaces: spaces, shrink_to_fit: true, .. self.ctx - })?; + }; + + // Try putting it in the flex space first, but if that is not enough + // space, use the other space. + let commands = match func.body.val.layout(ctx(flex_spaces)) { + Ok(c) => c, + Err(LayoutError::NotEnoughSpace(_)) => { + func.body.val.layout(ctx(stack_spaces))? + }, + e => e?, + }; for command in commands { self.execute(command)?; |
