ui: add package input for merged input

To avoid passing a queue type for each kind of input (pointer, key),
introduce package input for mapping a handler key to all input events.

Future input sources can be added without changes to programs, and
as an added bonus, event ordering is preserved across input sources.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-06-07 21:41:09 +02:00
parent 28dd25736f
commit a35118d522
10 changed files with 172 additions and 130 deletions
+20
View File
@@ -0,0 +1,20 @@
// SPDX-License-Identifier: Unlicense OR MIT
// Package input exposes a unified interface to input sources. Subpackages
// such as pointer and key provide the interfaces for specific input types.
package input
// Events maps an event handler key to the events
// available to the handler.
type Events interface {
For(k Key) []Event
}
// Key is the stable identifier for an event handler. For a handler h, the
// key is typically &h.
type Key interface{}
// Event is the marker interface for input events.
type Event interface {
ImplementsInputEvent()
}