diff options
| author | Laurenz <laurmaedje@gmail.com> | 2023-02-12 12:15:03 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2023-02-12 12:57:35 +0100 |
| commit | 8951b1923a581f7454ddf4dbe3e55f69ce5799f9 (patch) | |
| tree | 86ba96f9f83ca3983bddf13ad37df2469877720d /library | |
| parent | e873468ea7deedd6d43f24100591c60a7de5accc (diff) | |
Skip grid region if one cell is empty
Diffstat (limited to 'library')
| -rw-r--r-- | library/src/layout/grid.rs | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/library/src/layout/grid.rs b/library/src/layout/grid.rs index 46518f82..544b76ed 100644 --- a/library/src/layout/grid.rs +++ b/library/src/layout/grid.rs @@ -482,6 +482,7 @@ impl<'a, 'v> GridLayouter<'a, 'v> { /// regions. fn layout_auto_row(&mut self, y: usize) -> SourceResult<()> { let mut resolved: Vec<Abs> = vec![]; + let mut skip = false; // Determine the size for each region of the row. for (x, &rcol) in self.rcols.iter().enumerate() { @@ -490,13 +491,15 @@ impl<'a, 'v> GridLayouter<'a, 'v> { pod.first.x = rcol; pod.base.x = rcol; - let mut sizes = cell - .layout(self.vt, self.styles, pod)? - .into_iter() - .map(|frame| frame.height()); + let frames = cell.layout(self.vt, self.styles, pod)?.into_frames(); + if let [first, rest @ ..] = frames.as_slice() { + skip |= + first.is_empty() && rest.iter().any(|frame| !frame.is_empty()); + } // For each region, we want to know the maximum height any // column requires. + let mut sizes = frames.iter().map(|frame| frame.height()); for (target, size) in resolved.iter_mut().zip(&mut sizes) { target.set_max(size); } @@ -519,6 +522,12 @@ impl<'a, 'v> GridLayouter<'a, 'v> { return Ok(()); } + // Skip the first region if it's empty for some cell. + if skip && !self.regions.in_last() { + self.finish_region()?; + resolved.remove(0); + } + // Expand all but the last region if the space is not // eaten up by any fr rows. if self.fr.is_zero() { |
