Skip to content
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

Add calculations to apply hover over high importance buttons #2017

Merged
merged 4 commits into from Feb 24, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 12 additions & 2 deletions widget/button.go
Expand Up @@ -312,10 +312,20 @@ func (r *buttonRenderer) buttonColor() color.Color {
switch {
case r.button.Disabled():
return theme.DisabledButtonColor()
case r.button.Importance == HighImportance:
return theme.PrimaryColor()
case r.button.hovered:
if r.button.Importance == HighImportance {
srcR, srcG, srcB, srcA := theme.PrimaryColor().RGBA()
dstR, dstG, dstB, dstA := theme.HoverColor().RGBA()
alpha := float32(dstA) / 0xFFFF
outR := alpha*float32(dstR) + (1-alpha)*float32(srcR)
outG := alpha*float32(dstG) + (1-alpha)*float32(srcG)
outB := alpha*float32(dstB) + (1-alpha)*float32(srcB)
outA := alpha*float32(dstA) + (1-alpha)*float32(srcA)
return color.RGBA{R: uint8(uint32(outR) >> 8), G: uint8(uint32(outG) >> 8), B: uint8(uint32(outB) >> 8), A: uint8(uint32(outA) >> 8)}
Copy link
Member

Choose a reason for hiding this comment

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

Oh that was my mistake 😅 I forgot to do it. Great!! I was beginning to be afraid of colors 😂

}
return theme.HoverColor()
Copy link
Member

@fpabl0 fpabl0 Feb 23, 2021

Choose a reason for hiding this comment

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

I think the above change should have the normal button color too, because if someone use a custom theme and change the button Color, it would not look great if button is colored directly to the hover Color.

case r.button.Importance == HighImportance:
return theme.PrimaryColor()
default:
return theme.ButtonColor()
}
Expand Down
25 changes: 25 additions & 0 deletions widget/button_test.go
Expand Up @@ -121,6 +121,31 @@ func TestButton_Disabled(t *testing.T) {
assert.False(t, button.Disabled())
}

func TestButton_Hover(t *testing.T) {
app := test.NewApp()
defer test.NewApp()
app.Settings().SetTheme(theme.LightTheme())

b := widget.NewButtonWithIcon("Test", theme.HomeIcon(), func() {})
w := test.NewWindow(b)
defer w.Close()

test.MoveMouse(w.Canvas(), fyne.NewPos(5, 5))
test.AssertImageMatches(t, "button/hovered.png", w.Canvas().Capture())

b.Importance = widget.HighImportance
b.Refresh()
test.AssertImageMatches(t, "button/high_importance_hovered.png", w.Canvas().Capture())

test.MoveMouse(w.Canvas(), fyne.NewPos(0, 0))
b.Refresh()
test.AssertImageMatches(t, "button/high_importance.png", w.Canvas().Capture())

b.Importance = widget.MediumImportance
b.Refresh()
test.AssertImageMatches(t, "button/initial.png", w.Canvas().Capture())
}

func TestButton_Layout(t *testing.T) {
test.NewApp()
defer test.NewApp()
Expand Down
Binary file added widget/testdata/button/high_importance.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added widget/testdata/button/hovered.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.