Skip to content

Repeatable Table Footers [More Flexible Tables Pt.6a] #3577

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 28 commits into from
Mar 9, 2024

Conversation

PgBiel
Copy link
Contributor

@PgBiel PgBiel commented Mar 8, 2024

Adds table.footer and grid.footer to have some rows repeat at the bottom of a table's pages.

First part of the sixth task in #3001.

Currently, footers must always include the last row of the table.

NOTE: There are some parts of this PR which are direct improvements/fixes for headers, such as the Repeatable enum, which is used to force non-repeated headers to be unbreakable for consistency. If needed for the release, I can try to extract as much as possible into a separate PR, but, ideally, we'd just merge this PR, which, as I see it, is basically ready. :)

User-facing API

  • Use table.footer and grid.footer with repeat: true/false (defaults to true) to have optionally repeatable footer rows at the bottom of the table. When there's gutter, the gutter above the footer is repeated too.
#set page(width: auto, height: 15em)
#table(
  columns: 5,
  align: center + horizon,
  table.header(
    table.cell(colspan: 5)[*Cool Zone*],
    table.cell(stroke: red)[*Name*], table.cell(stroke: aqua)[*Number*], [*Data 1*], [*Data 2*], [*Etc*],
    table.hline(start: 2, end: 3, stroke: yellow)
  ),
  ..range(0, 5).map(i => ([John \##i], table.cell(stroke: green)[123], table.cell(stroke: blue)[456], [789], [?], table.hline(start: 4, end: 5, stroke: red))).flatten(),
  table.footer(
    table.hline(start: 2, end: 3, stroke: yellow),
    table.cell(stroke: red)[*Name*], table.cell(stroke: aqua)[*Number*], [*Data 1*], [*Data 2*], [*Etc*],
    table.cell(colspan: 5)[*Cool Zone*]
  )
)

image
image

Implementation details

  • Here I mostly just use the same tricks as headers to reduce available space through self.regions.map, use in_last_with_offset etc. This is made possible by the fact that I simulate the footers right before simulating headers, and then skip regions until both header and footer fit. The simulated footer height is kept in the layouter state so rows can be aware of that info, but either way it is subtracted from the available size so rows will properly skip to the next region as needed.
  • The footer is only laid out for the current region when finish_region is called, right before effectively resolving rows in lrows, and it only occurs if it hasn't been laid out already, or if it wouldn't be an orphan (and/or the region would only have the header and the footer, in which case both would be orphans and would not be laid out).
  • The rest (CellGrid stuff, line priority etc.) is very similar to headers.

@PgBiel PgBiel mentioned this pull request Mar 8, 2024
18 tasks
@PgBiel
Copy link
Contributor Author

PgBiel commented Mar 8, 2024

Of note, a larger refactor is likely in order, moving CellGrid and related types to some file like cells.rs, and anything related to headers and footers to some repeatable.rs file. However, I think this could be done in a future PR (such as the one for multiple headers/footers or whatever), since right now headers and footers aren't demanding that much space (although it's, of course, larger than before), and also to save a bit of time.

@laurmaedje laurmaedje enabled auto-merge March 9, 2024 15:45
@laurmaedje
Copy link
Member

I minified the test images a bit. Thank you for the PR!

@laurmaedje laurmaedje added this pull request to the merge queue Mar 9, 2024
Merged via the queue into typst:main with commit 639a8d0 Mar 9, 2024
@PgBiel PgBiel deleted the repeatable-footers branch March 9, 2024 16:11
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.

2 participants