widget: [API] re-implement Clickable.Focus with a command

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2023-10-20 21:00:09 -05:00
parent 9de80749e1
commit 627e028d3c
2 changed files with 4 additions and 9 deletions
+2 -7
View File
@@ -23,7 +23,6 @@ type Clickable struct {
history []Press
keyTag struct{}
requestFocus bool
requestClicks int
focused bool
pressedKey string
@@ -79,8 +78,8 @@ func (b *Clickable) Pressed() bool {
}
// Focus requests the input focus for the element.
func (b *Clickable) Focus() {
b.requestFocus = true
func (b *Clickable) Focus(gtx layout.Context) {
gtx.Queue(key.FocusCmd{Tag: &b.keyTag})
}
// Focused reports whether b has focus.
@@ -121,10 +120,6 @@ func (b *Clickable) Update(gtx layout.Context) []Click {
if !gtx.Enabled() {
b.focused = false
}
if b.requestFocus {
gtx.Queue(key.FocusCmd{Tag: &b.keyTag})
b.requestFocus = false
}
for len(b.history) > 0 {
c := b.history[0]
if c.End.IsZero() || gtx.Now.Sub(c.End) < 1*time.Second {