mirror of
https://github.com/rivo/tview.git
synced 2026-04-26 13:25:51 +03:00
[GH-ISSUE #20] Feature request - add "BackgroundColor" field to TableCell struct #15
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/tview#15
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 @andrewuhl on GitHub (Jan 13, 2018).
Original GitHub issue: https://github.com/rivo/tview/issues/20
It would be very nice to be able to set background colors for individual table cells.
When those (individually colored) cells are selected as part of a highlighted row or column, the current behavior of inverting text and background colors should remain as default behavior. More advanced future behavior might allow for setting all of the following:
@rivo commented on GitHub (Jan 13, 2018):
Can you provide an example where this could be useful? I'm trying to strike a balance between keeping the package simple and covering common use cases. It would be good to understand where this is needed.
@andrewuhl commented on GitHub (Jan 13, 2018):
In general, having control over cell background coloring allows for better visual contrast.
Most common use cases that would be immediately useful for me include:
Controlling text color alone doesn't quite provide the visual contrast needed.
Having different text and background colors based on selection state is a nice-to-have but not really that important. But controlling cell background color would be wonderful.
This is a terrific package, btw. Thanks for all the great work!
@rivo commented on GitHub (Jan 14, 2018):
So I added this. Thank you for your explanation. It will require some people to use the
NewTableCell()constructor or explicitly define a background color now becausetcell.Colordefaults to black (see #1 for where this would cause issues).Also, it's quite difficult to make this work with borders. You examples don't have character-wide/high borders but in a terminal, it looks odd when a cell has a background color but the cell borders don't. I implemented a simple solution for now. Might improve this later on.
@andrewuhl commented on GitHub (Jan 16, 2018):
From what I have seen, something like the following should correct at least some of the border issues that come about when using cell background color (not clear what other issues it may cause):
@rivo commented on GitHub (Jan 17, 2018):
I think this causes more problems than before. It includes the left cell border in situations where it shouldn't, in my opinion.
I did make a change for column-only selections, though. Those still looked odd but should be ok now.
If you encounter any situations where it doesn't seem to look correct, you could include a screenshot here or the code which uses the
Tableclass.@andrewuhl commented on GitHub (Jan 18, 2018):
Here is a table example using the most recent master (as of 2018/1/17).
Here is a table example using the above code change to table.go as of two days ago (despite other problems it causes as you identified):
The above image illustrates what I believe to be desirable behavior with respect to background colors and cell borders (aka "separator" or "gap").
I used the following code to produce both images (again, the first using my small change to table.go in the previous comment, and the second using today's most recent master):
It seems that the default separator rune (space character) makes the logic substantially more challenging when using background colors. If this is true, would it be possible to optionally not have any cell separator, thereby (hopefully) eliminating the problems with adjacent cell background coloring?
@rivo commented on GitHub (Jan 19, 2018):
It probably wouldn't be very hard to make it work if there was no space at all between columns. I don't see this as an option, though. It would lead to odd side effects when two neighbouring strings are joined. (And it adds even more complexity to the code.)
Just a slight modification to your code (calling
SetBorders(true)) illustrates how the situation is much more complex than what can be seen in your screenshots:You can see that the current code joins neighbouring cells' background if they are the same. (Not so with joining horizontal lines.) Here we also have a green cell ("Row 1") and a magenta cell ("-18.44%"), divided by a vertical line. Does the vertical line's background need to be colored? And if so, should it be green or magenta?
Your first example definitely shows an undesired effect so I'm reopening this issue now.
But the solution will require some more thought. I don't see a quick fix here like you suggested.
@rivo commented on GitHub (Jan 20, 2018):
I rewrote the whole background color logic. The new solution should make your examples look like one would expect.
When a table has borders around each cell, it's more difficult because neighbouring cells share the same border so I have to make a tradeoff. But I think the way it is now is the best I can think of.