io/input,widget: [API] replace per-widget Focused with Source.Focused

Widgets have themselves as tags, by convention, and so it's possible to
replace the per-widget Focused methods with a general-purpose Source.
Focused query.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2023-11-28 10:35:51 -06:00
parent c3f2abebca
commit e59f91dfd0
9 changed files with 65 additions and 68 deletions
+3 -3
View File
@@ -96,7 +96,7 @@ func Clickable(gtx layout.Context, button *widget.Clickable, w layout.Widget) la
return layout.Background{}.Layout(gtx,
func(gtx layout.Context) layout.Dimensions {
defer clip.Rect{Max: gtx.Constraints.Min}.Push(gtx.Ops).Pop()
if button.Hovered() || button.Focused() {
if button.Hovered() || gtx.Focused(button) {
paint.Fill(gtx.Ops, f32color.Hovered(color.NRGBA{}))
}
for _, c := range button.History() {
@@ -135,7 +135,7 @@ func (b ButtonLayoutStyle) Layout(gtx layout.Context, w layout.Widget) layout.Di
switch {
case !gtx.Enabled():
background = f32color.Disabled(b.Background)
case b.Button.Hovered() || b.Button.Focused():
case b.Button.Hovered() || gtx.Focused(b.Button):
background = f32color.Hovered(b.Background)
}
paint.Fill(gtx.Ops, background)
@@ -167,7 +167,7 @@ func (b IconButtonStyle) Layout(gtx layout.Context) layout.Dimensions {
switch {
case !gtx.Enabled():
background = f32color.Disabled(b.Background)
case b.Button.Hovered() || b.Button.Focused():
case b.Button.Hovered() || gtx.Focused(b.Button):
background = f32color.Hovered(b.Background)
}
paint.Fill(gtx.Ops, background)