summaryrefslogtreecommitdiff
path: root/src/layout
diff options
context:
space:
mode:
Diffstat (limited to 'src/layout')
-rw-r--r--src/layout/flex.rs4
-rw-r--r--src/layout/stacked.rs1
-rw-r--r--src/layout/tree.rs18
3 files changed, 19 insertions, 4 deletions
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<FlexUnit>,
@@ -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<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();
+ }
}
}