mirror of
https://github.com/typst/typst
synced 2025-05-13 12:36:23 +08:00
Skip grid region if one cell is empty
This commit is contained in:
parent
e873468ea7
commit
8951b1923a
@ -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() {
|
||||
|
BIN
tests/ref/bugs/grid-2.png
Normal file
BIN
tests/ref/bugs/grid-2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.7 KiB |
Binary file not shown.
Before Width: | Height: | Size: 43 KiB After Width: | Height: | Size: 43 KiB |
18
tests/typ/bugs/grid-2.typ
Normal file
18
tests/typ/bugs/grid-2.typ
Normal file
@ -0,0 +1,18 @@
|
||||
// Grid now skips a remaining region when one of the cells
|
||||
// doesn't fit into it at all.
|
||||
|
||||
---
|
||||
#set page(height: 100pt)
|
||||
#grid(
|
||||
columns: (2cm, auto),
|
||||
rows: (auto, auto),
|
||||
rect(width: 100%, fill: red),
|
||||
rect(width: 100%, fill: blue),
|
||||
rect(width: 100%, height: 80%, fill: green),
|
||||
[Hello],
|
||||
)
|
||||
|
||||
---
|
||||
#set page(height: 60pt)
|
||||
#lorem(5)
|
||||
- #lorem(5)
|
Loading…
x
Reference in New Issue
Block a user