summaryrefslogtreecommitdiff
path: root/src/layout/tree.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2019-10-17 10:12:34 +0200
committerLaurenz <laurmaedje@gmail.com>2019-10-17 10:12:34 +0200
commitf22f9513aea21408ebf6febd01912e630e9ad5e6 (patch)
tree06885bca8bc31d26189f33c059649ed7909af282 /src/layout/tree.rs
parent9a1d57a11a510b8e6af024b4338ee58d791f3088 (diff)
Add pagebreak function ⏭
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 d125bc84..bd4adb8a 100644
--- a/src/layout/tree.rs
+++ b/src/layout/tree.rs
@@ -7,6 +7,7 @@ pub fn layout_tree(tree: &SyntaxTree, ctx: LayoutContext) -> LayoutResult<MultiL
layouter.finish()
}
+#[derive(Debug, Clone)]
struct TreeLayouter<'a, 'p> {
ctx: LayoutContext<'a, 'p>,
stack: StackLayouter,
@@ -85,13 +86,18 @@ impl<'a, 'p> TreeLayouter<'a, 'p> {
/// Layout a function.
fn layout_func(&mut self, func: &FuncCall) -> LayoutResult<()> {
+ // Finish the current flex layout on a copy to find out how
+ // much space would be remaining if we finished.
+ let mut lookahead_stack = self.stack.clone();
+ let layouts = self.flex.clone().finish()?;
+ lookahead_stack.add_many(layouts)?;
+ let remaining = lookahead_stack.remaining();
+
let mut ctx = self.ctx;
ctx.style = &self.style;
ctx.shrink_to_fit = true;
-
- ctx.space.dimensions = self.stack.remaining();
+ ctx.space.dimensions = remaining;
ctx.space.padding = SizeBox::zero();
-
if let Some(space) = ctx.followup_spaces.as_mut() {
*space = space.usable_space();
}
@@ -127,6 +133,12 @@ impl<'a, 'p> TreeLayouter<'a, 'p> {
Command::SetStyle(style) => {
*self.style.to_mut() = style;
}
+
+ Command::FinishLayout => {
+ self.finish_flex()?;
+ self.stack.finish_layout(true)?;
+ self.start_new_flex();
+ }
}
}