mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
io: give event packages a common prefix
Packages that provide support for external events such as pointer, key and system are only the beginning. Future packages are expected for clipboard access, drag and drop, gps positions and so on. To keep the number of top-level packages under control, move such I/O packages to the new `io` directory. The `system` package name was the previous solution to keeping the number of top-level packages under control: I named it `system` instead of the narrower `profile` because I expected to put all the less common events into it, turning `system` into a "package util" smell. With `io`, package system can be renamed to `profile`. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -3,10 +3,10 @@
|
||||
package input
|
||||
|
||||
import (
|
||||
"gioui.org/ui"
|
||||
"gioui.org/internal/opconst"
|
||||
"gioui.org/internal/ops"
|
||||
"gioui.org/key"
|
||||
"gioui.org/io/key"
|
||||
"gioui.org/ui"
|
||||
)
|
||||
|
||||
type TextInputState uint8
|
||||
|
||||
@@ -6,11 +6,11 @@ import (
|
||||
"encoding/binary"
|
||||
"image"
|
||||
|
||||
"gioui.org/ui"
|
||||
"gioui.org/f32"
|
||||
"gioui.org/internal/opconst"
|
||||
"gioui.org/internal/ops"
|
||||
"gioui.org/pointer"
|
||||
"gioui.org/io/pointer"
|
||||
"gioui.org/ui"
|
||||
)
|
||||
|
||||
type pointerQueue struct {
|
||||
|
||||
@@ -6,12 +6,12 @@ import (
|
||||
"encoding/binary"
|
||||
"time"
|
||||
|
||||
"gioui.org/ui"
|
||||
"gioui.org/internal/opconst"
|
||||
"gioui.org/internal/ops"
|
||||
"gioui.org/key"
|
||||
"gioui.org/pointer"
|
||||
"gioui.org/system"
|
||||
"gioui.org/io/key"
|
||||
"gioui.org/io/pointer"
|
||||
"gioui.org/io/profile"
|
||||
"gioui.org/ui"
|
||||
)
|
||||
|
||||
// Router is a Queue implementation that routes events from
|
||||
@@ -98,7 +98,7 @@ func (q *Router) collect() {
|
||||
}
|
||||
}
|
||||
|
||||
func (q *Router) AddProfile(e system.ProfileEvent) {
|
||||
func (q *Router) AddProfile(e profile.Event) {
|
||||
for _, h := range q.profHandlers {
|
||||
q.handlers.Add(h, e)
|
||||
}
|
||||
@@ -150,11 +150,11 @@ func (h *handlerEvents) Clear() {
|
||||
}
|
||||
}
|
||||
|
||||
func decodeProfileOp(d []byte, refs []interface{}) system.ProfileOp {
|
||||
func decodeProfileOp(d []byte, refs []interface{}) profile.Op {
|
||||
if opconst.OpType(d[0]) != opconst.TypeProfile {
|
||||
panic("invalid op")
|
||||
}
|
||||
return system.ProfileOp{
|
||||
return profile.Op{
|
||||
Key: refs[0].(ui.Key),
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -24,10 +24,10 @@ import (
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
"gioui.org/ui"
|
||||
"gioui.org/f32"
|
||||
"gioui.org/key"
|
||||
"gioui.org/pointer"
|
||||
"gioui.org/io/key"
|
||||
"gioui.org/io/pointer"
|
||||
"gioui.org/ui"
|
||||
)
|
||||
|
||||
type window struct {
|
||||
|
||||
+3
-3
@@ -22,10 +22,10 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"gioui.org/ui"
|
||||
"gioui.org/f32"
|
||||
"gioui.org/key"
|
||||
"gioui.org/pointer"
|
||||
"gioui.org/io/key"
|
||||
"gioui.org/io/pointer"
|
||||
"gioui.org/ui"
|
||||
)
|
||||
|
||||
type window struct {
|
||||
|
||||
+2
-2
@@ -9,8 +9,8 @@ import (
|
||||
"time"
|
||||
|
||||
"gioui.org/f32"
|
||||
"gioui.org/key"
|
||||
"gioui.org/pointer"
|
||||
"gioui.org/io/key"
|
||||
"gioui.org/io/pointer"
|
||||
)
|
||||
|
||||
type window struct {
|
||||
|
||||
+2
-2
@@ -20,8 +20,8 @@ import (
|
||||
"unsafe"
|
||||
|
||||
"gioui.org/f32"
|
||||
"gioui.org/key"
|
||||
"gioui.org/pointer"
|
||||
"gioui.org/io/key"
|
||||
"gioui.org/io/pointer"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
+2
-2
@@ -18,8 +18,8 @@ import (
|
||||
|
||||
"gioui.org/f32"
|
||||
"gioui.org/internal/fling"
|
||||
"gioui.org/key"
|
||||
"gioui.org/pointer"
|
||||
"gioui.org/io/key"
|
||||
"gioui.org/io/pointer"
|
||||
syscall "golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
|
||||
+2
-2
@@ -15,8 +15,8 @@ import (
|
||||
syscall "golang.org/x/sys/windows"
|
||||
|
||||
"gioui.org/f32"
|
||||
"gioui.org/key"
|
||||
"gioui.org/pointer"
|
||||
"gioui.org/io/key"
|
||||
"gioui.org/io/pointer"
|
||||
)
|
||||
|
||||
var winMap = make(map[syscall.Handle]*window)
|
||||
|
||||
+3
-3
@@ -8,10 +8,10 @@ import (
|
||||
"image"
|
||||
"time"
|
||||
|
||||
"gioui.org/ui"
|
||||
"gioui.org/app/internal/gpu"
|
||||
"gioui.org/app/internal/input"
|
||||
"gioui.org/system"
|
||||
"gioui.org/io/profile"
|
||||
"gioui.org/ui"
|
||||
)
|
||||
|
||||
// WindowOption configures a Window.
|
||||
@@ -144,7 +144,7 @@ func (w *Window) draw(size image.Point, frame *ui.Ops) {
|
||||
if w.queue.q.Profiling() {
|
||||
q := 100 * time.Microsecond
|
||||
timings := fmt.Sprintf("tot:%7s cpu:%7s %s", frameDur.Round(q), drawDur.Round(q), w.gpu.Timings())
|
||||
w.queue.q.AddProfile(system.ProfileEvent{Timings: timings})
|
||||
w.queue.q.AddProfile(profile.Event{Timings: timings})
|
||||
w.setNextFrame(time.Time{})
|
||||
}
|
||||
if t, ok := w.queue.q.WakeupTime(); ok {
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ import (
|
||||
"unicode/utf8"
|
||||
"unsafe"
|
||||
|
||||
"gioui.org/key"
|
||||
"gioui.org/io/key"
|
||||
)
|
||||
|
||||
type xkb struct {
|
||||
|
||||
+2
-2
@@ -12,10 +12,10 @@ package gesture
|
||||
import (
|
||||
"math"
|
||||
|
||||
"gioui.org/ui"
|
||||
"gioui.org/f32"
|
||||
"gioui.org/internal/fling"
|
||||
"gioui.org/pointer"
|
||||
"gioui.org/io/pointer"
|
||||
"gioui.org/ui"
|
||||
)
|
||||
|
||||
// Click detects click gestures in the form
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
// SPDX-License-Identifier: Unlicense OR MIT
|
||||
|
||||
// Package profiles provides access to rendering
|
||||
// profiles.
|
||||
package profile
|
||||
|
||||
import (
|
||||
"gioui.org/internal/opconst"
|
||||
"gioui.org/ui"
|
||||
)
|
||||
|
||||
// Op registers a handler for receiving
|
||||
// Events.
|
||||
type Op struct {
|
||||
Key ui.Key
|
||||
}
|
||||
|
||||
// Event contains profile data from a single
|
||||
// rendered frame.
|
||||
type Event struct {
|
||||
// Timings. Very likely to change.
|
||||
Timings string
|
||||
}
|
||||
|
||||
func (p Op) Add(o *ui.Ops) {
|
||||
data := make([]byte, opconst.TypeProfileLen)
|
||||
data[0] = byte(opconst.TypeProfile)
|
||||
o.Write(data, p.Key)
|
||||
}
|
||||
|
||||
func (p Event) ImplementsEvent() {}
|
||||
+2
-2
@@ -5,10 +5,10 @@ package layout
|
||||
import (
|
||||
"image"
|
||||
|
||||
"gioui.org/ui"
|
||||
"gioui.org/gesture"
|
||||
"gioui.org/io/pointer"
|
||||
"gioui.org/paint"
|
||||
"gioui.org/pointer"
|
||||
"gioui.org/ui"
|
||||
)
|
||||
|
||||
type scrollChild struct {
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
// SPDX-License-Identifier: Unlicense OR MIT
|
||||
|
||||
// Package system contain ops and types for
|
||||
// system events.
|
||||
package system
|
||||
|
||||
import (
|
||||
"gioui.org/ui"
|
||||
"gioui.org/internal/opconst"
|
||||
)
|
||||
|
||||
// ProfileOp registers a handler for receiving
|
||||
// ProfileEvents.
|
||||
type ProfileOp struct {
|
||||
Key ui.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, opconst.TypeProfileLen)
|
||||
data[0] = byte(opconst.TypeProfile)
|
||||
o.Write(data, p.Key)
|
||||
}
|
||||
|
||||
func (p ProfileEvent) ImplementsEvent() {}
|
||||
+3
-3
@@ -9,12 +9,12 @@ import (
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
|
||||
"gioui.org/ui"
|
||||
"gioui.org/gesture"
|
||||
"gioui.org/key"
|
||||
"gioui.org/io/key"
|
||||
"gioui.org/io/pointer"
|
||||
"gioui.org/layout"
|
||||
"gioui.org/paint"
|
||||
"gioui.org/pointer"
|
||||
"gioui.org/ui"
|
||||
|
||||
"golang.org/x/image/math/fixed"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user