-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added Importance field on Label to color the text #4047
Conversation
I hadn't thought about this, could be cool. Or just export the ColorName directly on Label - not sure about that either... |
That what I was thinking at first, but I didn't want to use ButtonImportance for something called Label, and I also didn't want to move too much code for my first attempt so I made this. But yes, ideally an "importance" type that work for multiple widget would be the best. |
I think we should deprecate |
I commit a patch to use widget.Importance instead of widget.ButtonImportance. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I added a few notes inline. Also, would you mind adding some tests? You can probably have a look at the existing importance tests for Button.
I resolved the comments you made and added some tests. |
Thanks. I'll try to review this in a few days at most. FYI: We usually prefer to let the reviewer mark their own comments as resolved (the one that request something decides on when it is done). It's no biggie this time but you know to the next time :) |
Oh ok sorry I didn't know. I will not touch next time ;) Thanks. |
I added initialization on Medium importance on the label. It's not necessary because Medium = 0 but I think it's more readable. Also, I copied the test and I notified this strange call in many test :
I don't understand why this is called second time at the end of the test. Can you explain me ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Just left a few minor notes inline.
I added initialization on Medium importance on the label. It's not necessary because Medium = 0 but I think it's more readable.
We generally try to not set default values. You can create a label or button without using the constructor as well. In my opinion it makes anyone reading the code think that it isn't the default so they set it when they don't need to.
widget/button_test.go
Outdated
test.NewApp() | ||
defer test.NewApp() | ||
test.ApplyTheme(t, theme.LightTheme()) | ||
|
||
//test backward compatibility of widget.Importance | ||
var imp widget.ButtonImportance = widget.HighImportance | ||
|
||
btn := widget.NewButton("test", func() {}) | ||
btn.Importance = imp | ||
btn.Refresh() | ||
|
||
w := test.NewWindow(btn) | ||
defer w.Close() | ||
|
||
test.AssertImageMatches(t, "button/compat_importance.png", w.Canvas().Capture()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need any image for this if you just want to make sure that it compiles (please also start comments with a space and then a capital letter):
test.NewApp() | |
defer test.NewApp() | |
test.ApplyTheme(t, theme.LightTheme()) | |
//test backward compatibility of widget.Importance | |
var imp widget.ButtonImportance = widget.HighImportance | |
btn := widget.NewButton("test", func() {}) | |
btn.Importance = imp | |
btn.Refresh() | |
w := test.NewWindow(btn) | |
defer w.Close() | |
test.AssertImageMatches(t, "button/compat_importance.png", w.Canvas().Capture()) | |
// Test backward compatibility of widget.Importance | |
var imp widget.ButtonImportance = widget.HighImportance | |
btn := widget.NewButton("test", func() {}) | |
btn.Importance = imp |
Remember to delete the corresponding image as well.
widget/label.go
Outdated
Text: text, | ||
Alignment: alignment, | ||
TextStyle: style, | ||
Importance: MediumImportance, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be needed. MediumImportance
is equal to zero and thus is the default.
FYI: Please fill out all of the checkboxes in the PR description. |
Sorry for the confusion. I meant all of those that you have done. You can delete those under "Where applicable:" that don't fit in with your current PR. |
The code looks good to me. I'll do a proper review and test locally when I have some time over. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me. Thanks. Well done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great thanks for adding this
Description:
I'm making a cross platform GUI app that manage acounting data and I wanted to color texts for negative values (red) and positive values (green). Also some warning messages if the client havn't paid should be printed in orange.
I can use canvas.Text but then I lost the TextStyle{} and Wrapping feature.
Also, using label and text in the same row of a List are not exactly aligned.
So I made this little patch based on the logic of ButtonImportance to add an Importance to a label. The Importance color the message on the label.
I'm not sure about names, and if it need to add an importance that print in Primary color and Secondary color.
But I think a lot of use case needs success, warning and error messages in the app.
Coloring text make the message more clear and the interface more intuitive.
Fixes #(issue)
Checklist: