Skip to content
This repository has been archived by the owner on Oct 13, 2021. It is now read-only.

Make Styles inherit by default #82

Merged
merged 5 commits into from
Dec 24, 2017

Conversation

cceckman
Copy link
Contributor

Overall, this fixes #81 - it changes the semantics of Style to be a set of overrides on top of whatever the preexisting style is. The zero value for Style means "inherit everything".

Style changes in a backwards-incompatible way- makes Reverse, Bold, and Underline into tri-state values ("inherit", "on", and "off").

The included example (examples/color/main.go) isn't as clean as I'd like because it requires embedding- there's not a way to apply a style to one Box but not another, at the moment.

Follows #80; I'll rebase from there once merged. (I'm also open to suggestions on how to present stacked pull requests in a more sensible way.) Tagging #36 because it's a similar behavior.

@cceckman
Copy link
Contributor Author

Has been rebased after #80; ready for review.

// StyledBox is a Box with an overriden Draw method.
// Embedding a Widget within another allows overriding of some behaviors.
type StyledBox struct {
Style string
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be exported as a method rather than a field to keep the API consistent. I don't believe there are any exported fields in the current API (to my knowledge).

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I scanned it too fast (this isn't part of the API). Ignore my comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, this is just internal for the example.

@marcusolsson
Copy link
Owner

You're on fire! 🥇 Only had one comment, otherwise I'm ready to merge!

@marcusolsson
Copy link
Owner

Regarding the comment on StyledBox. It might be time to roll out SetStyleName for other widgets than Label?

@cceckman
Copy link
Contributor Author

Re: SetStyleName everywhere- +1 to generally being able to set styles on widgets, but the question of what that API is is at the root of #74.

Moving SetStyleName up to WidgetBase would be an easy fix, but that doesn't account well for widgets with multiple styles (Box with its border, List with its selection). Let's continue discussion there?

@cceckman
Copy link
Contributor Author

(Also as FYI, re: "on fire" - I'm on vacation for a couple of weeks, and therefore have lots of weekday time for personal projects. That includes the stuff I'm using tui for, as well as tui itself. :-) )

WithStyle and Theme have an interesting behavior. Theme.Style will
always return a value (the zero value of Style, essentially), even if
the Style with the requested name doesn't have anything set in the
Theme. However, as far as I can tell, this does't matter- WithStyle
first checks if the Theme HasStyle, and only applies an additional style
when one is set in the Theme.

I'd like these to be the same (see marcusolsson#81)... but I'm
not going to send this as a PR yet until that's agreed.
The previous Style behavior was for each WithStyle application to reset
each property; application of "this color" and then "underline" would go
back to ColorDefault.

This allows each of Style's properties to be either explicitly
specified, or to inherit from the existing Style. The default is to
inherit from the next style up in the widget stack.

Mostly this is accomplished by making the boolean properties into a
tri-state (inherit/on/off) type.
@marcusolsson marcusolsson merged commit 1903c42 into marcusolsson:master Dec 24, 2017
@cceckman cceckman deleted the inheritstyle branch January 4, 2018 06:13
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Proposal: partial application of Style
2 participants