mirror of
https://github.com/rivo/tview.git
synced 2026-04-26 13:25:51 +03:00
[GH-ISSUE #1] Color inheritance from parent primitives #1
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/tview#1
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 @dpotapov on GitHub (Jan 8, 2018).
Original GitHub issue: https://github.com/rivo/tview/issues/1
Hi,
First of all, thank you very much for this library! I'm going to use it to replace dialog in my scripts...
Just would like to propose an enhancement: ability to inherit background and foreground colors from parent primitives. Right now I have to explicitly call SetBackgroundColor/SetTextColor on every new element, which is a bit annoying.
Thanks!
@rivo commented on GitHub (Jan 9, 2018):
I'm not 100% sure what kind of solution you are looking for. Do you mean you would like to set package-wide default colors for background and text?
@Spriithy commented on GitHub (Jan 9, 2018):
I think he means that if one sets Backgroung color of an element, then all its subsequent children will -by default- have their background color set to black. Same would go for foreground colors.
See his proposal as color settings inheritance.
@rivo commented on GitHub (Jan 9, 2018):
Maybe I'm confused by what you mean by "children" then. For example,
TextViewinherits fromBoxand if I useSetBackgroundColor()(which is a function ofBox), it will also be used for theTextView. Do you mean composed primitives such asFlex? I.e. makeSetBackgroundColor()called onFlexapply to all its contained primitives?Can you provide an example?
@dpotapov commented on GitHub (Jan 9, 2018):
Let me illustrate what I'm trying to achieve...
Currently if I draw primitives on a blue screen, I have black background by default:

I would like to achieve something like this without adding

SetBackgroundColor()for each primitive:Code example:
Naive approach would be to have a function like
app.SetBackgroundColor(tcell.ColorBlue)to set the background for entire application. However I don't want to stick to some particular implementation. Color inheritance could be a solution, but there might be different approaches (e.g. https://github.com/marcusolsson/tui-go/issues/74)@rivo commented on GitHub (Jan 9, 2018):
Thanks for the explanation. I think I understand now what you mean. I'm gravitating towards something simpler than what they're discussing at
tui-go. At the moment, I think it could be either the color inheritance solution for any primitives that contain other primitives (Flex, Pages, Frame, Form). Or a package-global style, something like this:In your example, are you choosing the blue background because your entire application will have a blue background? Or is this just for that one page and other pages may be styled differently?
@dpotapov commented on GitHub (Jan 9, 2018):
+1 for simplicity.
In my case the entire application will have a blue background.
@rivo commented on GitHub (Jan 10, 2018):
For now, I've added a package-global variable
Styleswhich can be adapted to your preferred look and feel.I might introduce inherited styles for composed primitives when the need comes up. But for now, this change should help you.