mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 09:55:40 +00:00
widget: add a Focus() method to widget.Clickable
Signed-off-by: Larry Clapp <larry@theclapp.org>
This commit is contained in:
+12
-2
@@ -25,8 +25,9 @@ type Clickable struct {
|
|||||||
prevClicks int
|
prevClicks int
|
||||||
history []Press
|
history []Press
|
||||||
|
|
||||||
keyTag struct{}
|
keyTag struct{}
|
||||||
focused bool
|
requestFocus bool
|
||||||
|
focused bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Click represents a click.
|
// Click represents a click.
|
||||||
@@ -80,6 +81,11 @@ func (b *Clickable) Pressed() bool {
|
|||||||
return b.click.Pressed()
|
return b.click.Pressed()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Focus requests the input focus for the element.
|
||||||
|
func (b *Clickable) Focus() {
|
||||||
|
b.requestFocus = true
|
||||||
|
}
|
||||||
|
|
||||||
// Focused reports whether b has focus.
|
// Focused reports whether b has focus.
|
||||||
func (b *Clickable) Focused() bool {
|
func (b *Clickable) Focused() bool {
|
||||||
return b.focused
|
return b.focused
|
||||||
@@ -115,6 +121,10 @@ func (b *Clickable) Layout(gtx layout.Context, w layout.Widget) layout.Dimension
|
|||||||
keys = ""
|
keys = ""
|
||||||
}
|
}
|
||||||
key.InputOp{Tag: &b.keyTag, Keys: keys}.Add(gtx.Ops)
|
key.InputOp{Tag: &b.keyTag, Keys: keys}.Add(gtx.Ops)
|
||||||
|
if b.requestFocus {
|
||||||
|
key.FocusOp{Tag: &b.keyTag}.Add(gtx.Ops)
|
||||||
|
b.requestFocus = false
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
b.focused = false
|
b.focused = false
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user