mirror of
https://github.com/rivo/tview.git
synced 2026-04-26 21:35:54 +03:00
[GH-ISSUE #242] Tablecells incorrectly expand in width #188
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/tview#188
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 @Bios-Marcel on GitHub (Feb 23, 2019).
Original GitHub issue: https://github.com/rivo/tview/issues/242
I have a table containing 3 columns, each having
Expandset to1. However, when putting a longer text into the cell, it just expands, even though there is still enough space left.@rivo commented on GitHub (Mar 9, 2019):
Yes, this would be expected. The
Expansionvalue distributes "remaining available space" so that narrow tables can fill the entire available width. If you add a long text to a column, the table's remaining space becomes less. Thus, there's less to distribute to other columns.In this example, you may want to set the
Expansionvalue to0for the first two columns.@Bios-Marcel commented on GitHub (Mar 9, 2019):
As far as I get it, setting the expansion on all cells to the same value, they should all take an equal amount of space.
@rivo commented on GitHub (Mar 9, 2019):
I think what you want is a
SetWidth()function (relative or absolute), not aSetExpansion()function.Again,
Expansiondetermines how the table grows, not the initial width of a column.@Bios-Marcel commented on GitHub (Mar 9, 2019):
So, shouldn't it be a
boolinstead? Because currently it is anint.@rivo commented on GitHub (Mar 9, 2019):
You mean the
Expansionvalue? I'm not sure what you mean.@Bios-Marcel commented on GitHub (Mar 9, 2019):
Okay, I am a bit confused.
github.com/rivo/tview@03d744dee3/table.go (L83)I have had 3 columns all having their
Expansionvalue set to1, meaning they were all equal, so why when changing theTextattribute of one of those three columns, did it expand?@rivo commented on GitHub (Mar 9, 2019):
This is the function description:
Again, the
Expansionvalue does not determine the designated width of the column. It only grows it after the column width has already been established.The algorithm works somewhat like this:
i, calculatecolumn width(i) = max(text width)over all rows.table width = sum(column width)over all columns.table width < available width, distributeavailable width - table widthaccording toexpansionvalues:column width(i) += expansion(i) * (available width - table width) / sum(expansion)table width >= available width, do nothing.This is not the same as, say,
Grid.SetColumns(-1,-1,-1). If it was, I would have given it a different name, as "to expand" generally means "to grow".Thus, because of Step 1, it all depends on the width of your text. If you change it, everything changes.
I'm guessing a solution to what you're asking for is described in #184.
@Bios-Marcel commented on GitHub (Mar 9, 2019):
I see. Thanks a lot man! I'll be closing the issue then.