Refactor grid header and footer resolving (#5919)

This commit is contained in:
PgBiel 2025-03-24 17:42:48 -03:00 committed by GitHub
parent 1e591ac8dc
commit 1f1c133878
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 1496 additions and 821 deletions

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 365 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 385 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 579 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 419 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 674 B

View File

@ -83,12 +83,55 @@
grid.cell(y: 1)[c],
)
--- grid-footer-expand ---
// Ensure footer properly expands
--- 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-no-expand-with-col-and-row-pos-cell ---
#grid(
columns: 2,
[a], [],
[b], [],
fill: (_, y) => if calc.odd(y) { blue } else { red },
inset: 5pt,
grid.cell(x: 1, y: 3, rowspan: 4)[b],
grid.cell(y: 2, rowspan: 2)[a],
grid.footer(),
// Error: 3-27 cell would conflict with footer spanning the same position
// Hint: 3-27 try reducing the cell's rowspan or moving the footer
grid.cell(x: 1, y: 7)[d],
)
--- grid-footer-no-expand-with-row-pos-cell ---
#grid(
columns: 2,
[a], [],
[b], [],
fill: (_, y) => if calc.odd(y) { blue } else { red },
inset: 5pt,
grid.cell(x: 1, y: 3, rowspan: 4)[b],
grid.cell(y: 2, rowspan: 2)[a],
grid.footer(),
// Error: 3-33 cell would conflict with footer spanning the same position
// Hint: 3-33 try reducing the cell's rowspan or moving the footer
grid.cell(y: 6, rowspan: 2)[d],
)
--- grid-footer-moved-to-bottom-of-rowspans ---
#grid(
columns: 2,
[a], [],
[b], [],
stroke: red,
inset: 5pt,
grid.cell(x: 1, y: 3, rowspan: 4)[b],
grid.cell(y: 2, rowspan: 2)[a],
grid.footer(),
@ -113,13 +156,13 @@
)
--- grid-footer-overlap ---
// Error: 4:3-4:19 footer would conflict with a cell placed before it at column 1 row 0
// Hint: 4:3-4:19 try reducing that cell's rowspan or moving the footer
#grid(
columns: 2,
grid.header(),
grid.footer([a]),
grid.cell(x: 1, y: 0, rowspan: 2)[a],
grid.footer(grid.cell(y: 2)[a]),
// Error: 3-39 cell would conflict with footer spanning the same position
// Hint: 3-39 try reducing the cell's rowspan or moving the footer
grid.cell(x: 1, y: 1, rowspan: 2)[a],
)
--- grid-footer-multiple ---
@ -374,8 +417,8 @@
table.hline(stroke: red),
table.vline(stroke: green),
[b],
[c]
),
table.cell(x: 1, y: 3)[c]
)
--- grid-footer-hline-and-vline-2 ---
@ -385,8 +428,8 @@
#table(
columns: 3,
inset: 1.5pt,
table.cell(y: 0)[a],
table.footer(
table.cell(y: 0)[a],
table.hline(stroke: red),
table.hline(y: 1, stroke: aqua),
table.cell(y: 0)[b],
@ -394,6 +437,38 @@
)
)
--- grid-footer-top-hlines-with-only-row-pos-cell ---
// Top hlines should attach to the top of the footer.
#set page(margin: 2pt)
#set text(6pt)
#table(
columns: 3,
inset: 2.5pt,
table.footer(
table.hline(stroke: red),
table.vline(stroke: blue),
table.cell(x: 2, y: 2)[a],
table.hline(stroke: 3pt),
table.vline(stroke: 3pt),
)
)
--- grid-footer-top-hlines-with-row-and-auto-pos-cell ---
#set page(margin: 2pt)
#set text(6pt)
#table(
columns: 3,
inset: 2.5pt,
table.footer(
table.hline(stroke: red),
table.vline(stroke: blue),
table.cell(x: 2, y: 2)[a],
[b],
table.hline(stroke: 3pt),
table.vline(stroke: 3pt),
)
)
--- grid-footer-below-rowspans ---
// Footer should go below the rowspans.
#set page(margin: 2pt)
@ -404,3 +479,71 @@
table.cell(rowspan: 2)[a], table.cell(rowspan: 2)[b],
table.footer()
)
--- grid-footer-row-pos-cell-inside-conflicts-with-row-before ---
#set page(margin: 2pt)
#set text(6pt)
#table(
columns: 3,
inset: 1.5pt,
table.cell(y: 0)[a],
table.footer(
table.hline(stroke: red),
table.hline(y: 1, stroke: aqua),
// Error: 5-24 cell would cause footer to expand to non-empty row 0
// Hint: 5-24 try moving its cells to available rows
table.cell(y: 0)[b],
[c]
)
)
--- grid-footer-auto-pos-cell-inside-conflicts-with-row-after ---
#set page(margin: 2pt)
#set text(6pt)
#table(
columns: 2,
inset: 1.5pt,
table.cell(y: 1)[a],
table.footer(
[b], [c],
// Error: 6-7 cell would cause footer to expand to non-empty row 1
// Hint: 6-7 try moving its cells to available rows
[d],
),
)
--- grid-footer-row-pos-cell-inside-conflicts-with-row-after ---
#set page(margin: 2pt)
#set text(6pt)
#table(
columns: 2,
inset: 1.5pt,
table.cell(y: 2)[a],
table.footer(
[b], [c],
// Error: 5-24 cell would cause footer to expand to non-empty row 2
// Hint: 5-24 try moving its cells to available rows
table.cell(y: 3)[d],
),
)
--- grid-footer-conflicts-with-empty-header ---
#table(
columns: 2,
table.header(),
table.footer(
// Error: 5-24 cell would cause footer to expand to non-empty row 0
// Hint: 5-24 try moving its cells to available rows
table.cell(y: 0)[a]
),
)
--- issue-5359-column-override-stays-inside-footer ---
#table(
columns: 3,
[Outside],
table.footer(
[A], table.cell(x: 1)[B], [C],
table.cell(x: 1)[D],
),
)

