Now (*widget.Selectable).Update() returns whether the selection changed during
event processing, rather than requiring a separate call to (*widget.Selectable).Events().
The Events() method has been removed as redundant.
Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
This commit eliminates (*widget.Editor).Events() in favor of making
(*widget.Editor).Update() return events as they are generated in response to
input. This makes the behavior of the editor match the rest of the core widgets.
Callers who previously invoked Events() can now achieve the same thing by using
a loop like this:
for {
ev, ok := editor.Update(gtx)
if !ok {
break
}
// Handle ev
}
This is undeniably more verbose, but it enables more sophisticated event processing.
Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
The method no longer returns anything, and thus does not actually report
whether any events matched a handler.
Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
Widgets have themselves as tags, by convention, and so it's possible to
replace the per-widget Focused methods with a general-purpose Source.
Focused query.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
The empty key.Filter.Name now means matching every key name. This is a
replacement for the previous special case where the top-level key.InputOp
handler would get all unmatched events.
Add special case for system events such as focus switch shortcuts.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
New handlers receive reset events the first time Source.Event is called.
However, in case the filter doesn't match a reset event it shouldn't be
reported.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
It's semantically problematic that a zero Kind matches Cancel, and
outweighs the downside of having to explicitly mention Cancel in filters.
For example, GrabCmd was always deferred because the resulting Cancel
events always match the processed filters.
Remove Frame from a few tests now that GrabCmd can be executed
immediately.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
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>
Until now, every event has had a particular target. We're about to simplify
key event delivery to match the first matching filter, so there is no
longer a global meaning to the tag argument to Source.Event.
Add fields to filters to specify their target tags.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
If the client asks for the focus to be set to a tag, allow it. There is a
check at the end of Router.Frame that clears the focus if the tag turns
out to fail the requirements (visible and has asked for FocusEvents).
The change simplifies the logic for determining whether a command can
be executed immediately.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
Now that widgets by convention may be focused by issuing FocusCmd
directly, remove the now redundant Focus methods on Clickable, Editor,
Selectable.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
We're about to replace the per-widget Focus methods with the client
executing FocusCmd themselves. To ensure the soft keyboard is not
forgotten, ask to show it automatically on focus.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
With the introduction of filters, it is now possible to have one tag per
widget by convention. Note that gestures still have their own tags, for
disambiguation.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
Processing one event at a time allows a widget to execute commands after
the event that triggered it, instead of after all matching events.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
Change the semantics of commands to execute immediately. In cases where
execution of a command introduces a inconsistency, freeze event routing
and defer the command as well as queued events to the next frame.
Rename Source.Queue to Source.Execute to better fit the new command
semantics.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
Refactor the pointer and key filter unions into the handler state struct.
This is a preparation for replacing calls to filtersMatches with queries
to the filter union.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
We're about to need per-handler state related to neither pointer nor
key input. This change merges the pointer and key handler state into one
state struct, tracked in the Router.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This change defers event routing from the time the event is queued until
the time Events is called. This allows a future change to execute
commands immediately and to react to event order changes during a frame.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
Replace the per-event event queues with a single queue of events, each
marked with the target tag. This change is a prerequisite for lazy event
delivery.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
We're about the refactor this quite subtle code, and the optimization
doesn't seem to carry its weight in complexity.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
Refactor delivery of reset events to be resolved and delivered as part of
Source.Events. This is a preparation for changing event handling to be
lazy.
Reset events are delivered to event handlers that are either new or
haven't been active in the previous frame for a particular event type
(pointer or key events), to ensure the handler state is reset.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
We're about to replace key.InputOp with a filter; this change separates
the input hint into its own operation.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
Instead of having to supply the predicates for event filtering at the
time of layout, the new Filter type allows widgets to filter at the time
of calling Source.Events. There is then only the need for a single input
op type, in package event.
Filters most importantly allow the use of one tag for several event types,
and we can define that a widget w has &w as its primary tag, by convention.
This allows the replacement of per-widget Focus methods with direct uses
of FocusCmd{&w}, and the later addition of Source.Focused(&w) queries.
Note that the TestCursor test needed restructuring to avoid its use of
InputOps.
Signed-off-by: Elias Naur <mail@eliasnaur.com>