widget,widget/material: make Clickable widgets focusable

This change adds focus and keyboard control to Clickable widgets.
They now consider a press of the enter or return key equivalent to
a click. To keep the change simple, the focus indication is the
same as the hover indication.

References: https://todo.sr.ht/~eliasnaur/gio/195
References: https://github.com/tailscale/tailscale/issues/1611
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2022-02-23 10:39:08 +01:00
parent eb48b45913
commit cd2ade0583
7 changed files with 128 additions and 43 deletions
+2 -2
View File
@@ -132,7 +132,7 @@ func (b ButtonLayoutStyle) Layout(gtx layout.Context, w layout.Widget) layout.Di
switch {
case gtx.Queue == nil:
background = f32color.Disabled(b.Background)
case b.Button.Hovered():
case b.Button.Hovered() || b.Button.Focused():
background = f32color.Hovered(b.Background)
}
paint.Fill(gtx.Ops, background)
@@ -168,7 +168,7 @@ func (b IconButtonStyle) Layout(gtx layout.Context) layout.Dimensions {
switch {
case gtx.Queue == nil:
background = f32color.Disabled(b.Background)
case b.Button.Hovered():
case b.Button.Hovered() || b.Button.Focused():
background = f32color.Hovered(b.Background)
}
paint.Fill(gtx.Ops, background)