From f22f9513aea21408ebf6febd01912e630e9ad5e6 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Thu, 17 Oct 2019 10:12:34 +0200 Subject: =?UTF-8?q?Add=20pagebreak=20function=20=E2=8F=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layout/flex.rs | 4 +++- src/layout/stacked.rs | 1 + src/layout/tree.rs | 18 +++++++++++++++--- 3 files changed, 19 insertions(+), 4 deletions(-) (limited to 'src/layout') diff --git a/src/layout/flex.rs b/src/layout/flex.rs index 98cca2f9..39c16aef 100644 --- a/src/layout/flex.rs +++ b/src/layout/flex.rs @@ -17,6 +17,7 @@ use super::*; /// flows into a new line. A _glue_ layout is typically used for a space character /// since it prevents a space from appearing in the beginning or end of a line. /// However, it can be any layout. +#[derive(Debug, Clone)] pub struct FlexLayouter { ctx: FlexContext, units: Vec, @@ -64,6 +65,7 @@ impl FlexContext { } } +#[derive(Debug, Clone)] enum FlexUnit { /// A content unit to be arranged flexibly. Boxed(Layout), @@ -73,6 +75,7 @@ enum FlexUnit { Glue(Size2D), } +#[derive(Debug, Clone)] struct FlexRun { content: Vec<(Size, Layout)>, size: Size2D, @@ -168,7 +171,6 @@ impl FlexLayouter { } fn layout_glue(&mut self, glue: Size2D) { - self.flush_glue(); self.cached_glue = Some(glue); } diff --git a/src/layout/stacked.rs b/src/layout/stacked.rs index 0b7bfd4f..d87e5394 100644 --- a/src/layout/stacked.rs +++ b/src/layout/stacked.rs @@ -3,6 +3,7 @@ use super::*; /// Layouts boxes stack-like. /// /// The boxes are arranged vertically, each layout gettings it's own "line". +#[derive(Debug, Clone)] pub struct StackLayouter { ctx: StackContext, layouts: MultiLayout, 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 { 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(); + } } } -- cgit v1.2.3