summaryrefslogtreecommitdiff
path: root/src/layout/tree.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2019-11-18 12:57:14 +0100
committerLaurenz <laurmaedje@gmail.com>2019-11-18 12:57:14 +0100
commit1eb25f86dd6763c4f2d7e60b6d09af60ada50af6 (patch)
tree104c16bc4ec779d8b5eeca819f6357af6c5a0d7a /src/layout/tree.rs
parent14259c7d09c12327b18aba21cc577e68ad283eda (diff)
Double-try spaces for functions 🌑🌕
Diffstat (limited to 'src/layout/tree.rs')
-rw-r--r--src/layout/tree.rs18
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)?;