mirror of
https://github.com/rivo/tview.git
synced 2026-04-27 05:45:49 +03:00
[GH-ISSUE #1040] Clarification on setting table column widths #752
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/tview#752
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @jsumners-nr on GitHub (Oct 17, 2024).
Original GitHub issue: https://github.com/rivo/tview/issues/1040
I have a case where I want columns to have specific widths, e.g.:
Based on https://github.com/rivo/tview/issues/227 and https://github.com/rivo/tview/issues/242, I think what I need to be doing is:
Simple example app
Is this correct? It's rather weird to set the "maximum width" in order to get a fixed width. And it's surprising to need toggle expansion of columns on.
@rivo commented on GitHub (Nov 2, 2024):
I'm not sure that you need to use
SetContenthere. That function (and the associated interface) is meant for more complex table designs like virtual tables (see the virtual table demo). Also, all thatGridcode kind of had me confused at first whether you're asking about grid layout or table layout.I think something like the following should be sufficient:
The
Tableclass primarily renders each cell as is, allocating space as needed. It was only later that people requested a maximum width (which would truncate the cell text if needed). And then, even later, people wanted to add space to columns when there was space left on screen, thus the "expansion" parameter. I'm not sure why one would want a width of exactly 23 for a table column instead of "whatever is needed". I mean, this is possible if required but you need to write a bit of extra code to make it happen.@jsumners-nr commented on GitHub (Nov 4, 2024):
The design had called for fixed width leading fields, e.g. log level and timestamp fields, in order to allocate the maximum amount of space for a primary field (log message). Ultimately, I ended up with the following to accomplish my goal:
And:
So, yes, I had to use the maximum width property in combination with the expansion property.