Skip to content

Commit

Permalink
Transparent background for LowImportance Button
Browse files Browse the repository at this point in the history
This makes sure that we don't change the background for disabled button with LowImportance.
As a benefit, this makes the SelectEntry look a lot better when disabled.

Fixes fyne-io#3139
  • Loading branch information
Jacalz committed Jul 15, 2022
1 parent ab10573 commit 70651db
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 1 deletion.
3 changes: 3 additions & 0 deletions widget/button.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,9 @@ func (r *buttonRenderer) applyTheme() {
func (r *buttonRenderer) buttonColor() color.Color {
switch {
case r.button.Disabled():
if r.button.Importance == LowImportance {
return color.Transparent
}
return theme.DisabledButtonColor()
case r.button.focused:
return blendColor(theme.ButtonColor(), theme.FocusColor())
Expand Down
14 changes: 14 additions & 0 deletions widget/button_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,20 @@ func TestButton_Disabled(t *testing.T) {
assert.False(t, button.Disabled())
}

func TestButton_LowImportance(t *testing.T) {
test.NewApp()
defer test.NewApp()

b := &widget.Button{Text: "Text", Icon: theme.HomeIcon(), Importance: widget.LowImportance}
w := test.NewWindow(b)
defer w.Close()

test.AssertImageMatches(t, "button/low_importance.png", w.Canvas().Capture())

b.Disable()
test.AssertImageMatches(t, "button/low_importance_disabled.png", w.Canvas().Capture())
}

func TestButton_Hover(t *testing.T) {
test.NewApp()
defer test.NewApp()
Expand Down
Binary file added widget/testdata/button/low_importance.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion widget/testdata/select_entry/disableable_disabled.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</widget>
</widget>
<widget pos="102,8" size="20x20" type="*widget.Button">
<rectangle fillColor="disabled button" size="20x20"/>
<rectangle size="20x20"/>
<rectangle fillColor="rgba(0,0,0,0)" pos="0,2" size="16x16"/>
<image fillMode="contain" rsc="menuDropDownIcon" size="iconInlineSize" themed="disabled"/>
</widget>
Expand Down

0 comments on commit 70651db

Please sign in to comment.