-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Table cell x
and y
fields [More Flexible Tables Pt.2b]
#3050
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
Conversation
5f50456
to
a070fb4
Compare
Quick suggestion: As this branch depends on the changes on branch
|
Hey @Julian24816 , thanks for the suggestion. I believe the problem with your idea is that this branch is in my fork, so the PR would have to be moved to my fork... Do you know if there's a way around this? |
a070fb4
to
f887ecd
Compare
Oh, the Smartphone App hid this important detail from me 😅 sadly I don't have any experience with this topic in cross fork PRs... |
6435a9a
to
c40b451
Compare
347b7ae
to
ba80fcd
Compare
Use approach proposed by Laurenz
if it works, it works
- Did some initial handling of detached spans; can probably be improved - Had to use the name `cell_span()` cuz `#[elem]` isn't prepared to deal with two functions named `span()` in the same scope
This reverts commit cb52c3f. (didn't know this feature was restricted to Rust 1.73.0+)
Please mark things that you've implemented as resolved. This helps me see whether the PR is ready for another round of review / merging when looking at it. Thanks. :) |
Sure! I was told otherwise when contributing elsewhere (that the reviewer is responsible for marking threads as resolved), so I've refrained from doing so since then :P. However, when I'm unsure about something, I'll probably keep it open and ask explicitly for feedback, otherwise I'll just resolve it. 👍 |
Interesting. Not sure what the industry practice is, but most contributors here just mark it themselves and it works well enough. Typically, I'd notice anyway that something didn't change when doing another review round. But having the marking definitely helps to decide whether another review round should be done.
Sounds good. |
We should be adding spans everywhere we make a cell already
Provide more useful error messages, linking back to the original grid when a cell errored
Aside from the one conflict, this looks ready to merge. |
I was taking a look, and this conflict seems more significant than I thought; after #3200, we'll probably have to migrate Grid and Table to use I'll take a further look at this later today. |
Switched to taking Packed<T> on CellGrid::resolve
not 100% sure on this one, but it seems to work
Okay, well, I'm not very familiar with the new stuff from #3200, but here's what I did:
Feel free to give opinions; I can revert 5c6b9b4 if that'd be preferred. |
this workaround to avoid borrow check problems probably makes more sense
This reverts commit 9481456. Mutating `Packed` over different lines of `resolve_cell` is likely prone to cloning the `Arc` multiple times, so using a single `cell` variable is probably worth it, as this function is in the hot path for tables.
Q: If we keep my current approach of implementing Edit: If |
Everything is coupled with
Yeah, that's also a thing in a few other parts of the codebase now.
Mutating the packed is fine. Unpacking is actually worse because it'd lose the spans and other metadata that's stored in the TLDR: Everything looks good as-is. |
I'm excited for advanced tables slowly coming together. 🎉 |
Same here 🚀 |
Adds fields
x
andy
togrid.cell
andtable.cell
, in both ways: not only can you access them in show rules to determine how the cell should be displayed based on its coordinates, but you can also specifyx
andy
manually for a cell to ensure it will be placed at that particular position (however, will raise an error if that would lead to two cells in the same position).Specifying
x
but noty
will lead the cell to be placed in the first available row in that column (or create a row if needed). Similarly, specifyingy
but notx
will lead the cell to be placed in the first available column in that row (or error if no column is available, since columns are fixed).Added tests and docs with some examples.
Second part of the second task in #3001
This PR is a draft PR as it depends on #3037(For a simpler diff, check out PgBiel/typst@table-cells...PgBiel:typst:cell-positioning )User-facing API
x
(column) andy
(row) coordinates:Implementation details
CellGrid::resolve
, the grid (vector of cells) is now built from scratch, since cells can now be positioned in any way they wish, so thecells
vector would have to be reordered; thus, we create aresolved_cells
vector, and iterate overcells
to determine the final position of each cell, resolve it, and place it in the appropriate position in the vector (three steps).cells
,resolved_cells
expands accordingly. But it has to expand with something (e.g. if a cell is placed 900 positions after the last one, what do we fill the empty vector spaces with?). We could expand adding many normal cells with empty bodies, but then those cells would be taking up space unnecessarily - it should be possible to override those "filler" cells later if we want.resolved_cells
starts out as a vector ofOption<Cell>
- it hasNone
where a new cell can be placed.None
inVec<Option<Cell>>
) can be replaced by a cell later incells
which might want to occupy its space (turning the position toSome(cell)
). However, if there are any absent cell positions remaining after rebuilding the grid, they are converted to normal cells with empty bodies (necessary so we can synthesize properties on the empty spaces, e.g. fill or align, and so we can apply show rules on them too).resolved_cells
and convertingOption<Cell>
toCell
(just unwrap if the cell is Some, otherwise create a new empty cell).resolved_cells.len() != cells.len()
, since the only way aNone
entry can remain after the grid is built is ifresolved_cells
was actually expanded. This could lead to a potential optimization here, but that would have to be discussed. For now, this works.Remaining questions
x
ory
- automatically skip cells which are already occupied by cells with arbitrary/custom position? For example,will error, which makes sense, since
[B]
was already placed in the grid by the time we got to that last cell. But the following also errors; maybe it shouldn't (and we should just skip the arbitrarily-positioned cell)?x: auto
andy: auto
, the default) will just skip non-absent (non-None
) positions. (Implemented in c376e57)Performance implications
In my unscientific tests using documents containing only large tables, tables took about 70-80% longer to cold compile with this PR.
Maybe there isn't too much we can do about this, unfortunately...
TODO
TODO:Fix problem with incomplete (non-c
-large) rowsTODO:Docs.TODO:Merge other PR.