mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 18:05:35 +00:00
op: move Ops internal methods and state to internal package ops
Merge package opconsts into ops as well; it only existed to break import cycles. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
package clipboard
|
||||
|
||||
import (
|
||||
"gioui.org/internal/opconst"
|
||||
"gioui.org/internal/ops"
|
||||
"gioui.org/io/event"
|
||||
"gioui.org/op"
|
||||
)
|
||||
@@ -25,13 +25,13 @@ type WriteOp struct {
|
||||
}
|
||||
|
||||
func (h ReadOp) Add(o *op.Ops) {
|
||||
data := o.Write1(opconst.TypeClipboardReadLen, h.Tag)
|
||||
data[0] = byte(opconst.TypeClipboardRead)
|
||||
data := o.Internal.Write1(ops.TypeClipboardReadLen, h.Tag)
|
||||
data[0] = byte(ops.TypeClipboardRead)
|
||||
}
|
||||
|
||||
func (h WriteOp) Add(o *op.Ops) {
|
||||
data := o.Write1(opconst.TypeClipboardWriteLen, &h.Text)
|
||||
data[0] = byte(opconst.TypeClipboardWrite)
|
||||
data := o.Internal.Write1(ops.TypeClipboardWriteLen, &h.Text)
|
||||
data[0] = byte(ops.TypeClipboardWrite)
|
||||
}
|
||||
|
||||
func (Event) ImplementsEvent() {}
|
||||
|
||||
+7
-7
@@ -13,7 +13,7 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"gioui.org/internal/opconst"
|
||||
"gioui.org/internal/ops"
|
||||
"gioui.org/io/event"
|
||||
"gioui.org/op"
|
||||
)
|
||||
@@ -145,22 +145,22 @@ func (h InputOp) Add(o *op.Ops) {
|
||||
if h.Tag == nil {
|
||||
panic("Tag must be non-nil")
|
||||
}
|
||||
data := o.Write1(opconst.TypeKeyInputLen, h.Tag)
|
||||
data[0] = byte(opconst.TypeKeyInput)
|
||||
data := o.Internal.Write1(ops.TypeKeyInputLen, h.Tag)
|
||||
data[0] = byte(ops.TypeKeyInput)
|
||||
data[1] = byte(h.Hint)
|
||||
}
|
||||
|
||||
func (h SoftKeyboardOp) Add(o *op.Ops) {
|
||||
data := o.Write(opconst.TypeKeySoftKeyboardLen)
|
||||
data[0] = byte(opconst.TypeKeySoftKeyboard)
|
||||
data := o.Internal.Write(ops.TypeKeySoftKeyboardLen)
|
||||
data[0] = byte(ops.TypeKeySoftKeyboard)
|
||||
if h.Show {
|
||||
data[1] = 1
|
||||
}
|
||||
}
|
||||
|
||||
func (h FocusOp) Add(o *op.Ops) {
|
||||
data := o.Write1(opconst.TypeKeyFocusLen, h.Tag)
|
||||
data[0] = byte(opconst.TypeKeyFocus)
|
||||
data := o.Internal.Write1(ops.TypeKeyFocusLen, h.Tag)
|
||||
data[0] = byte(ops.TypeKeyFocus)
|
||||
}
|
||||
|
||||
func (EditEvent) ImplementsEvent() {}
|
||||
|
||||
+23
-23
@@ -10,7 +10,7 @@ import (
|
||||
"time"
|
||||
|
||||
"gioui.org/f32"
|
||||
"gioui.org/internal/opconst"
|
||||
"gioui.org/internal/ops"
|
||||
"gioui.org/io/event"
|
||||
"gioui.org/io/key"
|
||||
"gioui.org/op"
|
||||
@@ -56,8 +56,8 @@ type AreaOp struct {
|
||||
|
||||
// AreaStack represents an AreaOp on the stack of areas.
|
||||
type AreaStack struct {
|
||||
ops *op.Ops
|
||||
id op.StackID
|
||||
ops *ops.Ops
|
||||
id ops.StackID
|
||||
macroID int
|
||||
}
|
||||
|
||||
@@ -194,35 +194,35 @@ func Ellipse(size image.Rectangle) AreaOp {
|
||||
|
||||
// Push the current area to the stack and intersects the current area with the
|
||||
// area represented by o.
|
||||
func (o AreaOp) Push(ops *op.Ops) AreaStack {
|
||||
id, macroID := ops.PushOp(op.AreaStack)
|
||||
o.add(ops, true)
|
||||
return AreaStack{ops: ops, id: id, macroID: macroID}
|
||||
func (a AreaOp) Push(o *op.Ops) AreaStack {
|
||||
id, macroID := o.Internal.PushOp(ops.AreaStack)
|
||||
a.add(o, true)
|
||||
return AreaStack{ops: &o.Internal, id: id, macroID: macroID}
|
||||
}
|
||||
|
||||
func (o AreaOp) add(ops *op.Ops, push bool) {
|
||||
data := ops.Write(opconst.TypeAreaLen)
|
||||
data[0] = byte(opconst.TypeArea)
|
||||
data[1] = byte(o.kind)
|
||||
if o.PassThrough {
|
||||
func (a AreaOp) add(o *op.Ops, push bool) {
|
||||
data := o.Internal.Write(ops.TypeAreaLen)
|
||||
data[0] = byte(ops.TypeArea)
|
||||
data[1] = byte(a.kind)
|
||||
if a.PassThrough {
|
||||
data[2] = 1
|
||||
}
|
||||
bo := binary.LittleEndian
|
||||
bo.PutUint32(data[3:], uint32(o.rect.Min.X))
|
||||
bo.PutUint32(data[7:], uint32(o.rect.Min.Y))
|
||||
bo.PutUint32(data[11:], uint32(o.rect.Max.X))
|
||||
bo.PutUint32(data[15:], uint32(o.rect.Max.Y))
|
||||
bo.PutUint32(data[3:], uint32(a.rect.Min.X))
|
||||
bo.PutUint32(data[7:], uint32(a.rect.Min.Y))
|
||||
bo.PutUint32(data[11:], uint32(a.rect.Max.X))
|
||||
bo.PutUint32(data[15:], uint32(a.rect.Max.Y))
|
||||
}
|
||||
|
||||
func (o AreaStack) Pop() {
|
||||
o.ops.PopOp(op.AreaStack, o.id, o.macroID)
|
||||
data := o.ops.Write(opconst.TypePopAreaLen)
|
||||
data[0] = byte(opconst.TypePopArea)
|
||||
o.ops.PopOp(ops.AreaStack, o.id, o.macroID)
|
||||
data := o.ops.Write(ops.TypePopAreaLen)
|
||||
data[0] = byte(ops.TypePopArea)
|
||||
}
|
||||
|
||||
func (op CursorNameOp) Add(o *op.Ops) {
|
||||
data := o.Write1(opconst.TypeCursorLen, op.Name)
|
||||
data[0] = byte(opconst.TypeCursor)
|
||||
data := o.Internal.Write1(ops.TypeCursorLen, op.Name)
|
||||
data[0] = byte(ops.TypeCursor)
|
||||
}
|
||||
|
||||
// Add panics if the scroll range does not contain zero.
|
||||
@@ -233,8 +233,8 @@ func (op InputOp) Add(o *op.Ops) {
|
||||
if b := op.ScrollBounds; b.Min.X > 0 || b.Max.X < 0 || b.Min.Y > 0 || b.Max.Y < 0 {
|
||||
panic(fmt.Errorf("invalid scroll range value %v", b))
|
||||
}
|
||||
data := o.Write1(opconst.TypePointerInputLen, op.Tag)
|
||||
data[0] = byte(opconst.TypePointerInput)
|
||||
data := o.Internal.Write1(ops.TypePointerInputLen, op.Tag)
|
||||
data[0] = byte(ops.TypePointerInput)
|
||||
if op.Grab {
|
||||
data[1] = 1
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
package profile
|
||||
|
||||
import (
|
||||
"gioui.org/internal/opconst"
|
||||
"gioui.org/internal/ops"
|
||||
"gioui.org/io/event"
|
||||
"gioui.org/op"
|
||||
)
|
||||
@@ -24,8 +24,8 @@ type Event struct {
|
||||
}
|
||||
|
||||
func (p Op) Add(o *op.Ops) {
|
||||
data := o.Write1(opconst.TypeProfileLen, p.Tag)
|
||||
data[0] = byte(opconst.TypeProfile)
|
||||
data := o.Internal.Write1(ops.TypeProfileLen, p.Tag)
|
||||
data[0] = byte(ops.TypeProfile)
|
||||
}
|
||||
|
||||
func (p Event) ImplementsEvent() {}
|
||||
|
||||
+8
-9
@@ -3,7 +3,6 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"gioui.org/internal/opconst"
|
||||
"gioui.org/internal/ops"
|
||||
"gioui.org/io/event"
|
||||
"gioui.org/io/key"
|
||||
@@ -61,7 +60,7 @@ func (q *keyQueue) Frame(root *op.Ops, events *handlerEvents) {
|
||||
for _, h := range q.handlers {
|
||||
h.visible, h.new = false, false
|
||||
}
|
||||
q.reader.Reset(root)
|
||||
q.reader.Reset(&root.Internal)
|
||||
|
||||
focus, changed, state := q.resolveFocus(events)
|
||||
for k, h := range q.handlers {
|
||||
@@ -104,19 +103,19 @@ func (q *keyQueue) Push(e event.Event, events *handlerEvents) {
|
||||
|
||||
func (q *keyQueue) resolveFocus(events *handlerEvents) (focus event.Tag, changed bool, state TextInputState) {
|
||||
for encOp, ok := q.reader.Decode(); ok; encOp, ok = q.reader.Decode() {
|
||||
switch opconst.OpType(encOp.Data[0]) {
|
||||
case opconst.TypeKeyFocus:
|
||||
switch ops.OpType(encOp.Data[0]) {
|
||||
case ops.TypeKeyFocus:
|
||||
op := decodeFocusOp(encOp.Data, encOp.Refs)
|
||||
changed = true
|
||||
focus = op.Tag
|
||||
case opconst.TypeKeySoftKeyboard:
|
||||
case ops.TypeKeySoftKeyboard:
|
||||
op := decodeSoftKeyboardOp(encOp.Data, encOp.Refs)
|
||||
if op.Show {
|
||||
state = TextInputOpen
|
||||
} else {
|
||||
state = TextInputClose
|
||||
}
|
||||
case opconst.TypeKeyInput:
|
||||
case ops.TypeKeyInput:
|
||||
op := decodeKeyInputOp(encOp.Data, encOp.Refs)
|
||||
h, ok := q.handlers[op.Tag]
|
||||
if !ok {
|
||||
@@ -131,7 +130,7 @@ func (q *keyQueue) resolveFocus(events *handlerEvents) (focus event.Tag, changed
|
||||
}
|
||||
|
||||
func decodeKeyInputOp(d []byte, refs []interface{}) key.InputOp {
|
||||
if opconst.OpType(d[0]) != opconst.TypeKeyInput {
|
||||
if ops.OpType(d[0]) != ops.TypeKeyInput {
|
||||
panic("invalid op")
|
||||
}
|
||||
return key.InputOp{
|
||||
@@ -141,7 +140,7 @@ func decodeKeyInputOp(d []byte, refs []interface{}) key.InputOp {
|
||||
}
|
||||
|
||||
func decodeSoftKeyboardOp(d []byte, refs []interface{}) key.SoftKeyboardOp {
|
||||
if opconst.OpType(d[0]) != opconst.TypeKeySoftKeyboard {
|
||||
if ops.OpType(d[0]) != ops.TypeKeySoftKeyboard {
|
||||
panic("invalid op")
|
||||
}
|
||||
return key.SoftKeyboardOp{
|
||||
@@ -150,7 +149,7 @@ func decodeSoftKeyboardOp(d []byte, refs []interface{}) key.SoftKeyboardOp {
|
||||
}
|
||||
|
||||
func decodeFocusOp(d []byte, refs []interface{}) key.FocusOp {
|
||||
if opconst.OpType(d[0]) != opconst.TypeKeyFocus {
|
||||
if ops.OpType(d[0]) != ops.TypeKeyFocus {
|
||||
panic("invalid op")
|
||||
}
|
||||
return key.FocusOp{
|
||||
|
||||
+11
-12
@@ -7,7 +7,6 @@ import (
|
||||
"image"
|
||||
|
||||
"gioui.org/f32"
|
||||
"gioui.org/internal/opconst"
|
||||
"gioui.org/internal/ops"
|
||||
"gioui.org/io/event"
|
||||
"gioui.org/io/pointer"
|
||||
@@ -107,15 +106,15 @@ func (q *pointerQueue) collectHandlers(r *ops.Reader, events *handlerEvents) {
|
||||
}
|
||||
reset()
|
||||
for encOp, ok := r.Decode(); ok; encOp, ok = r.Decode() {
|
||||
switch opconst.OpType(encOp.Data[0]) {
|
||||
case opconst.TypeSave:
|
||||
switch ops.OpType(encOp.Data[0]) {
|
||||
case ops.TypeSave:
|
||||
id := ops.DecodeSave(encOp.Data)
|
||||
q.save(id, state.t)
|
||||
case opconst.TypeLoad:
|
||||
case ops.TypeLoad:
|
||||
reset()
|
||||
id := ops.DecodeLoad(encOp.Data)
|
||||
state.t = q.states[id]
|
||||
case opconst.TypeArea:
|
||||
case ops.TypeArea:
|
||||
var op areaOp
|
||||
op.Decode(encOp.Data)
|
||||
area := -1
|
||||
@@ -130,21 +129,21 @@ func (q *pointerQueue) collectHandlers(r *ops.Reader, events *handlerEvents) {
|
||||
area: len(q.areas) - 1,
|
||||
})
|
||||
state.node = len(q.hitTree) - 1
|
||||
case opconst.TypePopArea:
|
||||
case ops.TypePopArea:
|
||||
n := len(q.nodeStack)
|
||||
state.node = q.nodeStack[n-1]
|
||||
q.nodeStack = q.nodeStack[:n-1]
|
||||
case opconst.TypeTransform:
|
||||
case ops.TypeTransform:
|
||||
dop, push := ops.DecodeTransform(encOp.Data)
|
||||
if push {
|
||||
q.transStack = append(q.transStack, state.t)
|
||||
}
|
||||
state.t = state.t.Mul(dop)
|
||||
case opconst.TypePopTransform:
|
||||
case ops.TypePopTransform:
|
||||
n := len(q.transStack)
|
||||
state.t = q.transStack[n-1]
|
||||
q.transStack = q.transStack[:n-1]
|
||||
case opconst.TypePointerInput:
|
||||
case ops.TypePointerInput:
|
||||
op := pointer.InputOp{
|
||||
Tag: encOp.Refs[0].(event.Tag),
|
||||
Grab: encOp.Data[1] != 0,
|
||||
@@ -184,7 +183,7 @@ func (q *pointerQueue) collectHandlers(r *ops.Reader, events *handlerEvents) {
|
||||
Y: int(int32(bo(encOp.Data[15:]))),
|
||||
},
|
||||
}
|
||||
case opconst.TypeCursor:
|
||||
case ops.TypeCursor:
|
||||
q.cursors = append(q.cursors, cursorNode{
|
||||
name: encOp.Refs[0].(pointer.CursorName),
|
||||
area: len(q.areas) - 1,
|
||||
@@ -258,7 +257,7 @@ func (q *pointerQueue) Frame(root *op.Ops, events *handlerEvents) {
|
||||
q.nodeStack = q.nodeStack[:0]
|
||||
q.transStack = q.transStack[:0]
|
||||
q.cursors = q.cursors[:0]
|
||||
q.reader.Reset(root)
|
||||
q.reader.Reset(&root.Internal)
|
||||
q.collectHandlers(&q.reader, events)
|
||||
for k, h := range q.handlers {
|
||||
if !h.active {
|
||||
@@ -476,7 +475,7 @@ func opDecodeFloat32(d []byte) float32 {
|
||||
}
|
||||
|
||||
func (op *areaOp) Decode(d []byte) {
|
||||
if opconst.OpType(d[0]) != opconst.TypeArea {
|
||||
if ops.OpType(d[0]) != ops.TypeArea {
|
||||
panic("invalid op")
|
||||
}
|
||||
rect := f32.Rectangle{
|
||||
|
||||
@@ -761,14 +761,14 @@ func BenchmarkAreaOp_Decode(b *testing.B) {
|
||||
ops := new(op.Ops)
|
||||
pointer.Rect(image.Rectangle{Max: image.Pt(100, 100)}).Push(ops).Pop()
|
||||
for i := 0; i < b.N; i++ {
|
||||
benchAreaOp.Decode(ops.Data())
|
||||
benchAreaOp.Decode(ops.Internal.Data())
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkAreaOp_Hit(b *testing.B) {
|
||||
ops := new(op.Ops)
|
||||
pointer.Rect(image.Rectangle{Max: image.Pt(100, 100)}).Push(ops).Pop()
|
||||
benchAreaOp.Decode(ops.Data())
|
||||
benchAreaOp.Decode(ops.Internal.Data())
|
||||
for i := 0; i < b.N; i++ {
|
||||
benchAreaOp.Hit(f32.Pt(50, 50))
|
||||
}
|
||||
|
||||
+8
-9
@@ -14,7 +14,6 @@ import (
|
||||
"encoding/binary"
|
||||
"time"
|
||||
|
||||
"gioui.org/internal/opconst"
|
||||
"gioui.org/internal/ops"
|
||||
"gioui.org/io/clipboard"
|
||||
"gioui.org/io/event"
|
||||
@@ -68,7 +67,7 @@ func (q *Router) Frame(ops *op.Ops) {
|
||||
for k := range q.profHandlers {
|
||||
delete(q.profHandlers, k)
|
||||
}
|
||||
q.reader.Reset(ops)
|
||||
q.reader.Reset(&ops.Internal)
|
||||
q.collect()
|
||||
|
||||
q.pqueue.Frame(ops, &q.handlers)
|
||||
@@ -126,22 +125,22 @@ func (q *Router) Cursor() pointer.CursorName {
|
||||
|
||||
func (q *Router) collect() {
|
||||
for encOp, ok := q.reader.Decode(); ok; encOp, ok = q.reader.Decode() {
|
||||
switch opconst.OpType(encOp.Data[0]) {
|
||||
case opconst.TypeInvalidate:
|
||||
switch ops.OpType(encOp.Data[0]) {
|
||||
case ops.TypeInvalidate:
|
||||
op := decodeInvalidateOp(encOp.Data)
|
||||
if !q.wakeup || op.At.Before(q.wakeupTime) {
|
||||
q.wakeup = true
|
||||
q.wakeupTime = op.At
|
||||
}
|
||||
case opconst.TypeProfile:
|
||||
case ops.TypeProfile:
|
||||
op := decodeProfileOp(encOp.Data, encOp.Refs)
|
||||
if q.profHandlers == nil {
|
||||
q.profHandlers = make(map[event.Tag]struct{})
|
||||
}
|
||||
q.profHandlers[op.Tag] = struct{}{}
|
||||
case opconst.TypeClipboardRead:
|
||||
case ops.TypeClipboardRead:
|
||||
q.cqueue.ProcessReadClipboard(encOp.Refs)
|
||||
case opconst.TypeClipboardWrite:
|
||||
case ops.TypeClipboardWrite:
|
||||
q.cqueue.ProcessWriteClipboard(encOp.Refs)
|
||||
}
|
||||
}
|
||||
@@ -206,7 +205,7 @@ func (h *handlerEvents) Clear() {
|
||||
}
|
||||
|
||||
func decodeProfileOp(d []byte, refs []interface{}) profile.Op {
|
||||
if opconst.OpType(d[0]) != opconst.TypeProfile {
|
||||
if ops.OpType(d[0]) != ops.TypeProfile {
|
||||
panic("invalid op")
|
||||
}
|
||||
return profile.Op{
|
||||
@@ -216,7 +215,7 @@ func decodeProfileOp(d []byte, refs []interface{}) profile.Op {
|
||||
|
||||
func decodeInvalidateOp(d []byte) op.InvalidateOp {
|
||||
bo := binary.LittleEndian
|
||||
if opconst.OpType(d[0]) != opconst.TypeInvalidate {
|
||||
if ops.OpType(d[0]) != ops.TypeInvalidate {
|
||||
panic("invalid op")
|
||||
}
|
||||
var o op.InvalidateOp
|
||||
|
||||
Reference in New Issue
Block a user