mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-05 01:15:35 +00:00
widget: [API] re-implement Clickable.Focus with a command
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+2
-7
@@ -23,7 +23,6 @@ type Clickable struct {
|
|||||||
history []Press
|
history []Press
|
||||||
|
|
||||||
keyTag struct{}
|
keyTag struct{}
|
||||||
requestFocus bool
|
|
||||||
requestClicks int
|
requestClicks int
|
||||||
focused bool
|
focused bool
|
||||||
pressedKey string
|
pressedKey string
|
||||||
@@ -79,8 +78,8 @@ func (b *Clickable) Pressed() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Focus requests the input focus for the element.
|
// Focus requests the input focus for the element.
|
||||||
func (b *Clickable) Focus() {
|
func (b *Clickable) Focus(gtx layout.Context) {
|
||||||
b.requestFocus = true
|
gtx.Queue(key.FocusCmd{Tag: &b.keyTag})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Focused reports whether b has focus.
|
// Focused reports whether b has focus.
|
||||||
@@ -121,10 +120,6 @@ func (b *Clickable) Update(gtx layout.Context) []Click {
|
|||||||
if !gtx.Enabled() {
|
if !gtx.Enabled() {
|
||||||
b.focused = false
|
b.focused = false
|
||||||
}
|
}
|
||||||
if b.requestFocus {
|
|
||||||
gtx.Queue(key.FocusCmd{Tag: &b.keyTag})
|
|
||||||
b.requestFocus = false
|
|
||||||
}
|
|
||||||
for len(b.history) > 0 {
|
for len(b.history) > 0 {
|
||||||
c := b.history[0]
|
c := b.history[0]
|
||||||
if c.End.IsZero() || gtx.Now.Sub(c.End) < 1*time.Second {
|
if c.End.IsZero() || gtx.Now.Sub(c.End) < 1*time.Second {
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ func TestClickable(t *testing.T) {
|
|||||||
r.Frame(gtx.Ops)
|
r.Frame(gtx.Ops)
|
||||||
}
|
}
|
||||||
// frame: request focus for button 1
|
// frame: request focus for button 1
|
||||||
b1.Focus()
|
b1.Focus(gtx)
|
||||||
frame()
|
frame()
|
||||||
// frame: gain focus for button 1
|
// frame: gain focus for button 1
|
||||||
frame()
|
frame()
|
||||||
@@ -77,7 +77,7 @@ func TestClickable(t *testing.T) {
|
|||||||
t.Error("button 1 got clicked, even if it only got return press")
|
t.Error("button 1 got clicked, even if it only got return press")
|
||||||
}
|
}
|
||||||
// frame: request focus for button 2
|
// frame: request focus for button 2
|
||||||
b2.Focus()
|
b2.Focus(gtx)
|
||||||
frame()
|
frame()
|
||||||
// frame: gain focus for button 2
|
// frame: gain focus for button 2
|
||||||
frame()
|
frame()
|
||||||
|
|||||||
Reference in New Issue
Block a user