widget/material: add focus and hover indicators to Clickable

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2022-02-28 16:49:43 +01:00
parent f711e7eaa8
commit 50e35c9c3f
2 changed files with 7 additions and 0 deletions
+4
View File
@@ -154,6 +154,10 @@ func Disabled(c color.NRGBA) (d color.NRGBA) {
// Hovered blends dark colors towards white, and light colors towards
// black. It is approximate because it operates in non-linear sRGB space.
func Hovered(c color.NRGBA) (h color.NRGBA) {
if c.A == 0 {
// Provide a reasonable default for transparent widgets.
return color.NRGBA{A: 0x44, R: 0x88, G: 0x88, B: 0x88}
}
const ratio = 0x20
m := color.NRGBA{R: 0xff, G: 0xff, B: 0xff, A: c.A}
if approxLuminance(c) > 128 {
+3
View File
@@ -94,6 +94,9 @@ func Clickable(gtx layout.Context, button *widget.Clickable, w layout.Widget) la
return layout.Stack{}.Layout(gtx,
layout.Expanded(func(gtx layout.Context) layout.Dimensions {
defer clip.Rect{Max: gtx.Constraints.Min}.Push(gtx.Ops).Pop()
if button.Hovered() || button.Focused() {
paint.Fill(gtx.Ops, f32color.Hovered(color.NRGBA{}))
}
for _, c := range button.History() {
drawInk(gtx, c)
}