Skip to content

Refactor grid header and footer resolving#5919

Merged
laurmaedje merged 28 commits intomainfrom
refactor-header-resolve
Mar 24, 2025
Merged

Refactor grid header and footer resolving#5919
laurmaedje merged 28 commits intomainfrom
refactor-header-resolve

Conversation

@PgBiel
Copy link
Contributor

@PgBiel PgBiel commented Feb 21, 2025

(Draft as there's some polishing still missing, but keeping it open to track progress so far.)

Fixes #5359

This refactors grid resolving - that is, the step before grid and table layout where we parse the parameters, place cells in their appropriate locations and generate the final grid - in preparation for #5375 and #5377 to ensure the code can handle any amount of arbitrary row groups, that is, table children which aren't cells directly but span groups of entire rows, which right now only include headers and footers.

This also adjusts how manually-positioned cells behave with headers and footers. Before, you could place a cell before the header and then, even though the header would normally try to occupy the following row (so as to not conflict with that existing cell), you could force the header to occupy the first row as well with grid.cell(y: 0)[...] inside the header. Instead of throwing an error, Typst would just happily accept that the cell outside of the header is now part of header, which is very unlikely to be the intention. So, headers and footers can no longer expand to include cells outside them. Instead, they will try to skip them, and cells outside headers and footers which don't pick their rows will always skip headers and footers, avoiding conflicts.

In other words, conflicts between headers and footers and cells outside them are now only possible when you have cells with fixed y, in which case this should always be an error now. This fixes #5359.

TODO

Mostly just doing some final polishing before marking the PR as ready for review. There are some TODOs in the code, I'll tackle some now and the rest should be tackled in further PRs.

@PgBiel PgBiel force-pushed the refactor-header-resolve branch from abf77f1 to 838bdc0 Compare February 27, 2025 16:25
@PgBiel PgBiel marked this pull request as ready for review February 27, 2025 21:29
Copy link
Member

@laurmaedje laurmaedje left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, I'm not familiar enough with the old code to properly review this change. I'd trust you on the change, but if you want we can also have a quick call where you walk me through the changes. Just trying to understanding everything from scratch by myself would be a bit too time-consuming right now.

@PgBiel
Copy link
Contributor Author

PgBiel commented Mar 4, 2025

To be honest, I'm not familiar enough with the old code to properly review this change. I'd trust you on the change, but if you want we can also have a quick call where you walk me through the changes. Just trying to understanding everything from scratch by myself would be a bit too time-consuming right now.

Yeah sure, we can do that, even if just for a quick sanity check.

@PgBiel PgBiel marked this pull request as draft March 5, 2025 18:13
Copy link
Contributor Author

@PgBiel PgBiel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, the refactor was pretty "light" (I didn't move all the context variables I could into struct fields), but I think the effects were quite significant already.

@PgBiel PgBiel marked this pull request as ready for review March 13, 2025 01:28
@laurmaedje laurmaedje added this pull request to the merge queue Mar 24, 2025
@laurmaedje
Copy link
Member

What do you think about turning grid_to_cellgrid and table_to_cellgrid into routines and moving them into typst-layout? I think it's conceptually sort of a layout task even though it's needed in HTML as well. And moving it would shave off a good amount of code from typst-library.

Merged via the queue into main with commit 1f1c133 Mar 24, 2025
13 checks passed
@laurmaedje laurmaedje deleted the refactor-header-resolve branch March 24, 2025 21:04
@PgBiel
Copy link
Contributor Author

PgBiel commented Mar 25, 2025

What do you think about turning grid_to_cellgrid and table_to_cellgrid into routines and moving them into typst-layout? I think it's conceptually sort of a layout task even though it's needed in HTML as well. And moving it would shave off a good amount of code from typst-library.

Not sure, in theory I can see it being useful from a library perspective in the future as well by providing a method or something which lets one access (and generate) the cellgrid before layout, within typst code. But i guess it doesn't really matter?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fixing cell column within table.header and table.footer causes weird behaviour.

2 participants