mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-05 17:35:36 +00:00
io/event: move event types from package ui to its own package
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
// SPDX-License-Identifier: Unlicense OR MIT
|
||||
|
||||
/*
|
||||
Package event contains the types for event handling.
|
||||
|
||||
The Queue interface is the protocol for receiving external events.
|
||||
|
||||
For example:
|
||||
|
||||
var queue event.Queue = ...
|
||||
|
||||
for _, e := range queue.Events(h) {
|
||||
switch e.(type) {
|
||||
...
|
||||
}
|
||||
}
|
||||
|
||||
In general, handlers must be declared before events become
|
||||
available. Other packages such as pointer and key provide
|
||||
the means for declaring handlers for specific event types.
|
||||
|
||||
The following example declares a handler ready for key input:
|
||||
|
||||
import gioui.org/io/key
|
||||
|
||||
ops := new(ui.Ops)
|
||||
var h *Handler = ...
|
||||
key.InputOp{Key: h}.Add(ops)
|
||||
|
||||
*/
|
||||
package event
|
||||
|
||||
// Queue maps an event handler key to the events
|
||||
// available to the handler.
|
||||
type Queue interface {
|
||||
// Events returns the available events for a
|
||||
// Key.
|
||||
Events(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 events.
|
||||
type Event interface {
|
||||
ImplementsEvent()
|
||||
}
|
||||
+3
-2
@@ -10,8 +10,9 @@ events.
|
||||
package key
|
||||
|
||||
import (
|
||||
"gioui.org/ui"
|
||||
"gioui.org/internal/opconst"
|
||||
"gioui.org/io/event"
|
||||
"gioui.org/ui"
|
||||
)
|
||||
|
||||
// InputOp declares a handler ready for key events.
|
||||
@@ -19,7 +20,7 @@ import (
|
||||
// focused key handler. Set the Focus flag to request
|
||||
// the focus.
|
||||
type InputOp struct {
|
||||
Key ui.Key
|
||||
Key event.Key
|
||||
Focus bool
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ A pointer is either a mouse controlled cursor or a touch
|
||||
object such as a finger.
|
||||
|
||||
The InputOp operation is used to declare a handler ready for pointer
|
||||
events. Use a ui.Queue to receive events.
|
||||
events. Use an event.Queue to receive events.
|
||||
|
||||
Areas
|
||||
|
||||
|
||||
@@ -7,9 +7,10 @@ import (
|
||||
"image"
|
||||
"time"
|
||||
|
||||
"gioui.org/ui"
|
||||
"gioui.org/f32"
|
||||
"gioui.org/internal/opconst"
|
||||
"gioui.org/io/event"
|
||||
"gioui.org/ui"
|
||||
)
|
||||
|
||||
// Event is a pointer event.
|
||||
@@ -63,7 +64,7 @@ type areaOp struct {
|
||||
// InputOp declares an input handler ready for pointer
|
||||
// events.
|
||||
type InputOp struct {
|
||||
Key ui.Key
|
||||
Key event.Key
|
||||
// Grab, if set, request that the handler get
|
||||
// Grabbed priority.
|
||||
Grab bool
|
||||
|
||||
@@ -6,13 +6,14 @@ package profile
|
||||
|
||||
import (
|
||||
"gioui.org/internal/opconst"
|
||||
"gioui.org/io/event"
|
||||
"gioui.org/ui"
|
||||
)
|
||||
|
||||
// Op registers a handler for receiving
|
||||
// Events.
|
||||
type Op struct {
|
||||
Key ui.Key
|
||||
Key event.Key
|
||||
}
|
||||
|
||||
// Event contains profile data from a single
|
||||
|
||||
Reference in New Issue
Block a user