all: [API] deliver key events to the first matching filter

Replace the key.Filter.Target field with a Focus field that matches only
of the specified tag has focus. This has the advantage of simpler event
delivery and for lower latency in delivering key events to new handlers.

For example, consider a UI where a button is activated by a key press,
which is turn displays a dialog with another button activated by the
same key. This change allows two button press(+releases) in the same frame
to arrive at the intended targets: one key press(+release) for each
button.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2023-11-26 17:54:51 -06:00
parent d9a007586c
commit ed0d5d5767
9 changed files with 169 additions and 184 deletions
+5 -10
View File
@@ -64,17 +64,12 @@ func (e *Enum) Update(gtx layout.Context) bool {
}
}
}
filters := []event.Filter{
key.FocusFilter{Target: &state.tag},
}
if e.focused && e.focus == state.key {
filters = append(filters,
key.Filter{Target: &state.tag, Name: key.NameReturn},
key.Filter{Target: &state.tag, Name: key.NameSpace},
)
}
for {
ev, ok := gtx.Event(filters...)
ev, ok := gtx.Event(
key.FocusFilter{Target: &state.tag},
key.Filter{Focus: &state.tag, Name: key.NameReturn},
key.Filter{Focus: &state.tag, Name: key.NameSpace},
)
if !ok {
break
}