mirror of
https://github.com/rivo/tview.git
synced 2026-04-27 05:45:49 +03:00
[GH-ISSUE #413] SetLabelColor() does not work, SetLabel("[color]...") does #301
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/tview#301
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 @gwijnja on GitHub (Feb 26, 2020).
Original GitHub issue: https://github.com/rivo/tview/issues/413
What's wrong with the code below?
I am trying to set the label color using
InputField.SetChangedFunc(), but the label color remains yellow. It works if I replace theSetLabelColorlines with i.e.SetLabel("[red]Name"). According to the tview wiki it is not necessary to call any Draw() function to redraw the label.@gnojus commented on GitHub (Feb 26, 2020):
Form overrides all of its child attributes. Therefore you need to use
form.SetLabelColor(tcell.ColorRed)@gwijnja commented on GitHub (Feb 26, 2020):
But I want the label color to indicate the validation result. If I have many fields, all fields would change color simultaneously...
@gwijnja commented on GitHub (Feb 26, 2020):
I found it.
Formhas propertyitems []FormItem(including the InputFields). WheneverForm.Draw()is executed, all form items get their attributes overwritten with the Form's color properties.in form.go:
So whatever is set with
InputField.SetLabelColor()(and checkbox, and dropdown) is ignored and overwritten by the form.And indeed, if I comment that part of the code and replace it with a type switch to only set the label width and not overwrite the colors, it works as expected:
But this probably breaks
Form.SetLabelColor(). Maybe it's better to have a system where you can update all label colors through the Form, but override it from FormItems. So an update to a Form has priority over the defaults, but an update to a FormItem has priority over the Form.@gwijnja commented on GitHub (Feb 26, 2020):
How about this solution instead: keep the Form.go code as it is and change the
SetFormAttributesmethod in InputField.go/Checkbox.go/DropDown.go (and Button.go?) so that colors are only changed if they match the default colors:The result is that
Form.SetXxxColorapplies to all form elements that still have their default colors, and individual form elements can be overriden with[FormItem].SetXxxColoretc.Only if you update all colors through
Form.SetLabelColor()and then try to override a single element's color to the default color, it would be overridden again. If we want to fix that as well, then we need a flag for each color to remember if it was changed.@gwijnja commented on GitHub (Feb 26, 2020):
And now with flags. This would be the whole change, for each FormItem. The backgroundColor does not need to be checked, because there is no
InputField.SetBackgroundColor()method.@rivo commented on GitHub (Aug 18, 2020):
I could introduce a way to "intercept" these changes to form elements. A bit similar to
SetInputCapture()orSetMouseCapture(). So you can decide yourself which attribute the form can override and which one it can't.How does that sound to you?
@rivo commented on GitHub (Jan 11, 2021):
Please open a new issue and reference this one if this is still important to you.