forked from joejulian/gio
cb312c8d32
input.Event is enough if we stretch "input" to mean both input devices and other events such as profiling events and system commands. The pointer and key packages are separate already, so I don't expanding the meaning is unreasonable. Signed-off-by: Elias Naur <mail@eliasnaur.com>
42 lines
830 B
Go
42 lines
830 B
Go
// SPDX-License-Identifier: Unlicense OR MIT
|
|
|
|
// Package system contain ops and types for
|
|
// system events.
|
|
package system
|
|
|
|
import (
|
|
"gioui.org/ui"
|
|
"gioui.org/ui/input"
|
|
"gioui.org/ui/internal/ops"
|
|
)
|
|
|
|
// ProfileOp registers a handler for receiving
|
|
// ProfileEvents.
|
|
type ProfileOp struct {
|
|
Key input.Key
|
|
}
|
|
|
|
// ProfileEvent contain profile data from a single
|
|
// rendered frame.
|
|
type ProfileEvent struct {
|
|
// String with timings. Very likely to change.
|
|
Timings string
|
|
}
|
|
|
|
func (p ProfileOp) Add(o *ui.Ops) {
|
|
data := make([]byte, ops.TypeProfileLen)
|
|
data[0] = byte(ops.TypeProfile)
|
|
o.Write(data, p.Key)
|
|
}
|
|
|
|
func (p *ProfileOp) Decode(d []byte, refs []interface{}) {
|
|
if ops.OpType(d[0]) != ops.TypeProfile {
|
|
panic("invalid op")
|
|
}
|
|
*p = ProfileOp{
|
|
Key: refs[0].(input.Key),
|
|
}
|
|
}
|
|
|
|
func (p ProfileEvent) ImplementsEvent() {}
|