From 1dafe2c2ea0828bb075fdbb0da663967f7b5b2b9 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Tue, 19 Nov 2019 23:27:56 +0100 Subject: =?UTF-8?q?First=20half=20of=20flex=20refactoring=20=F0=9F=A5=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layout/tree.rs | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'src/layout/tree.rs') diff --git a/src/layout/tree.rs b/src/layout/tree.rs index 94b8553c..f7526500 100644 --- a/src/layout/tree.rs +++ b/src/layout/tree.rs @@ -42,13 +42,13 @@ impl<'a, 'p> TreeLayouter<'a, 'p> { } Node::Space => { - if !self.flex.box_is_empty() && !self.flex.last_is_space() { + if !self.flex.run_is_empty() && !self.flex.run_last_is_space() { let space = self.style.word_spacing * self.style.font_size; - self.flex.add_primary_space(space); + self.flex.add_primary_space(space, true); } } Node::Newline => { - if !self.flex.box_is_empty() { + if !self.flex.run_is_empty() { self.break_paragraph()?; } } @@ -71,7 +71,7 @@ impl<'a, 'p> TreeLayouter<'a, 'p> { let ctx = |spaces| LayoutContext { top_level: false, text_style: &self.style, - spaces: spaces, + spaces, shrink_to_fit: true, .. self.ctx }; @@ -100,12 +100,12 @@ impl<'a, 'p> TreeLayouter<'a, 'p> { Command::Add(layout) => self.flex.add(layout), Command::AddMultiple(layouts) => self.flex.add_multiple(layouts), - Command::AddPrimarySpace(space) => self.flex.add_primary_space(space), + Command::AddPrimarySpace(space) => self.flex.add_primary_space(space, false), Command::AddSecondarySpace(space) => self.flex.add_secondary_space(space)?, - Command::FinishRun => self.flex.add_run_break(), - Command::FinishBox => self.flex.finish_box()?, - Command::FinishLayout => self.flex.finish_layout(true)?, + Command::FinishLine => self.flex.add_break(), + Command::FinishRun => self.flex.finish_run()?, + Command::FinishSpace => self.flex.finish_space(true)?, Command::BreakParagraph => self.break_paragraph()?, @@ -140,9 +140,7 @@ impl<'a, 'p> TreeLayouter<'a, 'p> { /// Finish the current flex layout and add space after it. fn break_paragraph(&mut self) -> LayoutResult<()> { - self.flex.finish_box()?; - self.flex.add_secondary_space(paragraph_spacing(&self.style))?; - Ok(()) + self.flex.add_secondary_space(paragraph_spacing(&self.style)) } } -- cgit v1.2.3