From 6b6cdae7ce95681d6a1194be70b375494166a8c6 Mon Sep 17 00:00:00 2001 From: Martin Haug Date: Sun, 27 Jun 2021 12:28:40 +0200 Subject: Testing for incremental Also, constraint bugfixes. --- src/layout/par.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src/layout/par.rs') diff --git a/src/layout/par.rs b/src/layout/par.rs index 2208f9ee..0cf1cd23 100644 --- a/src/layout/par.rs +++ b/src/layout/par.rs @@ -213,10 +213,18 @@ impl<'a> ParLayouter<'a> { while !stack.regions.current.height.fits(line.size.height) && !stack.regions.in_full_last() { - stack.constraints.max.vertical.set_min(line.size.height); + stack.constraints.max.vertical.set_min( + stack.full.height - stack.regions.current.height + line.size.height, + ); stack.finish_region(ctx); } + if !stack.regions.current.height.fits(line.size.height) + && stack.regions.in_full_last() + { + stack.overflowing = true; + } + // If the line does not fit horizontally or we have a mandatory // line break (i.e. due to "\n"), we push the line into the // stack. @@ -303,11 +311,13 @@ impl ParItem<'_> { /// Stacks lines on top of each other. struct LineStack<'a> { line_spacing: Length, + full: Size, regions: Regions, size: Size, lines: Vec>, finished: Vec>>, constraints: Constraints, + overflowing: bool, } impl<'a> LineStack<'a> { @@ -316,10 +326,12 @@ impl<'a> LineStack<'a> { Self { line_spacing, constraints: Constraints::new(regions.expand), + full: regions.current, regions, size: Size::zero(), lines: vec![], finished: vec![], + overflowing: false, } } @@ -343,6 +355,12 @@ impl<'a> LineStack<'a> { self.constraints.exact.horizontal = Some(self.regions.current.width); } + if self.overflowing { + self.constraints.min.vertical = None; + self.constraints.max.vertical = None; + self.constraints.exact = self.full.to_spec().map(Some); + } + let mut output = Frame::new(self.size, self.size.height); let mut offset = Length::zero(); let mut first = true; @@ -362,6 +380,7 @@ impl<'a> LineStack<'a> { self.finished.push(output.constrain(self.constraints)); self.regions.next(); + self.full = self.regions.current; self.constraints = Constraints::new(self.regions.expand); self.size = Size::zero(); } -- cgit v1.2.3 From 57bd3e23c79878d106ab8be17c71caca6c4f5a7c Mon Sep 17 00:00:00 2001 From: Martin Date: Sun, 27 Jun 2021 17:08:40 +0200 Subject: Apply suggestions from code review Co-authored-by: Laurenz --- src/layout/par.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src/layout/par.rs') diff --git a/src/layout/par.rs b/src/layout/par.rs index 0cf1cd23..40cb84f2 100644 --- a/src/layout/par.rs +++ b/src/layout/par.rs @@ -219,12 +219,18 @@ impl<'a> ParLayouter<'a> { stack.finish_region(ctx); } - if !stack.regions.current.height.fits(line.size.height) - && stack.regions.in_full_last() - { - stack.overflowing = true; + // If the line does not fit vertically, we start a new region. + while !stack.regions.current.height.fits(line.size.height) { + if stack.regions.in_full_last() { + stack.overflowing = true; + break; + } + + stack.constraints.max.vertical.set_min( + stack.full.height - stack.regions.current.height + line.size.height, + ); + stack.finish_region(ctx); } - // If the line does not fit horizontally or we have a mandatory // line break (i.e. due to "\n"), we push the line into the // stack. -- cgit v1.2.3 From 9bd8b7ddac046f581dc750e148147901d08cb0f4 Mon Sep 17 00:00:00 2001 From: Martin Haug Date: Sun, 27 Jun 2021 18:06:39 +0200 Subject: Code review, new stack test --- src/layout/par.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/layout/par.rs') diff --git a/src/layout/par.rs b/src/layout/par.rs index 40cb84f2..504981e6 100644 --- a/src/layout/par.rs +++ b/src/layout/par.rs @@ -190,6 +190,7 @@ impl<'a> ParLayouter<'a> { // line cannot be broken up further. if !stack.regions.current.fits(line.size) { if let Some((last_line, last_end)) = last.take() { + // The region must not fit this line for the result to be valid. if !stack.regions.current.width.fits(line.size.width) { stack.constraints.max.horizontal.set_min(line.size.width); } @@ -213,6 +214,9 @@ impl<'a> ParLayouter<'a> { while !stack.regions.current.height.fits(line.size.height) && !stack.regions.in_full_last() { + // Again, the line must not fit. It would if the space taken up + // plus the line height would fit, therefore the constraint + // below. stack.constraints.max.vertical.set_min( stack.full.height - stack.regions.current.height + line.size.height, ); @@ -225,7 +229,7 @@ impl<'a> ParLayouter<'a> { stack.overflowing = true; break; } - + stack.constraints.max.vertical.set_min( stack.full.height - stack.regions.current.height + line.size.height, ); -- cgit v1.2.3 From e9960b89424ab67e633076ccc9f8c420316b076a Mon Sep 17 00:00:00 2001 From: Martin Haug Date: Sun, 27 Jun 2021 18:57:08 +0200 Subject: Code review: Reverse temperature --- src/layout/par.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/layout/par.rs') diff --git a/src/layout/par.rs b/src/layout/par.rs index 504981e6..45eefe29 100644 --- a/src/layout/par.rs +++ b/src/layout/par.rs @@ -217,9 +217,11 @@ impl<'a> ParLayouter<'a> { // Again, the line must not fit. It would if the space taken up // plus the line height would fit, therefore the constraint // below. - stack.constraints.max.vertical.set_min( - stack.full.height - stack.regions.current.height + line.size.height, - ); + stack + .constraints + .max + .vertical + .set_min(stack.size.height + line.size.height); stack.finish_region(ctx); } @@ -230,9 +232,11 @@ impl<'a> ParLayouter<'a> { break; } - stack.constraints.max.vertical.set_min( - stack.full.height - stack.regions.current.height + line.size.height, - ); + stack + .constraints + .max + .vertical + .set_min(stack.size.height + line.size.height); stack.finish_region(ctx); } // If the line does not fit horizontally or we have a mandatory -- cgit v1.2.3