skip headers and footers in cells with 'x: '

This commit is contained in:
PgBiel 2025-02-16 20:09:47 -03:00
parent fc56715ef6
commit 199bb7c56d
4 changed files with 61 additions and 7 deletions

View File

@ -1738,13 +1738,44 @@ fn resolve_cell_position(
// 'first_available_row'). Otherwise, start searching at the // 'first_available_row'). Otherwise, start searching at the
// first row. // first row.
let mut resolved_y = first_available_row; let mut resolved_y = first_available_row;
while let Some(Some(_)) = if header.is_some() || footer.is_some() {
resolved_cells.get(cell_index(cell_x, resolved_y)?) // There are row groups, so we have to not only skip
{ // rows where the requested column is occupied to find the
// Try each row until either we reach an absent position // first suitable row, but also skip rows belonging to
// (`Some(None)`) or an out of bounds position (`None`), // headers or footers.
// in which case we'd create a new row to place this cell in. loop {
resolved_y += 1; if let Some(Some(_)) =
resolved_cells.get(cell_index(cell_x, resolved_y)?)
{
// Try each row until either we reach an absent position
// (`Some(None)`) or an out of bounds position (`None`),
// in which case we'd create a new row to place this cell in.
resolved_y += 1;
} else if let Some(header) =
header.filter(|header| resolved_y < header.end)
{
// Skip header
resolved_y = header.end;
} else if let Some((footer_end, _, _)) =
footer.filter(|(end, _, footer)| {
resolved_y >= footer.start && resolved_y < *end
})
{
// Skip footer
resolved_y = *footer_end;
} else {
break;
}
}
} else {
// No row groups to skip, so only skip a row if the
// requested column is occupied, and find the first row
// where it isn't.
while let Some(Some(_)) =
resolved_cells.get(cell_index(cell_x, resolved_y)?)
{
resolved_y += 1;
}
} }
cell_index(cell_x, resolved_y) cell_index(cell_x, resolved_y)
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 419 B

View File

@ -83,6 +83,18 @@
grid.cell(y: 1)[c], grid.cell(y: 1)[c],
) )
--- grid-footer-cell-with-x ---
#grid(
columns: 2,
stroke: black,
inset: 5pt,
grid.cell(x: 1)[a],
// Error: 3-56 footer must end at the last row
grid.footer(grid.cell(x: 0)[b1], grid.cell(x: 0)[b2]),
// This should skip the footer
grid.cell(x: 1)[c]
)
--- grid-footer-expand --- --- grid-footer-expand ---
// Ensure footer properly expands // Ensure footer properly expands
#grid( #grid(

View File

@ -60,6 +60,17 @@
grid.cell(y: 2)[c] grid.cell(y: 2)[c]
) )
--- grid-header-cell-with-x ---
#grid(
columns: 2,
stroke: black,
inset: 5pt,
// grid.cell(x: 1)[a],
grid.header(grid.cell(x: 0)[b1], grid.cell(x: 0)[b2]),
// This should skip the header
grid.cell(x: 1)[c]
)
--- grid-header-last-child --- --- grid-header-last-child ---
// When the header is the last grid child, it shouldn't include the gutter row // When the header is the last grid child, it shouldn't include the gutter row
// after it, because there is none. // after it, because there is none.