mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 09:55:40 +00:00
all: remove exported Decode methods on operations
Add decode functions to the packages that need them instead. For TransformOp that is used in multiple packages, add the decode function to the internal ops package. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -144,6 +144,61 @@ func (op *clipOp) decode(data []byte) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func decodeImageOp(data []byte, refs []interface{}) gdraw.ImageOp {
|
||||||
|
bo := binary.LittleEndian
|
||||||
|
if opconst.OpType(data[0]) != opconst.TypeImage {
|
||||||
|
panic("invalid op")
|
||||||
|
}
|
||||||
|
sr := image.Rectangle{
|
||||||
|
Min: image.Point{
|
||||||
|
X: int(int32(bo.Uint32(data[1:]))),
|
||||||
|
Y: int(int32(bo.Uint32(data[5:]))),
|
||||||
|
},
|
||||||
|
Max: image.Point{
|
||||||
|
X: int(int32(bo.Uint32(data[9:]))),
|
||||||
|
Y: int(int32(bo.Uint32(data[13:]))),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
return gdraw.ImageOp{
|
||||||
|
Src: refs[0].(image.Image),
|
||||||
|
Rect: sr,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func decodeColorOp(data []byte, refs []interface{}) gdraw.ColorOp {
|
||||||
|
if opconst.OpType(data[0]) != opconst.TypeColor {
|
||||||
|
panic("invalid op")
|
||||||
|
}
|
||||||
|
return gdraw.ColorOp{
|
||||||
|
Color: color.RGBA{
|
||||||
|
R: data[1],
|
||||||
|
G: data[2],
|
||||||
|
B: data[3],
|
||||||
|
A: data[4],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func decodeDrawOp(data []byte, refs []interface{}) gdraw.DrawOp {
|
||||||
|
bo := binary.LittleEndian
|
||||||
|
if opconst.OpType(data[0]) != opconst.TypeDraw {
|
||||||
|
panic("invalid op")
|
||||||
|
}
|
||||||
|
r := f32.Rectangle{
|
||||||
|
Min: f32.Point{
|
||||||
|
X: math.Float32frombits(bo.Uint32(data[1:])),
|
||||||
|
Y: math.Float32frombits(bo.Uint32(data[5:])),
|
||||||
|
},
|
||||||
|
Max: f32.Point{
|
||||||
|
X: math.Float32frombits(bo.Uint32(data[9:])),
|
||||||
|
Y: math.Float32frombits(bo.Uint32(data[13:])),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
return gdraw.DrawOp{
|
||||||
|
Rect: r,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type clipType uint8
|
type clipType uint8
|
||||||
|
|
||||||
type resource interface {
|
type resource interface {
|
||||||
@@ -649,9 +704,8 @@ loop:
|
|||||||
for encOp, ok := r.Decode(); ok; encOp, ok = r.Decode() {
|
for encOp, ok := r.Decode(); ok; encOp, ok = r.Decode() {
|
||||||
switch opconst.OpType(encOp.Data[0]) {
|
switch opconst.OpType(encOp.Data[0]) {
|
||||||
case opconst.TypeTransform:
|
case opconst.TypeTransform:
|
||||||
var op ui.TransformOp
|
op := ops.DecodeTransformOp(encOp.Data)
|
||||||
op.Decode(encOp.Data)
|
state.t = state.t.Multiply(ui.TransformOp(op))
|
||||||
state.t = state.t.Multiply(op)
|
|
||||||
case opconst.TypeAux:
|
case opconst.TypeAux:
|
||||||
aux = encOp.Data[opconst.TypeAuxLen:]
|
aux = encOp.Data[opconst.TypeAuxLen:]
|
||||||
auxKey = encOp.Key
|
auxKey = encOp.Key
|
||||||
@@ -679,18 +733,15 @@ loop:
|
|||||||
aux = nil
|
aux = nil
|
||||||
auxKey = ops.Key{}
|
auxKey = ops.Key{}
|
||||||
case opconst.TypeColor:
|
case opconst.TypeColor:
|
||||||
var op gdraw.ColorOp
|
op := decodeColorOp(encOp.Data, encOp.Refs)
|
||||||
op.Decode(encOp.Data, encOp.Refs)
|
|
||||||
state.img = nil
|
state.img = nil
|
||||||
state.color = op.Color
|
state.color = op.Color
|
||||||
case opconst.TypeImage:
|
case opconst.TypeImage:
|
||||||
var op gdraw.ImageOp
|
op := decodeImageOp(encOp.Data, encOp.Refs)
|
||||||
op.Decode(encOp.Data, encOp.Refs)
|
|
||||||
state.img = op.Src
|
state.img = op.Src
|
||||||
state.imgRect = op.Rect
|
state.imgRect = op.Rect
|
||||||
case opconst.TypeDraw:
|
case opconst.TypeDraw:
|
||||||
var op gdraw.DrawOp
|
op := decodeDrawOp(encOp.Data, encOp.Refs)
|
||||||
op.Decode(encOp.Data, encOp.Refs)
|
|
||||||
off := state.t.Transform(f32.Point{})
|
off := state.t.Transform(f32.Point{})
|
||||||
clip := state.clip.Intersect(op.Rect.Add(off))
|
clip := state.clip.Intersect(op.Rect.Add(off))
|
||||||
if clip.Empty() {
|
if clip.Empty() {
|
||||||
|
|||||||
@@ -97,8 +97,7 @@ loop:
|
|||||||
for encOp, ok := q.reader.Decode(); ok; encOp, ok = q.reader.Decode() {
|
for encOp, ok := q.reader.Decode(); ok; encOp, ok = q.reader.Decode() {
|
||||||
switch opconst.OpType(encOp.Data[0]) {
|
switch opconst.OpType(encOp.Data[0]) {
|
||||||
case opconst.TypeKeyHandler:
|
case opconst.TypeKeyHandler:
|
||||||
var op key.HandlerOp
|
op := decodeKeyHandlerOp(encOp.Data, encOp.Refs)
|
||||||
op.Decode(encOp.Data, encOp.Refs)
|
|
||||||
var newPri listenerPriority
|
var newPri listenerPriority
|
||||||
switch {
|
switch {
|
||||||
case op.Focus:
|
case op.Focus:
|
||||||
@@ -139,3 +138,13 @@ func (p listenerPriority) replaces(p2 listenerPriority) bool {
|
|||||||
// Favor earliest default focus or latest requested focus.
|
// Favor earliest default focus or latest requested focus.
|
||||||
return p > p2 || p == p2 && p == priNewFocus
|
return p > p2 || p == p2 && p == priNewFocus
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func decodeKeyHandlerOp(d []byte, refs []interface{}) key.HandlerOp {
|
||||||
|
if opconst.OpType(d[0]) != opconst.TypeKeyHandler {
|
||||||
|
panic("invalid op")
|
||||||
|
}
|
||||||
|
return key.HandlerOp{
|
||||||
|
Focus: d[1] != 0,
|
||||||
|
Key: refs[0].(input.Key),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -72,8 +72,7 @@ func (q *pointerQueue) collectHandlers(r *ops.Reader, events *handlerEvents, t u
|
|||||||
case opconst.TypePop:
|
case opconst.TypePop:
|
||||||
return
|
return
|
||||||
case opconst.TypePass:
|
case opconst.TypePass:
|
||||||
var op pointer.PassOp
|
op := decodePassOp(encOp.Data)
|
||||||
op.Decode(encOp.Data)
|
|
||||||
pass = op.Pass
|
pass = op.Pass
|
||||||
case opconst.TypeArea:
|
case opconst.TypeArea:
|
||||||
var op areaOp
|
var op areaOp
|
||||||
@@ -87,12 +86,10 @@ func (q *pointerQueue) collectHandlers(r *ops.Reader, events *handlerEvents, t u
|
|||||||
})
|
})
|
||||||
node = len(q.hitTree) - 1
|
node = len(q.hitTree) - 1
|
||||||
case opconst.TypeTransform:
|
case opconst.TypeTransform:
|
||||||
var op ui.TransformOp
|
op := ops.DecodeTransformOp(encOp.Data)
|
||||||
op.Decode(encOp.Data)
|
t = t.Multiply(ui.TransformOp(op))
|
||||||
t = t.Multiply(op)
|
|
||||||
case opconst.TypePointerHandler:
|
case opconst.TypePointerHandler:
|
||||||
var op pointer.HandlerOp
|
op := decodePointerHandlerOp(encOp.Data, encOp.Refs)
|
||||||
op.Decode(encOp.Data, encOp.Refs)
|
|
||||||
q.hitTree = append(q.hitTree, hitNode{
|
q.hitTree = append(q.hitTree, hitNode{
|
||||||
next: node,
|
next: node,
|
||||||
area: area,
|
area: area,
|
||||||
@@ -316,3 +313,22 @@ func (op *areaOp) Hit(pos f32.Point) bool {
|
|||||||
panic("invalid area kind")
|
panic("invalid area kind")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func decodePointerHandlerOp(d []byte, refs []interface{}) pointer.HandlerOp {
|
||||||
|
if opconst.OpType(d[0]) != opconst.TypePointerHandler {
|
||||||
|
panic("invalid op")
|
||||||
|
}
|
||||||
|
return pointer.HandlerOp{
|
||||||
|
Grab: d[1] != 0,
|
||||||
|
Key: refs[0].(input.Key),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func decodePassOp(d []byte) pointer.PassOp {
|
||||||
|
if opconst.OpType(d[0]) != opconst.TypePass {
|
||||||
|
panic("invalid op")
|
||||||
|
}
|
||||||
|
return pointer.PassOp{
|
||||||
|
Pass: d[1] != 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
package input
|
package input
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/binary"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gioui.org/ui"
|
"gioui.org/ui"
|
||||||
@@ -74,15 +75,13 @@ func (q *Router) collect() {
|
|||||||
for encOp, ok := q.reader.Decode(); ok; encOp, ok = q.reader.Decode() {
|
for encOp, ok := q.reader.Decode(); ok; encOp, ok = q.reader.Decode() {
|
||||||
switch opconst.OpType(encOp.Data[0]) {
|
switch opconst.OpType(encOp.Data[0]) {
|
||||||
case opconst.TypeInvalidate:
|
case opconst.TypeInvalidate:
|
||||||
var op ui.InvalidateOp
|
op := decodeInvalidateOp(encOp.Data)
|
||||||
op.Decode(encOp.Data)
|
|
||||||
if !q.wakeup || op.At.Before(q.wakeupTime) {
|
if !q.wakeup || op.At.Before(q.wakeupTime) {
|
||||||
q.wakeup = true
|
q.wakeup = true
|
||||||
q.wakeupTime = op.At
|
q.wakeupTime = op.At
|
||||||
}
|
}
|
||||||
case opconst.TypeProfile:
|
case opconst.TypeProfile:
|
||||||
var op system.ProfileOp
|
op := decodeProfileOp(encOp.Data, encOp.Refs)
|
||||||
op.Decode(encOp.Data, encOp.Refs)
|
|
||||||
q.profHandlers = append(q.profHandlers, op.Key)
|
q.profHandlers = append(q.profHandlers, op.Key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -141,3 +140,24 @@ func (h *handlerEvents) Clear() {
|
|||||||
delete(h.handlers, k)
|
delete(h.handlers, k)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func decodeProfileOp(d []byte, refs []interface{}) system.ProfileOp {
|
||||||
|
if opconst.OpType(d[0]) != opconst.TypeProfile {
|
||||||
|
panic("invalid op")
|
||||||
|
}
|
||||||
|
return system.ProfileOp{
|
||||||
|
Key: refs[0].(input.Key),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func decodeInvalidateOp(d []byte) ui.InvalidateOp {
|
||||||
|
bo := binary.LittleEndian
|
||||||
|
if opconst.OpType(d[0]) != opconst.TypeInvalidate {
|
||||||
|
panic("invalid op")
|
||||||
|
}
|
||||||
|
var o ui.InvalidateOp
|
||||||
|
if nanos := bo.Uint64(d[1:]); nanos > 0 {
|
||||||
|
o.At = time.Unix(0, int64(nanos))
|
||||||
|
}
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|||||||
@@ -37,27 +37,6 @@ func (i ImageOp) Add(o *ui.Ops) {
|
|||||||
o.Write(data, i.Src)
|
o.Write(data, i.Src)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *ImageOp) Decode(data []byte, refs []interface{}) {
|
|
||||||
bo := binary.LittleEndian
|
|
||||||
if opconst.OpType(data[0]) != opconst.TypeImage {
|
|
||||||
panic("invalid op")
|
|
||||||
}
|
|
||||||
sr := image.Rectangle{
|
|
||||||
Min: image.Point{
|
|
||||||
X: int(int32(bo.Uint32(data[1:]))),
|
|
||||||
Y: int(int32(bo.Uint32(data[5:]))),
|
|
||||||
},
|
|
||||||
Max: image.Point{
|
|
||||||
X: int(int32(bo.Uint32(data[9:]))),
|
|
||||||
Y: int(int32(bo.Uint32(data[13:]))),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
*i = ImageOp{
|
|
||||||
Src: refs[0].(image.Image),
|
|
||||||
Rect: sr,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c ColorOp) Add(o *ui.Ops) {
|
func (c ColorOp) Add(o *ui.Ops) {
|
||||||
data := make([]byte, opconst.TypeColorLen)
|
data := make([]byte, opconst.TypeColorLen)
|
||||||
data[0] = byte(opconst.TypeColor)
|
data[0] = byte(opconst.TypeColor)
|
||||||
@@ -68,20 +47,6 @@ func (c ColorOp) Add(o *ui.Ops) {
|
|||||||
o.Write(data)
|
o.Write(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ColorOp) Decode(data []byte, refs []interface{}) {
|
|
||||||
if opconst.OpType(data[0]) != opconst.TypeColor {
|
|
||||||
panic("invalid op")
|
|
||||||
}
|
|
||||||
*c = ColorOp{
|
|
||||||
Color: color.RGBA{
|
|
||||||
R: data[1],
|
|
||||||
G: data[2],
|
|
||||||
B: data[3],
|
|
||||||
A: data[4],
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d DrawOp) Add(o *ui.Ops) {
|
func (d DrawOp) Add(o *ui.Ops) {
|
||||||
data := make([]byte, opconst.TypeDrawLen)
|
data := make([]byte, opconst.TypeDrawLen)
|
||||||
data[0] = byte(opconst.TypeDraw)
|
data[0] = byte(opconst.TypeDraw)
|
||||||
@@ -93,26 +58,6 @@ func (d DrawOp) Add(o *ui.Ops) {
|
|||||||
o.Write(data)
|
o.Write(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DrawOp) Decode(data []byte, refs []interface{}) {
|
|
||||||
bo := binary.LittleEndian
|
|
||||||
if opconst.OpType(data[0]) != opconst.TypeDraw {
|
|
||||||
panic("invalid op")
|
|
||||||
}
|
|
||||||
r := f32.Rectangle{
|
|
||||||
Min: f32.Point{
|
|
||||||
X: math.Float32frombits(bo.Uint32(data[1:])),
|
|
||||||
Y: math.Float32frombits(bo.Uint32(data[5:])),
|
|
||||||
},
|
|
||||||
Max: f32.Point{
|
|
||||||
X: math.Float32frombits(bo.Uint32(data[9:])),
|
|
||||||
Y: math.Float32frombits(bo.Uint32(data[13:])),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
*d = DrawOp{
|
|
||||||
Rect: r,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// RectClip returns a ClipOp op corresponding to
|
// RectClip returns a ClipOp op corresponding to
|
||||||
// a pixel aligned rectangular area.
|
// a pixel aligned rectangular area.
|
||||||
func RectClip(r image.Rectangle) ClipOp {
|
func RectClip(r image.Rectangle) ClipOp {
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
// SPDX-License-Identifier: Unlicense OR MIT
|
||||||
|
|
||||||
|
package ops
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/binary"
|
||||||
|
"math"
|
||||||
|
|
||||||
|
"gioui.org/ui"
|
||||||
|
"gioui.org/ui/f32"
|
||||||
|
"gioui.org/ui/internal/opconst"
|
||||||
|
)
|
||||||
|
|
||||||
|
func DecodeTransformOp(d []byte) ui.TransformOp {
|
||||||
|
bo := binary.LittleEndian
|
||||||
|
if opconst.OpType(d[0]) != opconst.TypeTransform {
|
||||||
|
panic("invalid op")
|
||||||
|
}
|
||||||
|
return ui.TransformOp{}.Offset(f32.Point{
|
||||||
|
X: math.Float32frombits(bo.Uint32(d[1:])),
|
||||||
|
Y: math.Float32frombits(bo.Uint32(d[5:])),
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -64,16 +64,6 @@ func (h HandlerOp) Add(o *ui.Ops) {
|
|||||||
o.Write(data, h.Key)
|
o.Write(data, h.Key)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HandlerOp) Decode(d []byte, refs []interface{}) {
|
|
||||||
if opconst.OpType(d[0]) != opconst.TypeKeyHandler {
|
|
||||||
panic("invalid op")
|
|
||||||
}
|
|
||||||
*h = HandlerOp{
|
|
||||||
Focus: d[1] != 0,
|
|
||||||
Key: refs[0].(input.Key),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h HideInputOp) Add(o *ui.Ops) {
|
func (h HideInputOp) Add(o *ui.Ops) {
|
||||||
data := make([]byte, opconst.TypeHideInputLen)
|
data := make([]byte, opconst.TypeHideInputLen)
|
||||||
data[0] = byte(opconst.TypeHideInput)
|
data[0] = byte(opconst.TypeHideInput)
|
||||||
|
|||||||
@@ -115,16 +115,6 @@ func (h HandlerOp) Add(o *ui.Ops) {
|
|||||||
o.Write(data, h.Key)
|
o.Write(data, h.Key)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HandlerOp) Decode(d []byte, refs []interface{}) {
|
|
||||||
if opconst.OpType(d[0]) != opconst.TypePointerHandler {
|
|
||||||
panic("invalid op")
|
|
||||||
}
|
|
||||||
*h = HandlerOp{
|
|
||||||
Grab: d[1] != 0,
|
|
||||||
Key: refs[0].(input.Key),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (op PassOp) Add(o *ui.Ops) {
|
func (op PassOp) Add(o *ui.Ops) {
|
||||||
data := make([]byte, opconst.TypePassLen)
|
data := make([]byte, opconst.TypePassLen)
|
||||||
data[0] = byte(opconst.TypePass)
|
data[0] = byte(opconst.TypePass)
|
||||||
@@ -134,15 +124,6 @@ func (op PassOp) Add(o *ui.Ops) {
|
|||||||
o.Write(data)
|
o.Write(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (op *PassOp) Decode(d []byte) {
|
|
||||||
if opconst.OpType(d[0]) != opconst.TypePass {
|
|
||||||
panic("invalid op")
|
|
||||||
}
|
|
||||||
*op = PassOp{
|
|
||||||
Pass: d[1] != 0,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t Type) String() string {
|
func (t Type) String() string {
|
||||||
switch t {
|
switch t {
|
||||||
case Press:
|
case Press:
|
||||||
|
|||||||
@@ -29,13 +29,4 @@ func (p ProfileOp) Add(o *ui.Ops) {
|
|||||||
o.Write(data, p.Key)
|
o.Write(data, p.Key)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ProfileOp) Decode(d []byte, refs []interface{}) {
|
|
||||||
if opconst.OpType(d[0]) != opconst.TypeProfile {
|
|
||||||
panic("invalid op")
|
|
||||||
}
|
|
||||||
*p = ProfileOp{
|
|
||||||
Key: refs[0].(input.Key),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p ProfileEvent) ImplementsEvent() {}
|
func (p ProfileEvent) ImplementsEvent() {}
|
||||||
|
|||||||
@@ -46,16 +46,6 @@ func (r InvalidateOp) Add(o *Ops) {
|
|||||||
o.Write(data)
|
o.Write(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *InvalidateOp) Decode(d []byte) {
|
|
||||||
bo := binary.LittleEndian
|
|
||||||
if opconst.OpType(d[0]) != opconst.TypeInvalidate {
|
|
||||||
panic("invalid op")
|
|
||||||
}
|
|
||||||
if nanos := bo.Uint64(d[1:]); nanos > 0 {
|
|
||||||
r.At = time.Unix(0, int64(nanos))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Offset the transformation.
|
// Offset the transformation.
|
||||||
func (t TransformOp) Offset(o f32.Point) TransformOp {
|
func (t TransformOp) Offset(o f32.Point) TransformOp {
|
||||||
return t.Multiply(TransformOp{o})
|
return t.Multiply(TransformOp{o})
|
||||||
@@ -86,14 +76,3 @@ func (t TransformOp) Add(o *Ops) {
|
|||||||
bo.PutUint32(data[5:], math.Float32bits(t.offset.Y))
|
bo.PutUint32(data[5:], math.Float32bits(t.offset.Y))
|
||||||
o.Write(data)
|
o.Write(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TransformOp) Decode(d []byte) {
|
|
||||||
bo := binary.LittleEndian
|
|
||||||
if opconst.OpType(d[0]) != opconst.TypeTransform {
|
|
||||||
panic("invalid op")
|
|
||||||
}
|
|
||||||
*t = TransformOp{f32.Point{
|
|
||||||
X: math.Float32frombits(bo.Uint32(d[1:])),
|
|
||||||
Y: math.Float32frombits(bo.Uint32(d[5:])),
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user