Skip to content
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

feat(table): Multi-column table cells #1568

Open
stijndcl opened this issue Dec 11, 2024 · 3 comments
Open

feat(table): Multi-column table cells #1568

stijndcl opened this issue Dec 11, 2024 · 3 comments
Labels
Status: Design Needed An issue that isn't yet designed or specified well enough to implement Type: Enhancement New feature or request

Comments

@stijndcl
Copy link

Problem

Table cells cannot currently span across multiple columns:

These Are Single Column
But these are multi-column

This is often useful when wanting to "group" or "nest" headers:

Benchmark Rust JavaScript
CPU Memory CPU Memory
bench1 5% 5kb 100% 5GB

Solution

Add an option to the Cell struct and take it into account when rendering the table. This means that in a table with N columns, each row can contain anywhere between 1 and N cells.

Additional notes

The specific example above would also require multi-row headers, which is a separate issue out of scope for this one. Multi-col cells are still useful in other contexts as well.

@stijndcl stijndcl added the Type: Enhancement New feature or request label Dec 11, 2024
@joshka
Copy link
Member

joshka commented Dec 12, 2024

If you no longer want Latta AI to attempt solving issues on your repository, you can block this account.

AI is cool with me (I use a variety of things daily). But I prefer there to be a human in the loop that checks things so they're not wasting my time like this.

@orhun orhun added the Status: Design Needed An issue that isn't yet designed or specified well enough to implement label Mar 4, 2025
@joshka
Copy link
Member

joshka commented Mar 4, 2025

Hey there,

It might be nice to see some ideas that you have for how the table API will change to support this. Have you got some ideas you can share?

I'm wary of changing the table implementation too much, as it's fairly complex already, which makes adding more complexity a maintenance burden (mostly in reviewing changes). Perhaps if you're interested in implementing this, consider whether there are any simplifying refactorings that can make this easy to implement and review. Also keep in mind what impact the changes would have on existing users.

One approach we like to suggest for adding more advanced behavior to widgets is to first fork them and use them in your own app with the desired changes to validate that things work correctly (note the MIT license allows you to do this, just keep the copyright notice). You might find that creating a tui-advanced-table crate might be worth considering at some point (similar to the the tui-widget-list crate)

@stijndcl
Copy link
Author

stijndcl commented Mar 7, 2025

Hey @joshka

My idea for the API would be something similar to the current style field. In other words, have the Cell struct take a width field (or span or whatever you'd like to call it). By default set it to 1, and let the new/From<> methods set it to 1 as well. That way it doesn't impact people that don't need it. Add a method width(usize) -> Self that modifies the cell and updates the field internally.

Perhaps you can even support Into<Cell> for (Into<Text>, usize) so users can create a multi-col cell using (content, width).into().

This is basically identical to the current approach for styling for end-users, so shouldn't feel out-of-place, and is completely transparant/non-breaking.

In terms of rendering I am not familiar with the internals of Ratatui so I fear I can't provide much insight there. I can imagine there's some functionality that computes the area of a cell, so that should factor in the width in that case (and the width of the cell border/separator that would've gone in between the cells).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Design Needed An issue that isn't yet designed or specified well enough to implement Type: Enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants
@joshka @orhun @stijndcl and others