io/input: [API] introduce Source, the interface between a Router and widgets

This change gets rid of the event.Queue interface by replacing it with
input.Source values. Source provides the interface to Router necessary
to implement interface widgets.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2023-10-08 17:56:03 -05:00
parent c319f3c214
commit 6027517949
31 changed files with 106 additions and 127 deletions
+4 -5
View File
@@ -40,13 +40,13 @@ func (e *Enum) index(k string) *enumKey {
// Update the state and report whether Value has changed by user interaction.
func (e *Enum) Update(gtx layout.Context) bool {
if gtx.Source == nil {
if !gtx.Enabled() {
e.focused = false
}
e.hovering = false
changed := false
for _, state := range e.keys {
for _, ev := range state.click.Update(gtx) {
for _, ev := range state.click.Update(gtx.Source) {
switch ev.Kind {
case gesture.KindPress:
if ev.Source == pointer.Mouse {
@@ -117,12 +117,11 @@ func (e *Enum) Layout(gtx layout.Context, k string, content layout.Widget) layou
}
clk := &state.click
clk.Add(gtx.Ops)
enabled := gtx.Source != nil
if enabled {
if gtx.Enabled() {
key.InputOp{Tag: &state.tag, Keys: "⏎|Space"}.Add(gtx.Ops)
}
semantic.SelectedOp(k == e.Value).Add(gtx.Ops)
semantic.EnabledOp(enabled).Add(gtx.Ops)
semantic.EnabledOp(gtx.Enabled()).Add(gtx.Ops)
c.Add(gtx.Ops)
return dims