View File

@ -60,6 +60,16 @@
grid.cell(y: 2)[c]
)
--- grid-header-cell-with-x ---
#grid(
columns: 2,
stroke: black,
inset: 5pt,
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 ---
// When the header is the last grid child, it shouldn't include the gutter row
// after it, because there is none.
@ -273,8 +283,7 @@
)
#context count.display()
--- grid-header-expand ---
// Ensure header expands to fit cell placed in it after its declaration
--- grid-header-no-expand-with-col-and-row-pos-cell ---
#set page(height: 10em)
#table(
columns: 2,
@ -282,9 +291,24 @@
[a], [b],
[c],
),
// Error: 3-48 cell would conflict with header spanning the same position
// Hint: 3-48 try moving the cell or the header
table.cell(x: 1, y: 1, rowspan: 2, lorem(80))
)
--- grid-header-no-expand-with-row-pos-cell ---
#set page(height: 10em)
#table(
columns: 2,
table.header(
[a], [b],
[c],
),
// Error: 3-42 cell would conflict with header spanning the same position
// Hint: 3-42 try moving the cell or the header
table.cell(y: 1, rowspan: 2, lorem(80))
)
--- grid-nested-with-headers ---
// Nested table with header should repeat both headers
#set page(height: 10em)
@ -368,3 +392,81 @@
[b]
)
)
--- grid-header-row-pos-cell-inside-conflicts-with-row-before ---
#set page(margin: 2pt)
#set text(6pt)
#table(
columns: 3,
inset: 1.5pt,
table.cell(y: 0)[a],
table.header(
table.hline(stroke: red),
table.hline(y: 1, stroke: aqua),
// Error: 5-24 cell would cause header to expand to non-empty row 0
// Hint: 5-24 try moving its cells to available rows
table.cell(y: 0)[b],
[c]
)
)
--- grid-header-row-pos-cell-inside-conflicts-with-row-before-after-first-empty-row ---
#set page(margin: 2pt)
#set text(6pt)
#table(
columns: 3,
inset: 1.5pt,
// Rows: Occupied, Empty, Occupied, Empty, Empty, ...
// Should not be able to expand header from the second Empty to the second Occupied.
table.cell(y: 0)[a],
table.cell(y: 2)[a],
table.header(
table.hline(stroke: red),
table.hline(y: 3, stroke: aqua),
// Error: 5-24 cell would cause header to expand to non-empty row 2
// Hint: 5-24 try moving its cells to available rows
table.cell(y: 2)[b],
)
)
--- grid-header-auto-pos-cell-inside-conflicts-with-row-after ---
#set page(margin: 2pt)
#set text(6pt)
#table(
columns: 2,
inset: 1.5pt,
table.cell(y: 1)[a],
table.header(
[b], [c],
// Error: 6-7 cell would cause header to expand to non-empty row 1
// Hint: 6-7 try moving its cells to available rows
[d],
),
)
--- grid-header-row-pos-cell-inside-conflicts-with-row-after ---
#set page(margin: 2pt)
#set text(6pt)
#table(
columns: 2,
inset: 1.5pt,
table.cell(y: 2)[a],
table.header(
[b], [c],
// Error: 5-24 cell would cause header to expand to non-empty row 2
// Hint: 5-24 try moving its cells to available rows
table.cell(y: 3)[d],
),
)
--- issue-5359-column-override-stays-inside-header ---
#table(
columns: 3,
[Outside],
// Error: 1:3-4:4 header must start at the first row
// Hint: 1:3-4:4 remove any rows before the header
table.header(
[A], table.cell(x: 1)[B], [C],
table.cell(x: 1)[D],
),
)