blob: deea8aca4faecf23713e2ebfbd4417618bacf883 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
package events
type Delta uint64
type DeviceID int
type MouseMotion struct {
Which DeviceID
Dx, Dy float32
Delta
}
type MousePress struct {
Delta
Key uint8
Which DeviceID
JustPressed, JustReleased, IsPressed bool
}
type WindowChange struct {
Height, Width int32
}
type KeyPress struct {
Delta
Key string
Which DeviceID
JustPressed, JustReleased, IsPressed bool
}
type Event interface {
KeyPress | WindowChange | MousePress | MouseMotion
}
type Events []any
func OfType[T Event](events ...any) []T {
var result []T
for _, e := range events {
if eT, ok := e.(T); ok {
result = append(result, eT)
}
}
return result
}
|