mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
Ensure grids have at least the given amount of rows (#3644)
This commit is contained in:
parent
3fd06136c2
commit
fd2eb0ceb2
@ -847,15 +847,26 @@ impl CellGrid {
|
||||
}
|
||||
}
|
||||
|
||||
// If the user specified cells occupying less rows than the given rows,
|
||||
// we shall expand the grid so that it has at least the given amount of
|
||||
// rows.
|
||||
let Some(expected_total_cells) = c.checked_mul(tracks.y.len()) else {
|
||||
bail!(span, "too many rows were specified");
|
||||
};
|
||||
let missing_cells = expected_total_cells.saturating_sub(resolved_cells.len());
|
||||
|
||||
// Fixup phase (final step in cell grid generation):
|
||||
// 1. Replace absent entries by resolved empty cells, and produce a
|
||||
// vector of 'Entry' from 'Option<Entry>'.
|
||||
// 2. If any cells were added to the header's rows after the header's
|
||||
// 2. Add enough empty cells to the end of the grid such that it has at
|
||||
// least the given amount of rows.
|
||||
// 3. If any cells were added to the header's rows after the header's
|
||||
// creation, ensure the header expands enough to accommodate them
|
||||
// across all of their spanned rows. Same for the footer.
|
||||
// 3. If any cells before the footer try to span it, error.
|
||||
// 4. If any cells before the footer try to span it, error.
|
||||
let resolved_cells = resolved_cells
|
||||
.into_iter()
|
||||
.chain(std::iter::repeat_with(|| None).take(missing_cells))
|
||||
.enumerate()
|
||||
.map(|(i, cell)| {
|
||||
if let Some(cell) = cell {
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 9.1 KiB |
@ -28,3 +28,13 @@
|
||||
],
|
||||
align(top)[B],
|
||||
)
|
||||
|
||||
---
|
||||
// Ensure grids expand enough for the given rows.
|
||||
#grid(
|
||||
columns: (2em, 2em),
|
||||
rows: (2em,) * 4,
|
||||
fill: red,
|
||||
stroke: aqua,
|
||||
[a]
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user