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:
@@ -3,6 +3,7 @@
|
||||
package input
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"time"
|
||||
|
||||
"gioui.org/ui"
|
||||
@@ -74,15 +75,13 @@ 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:
|
||||
var op ui.InvalidateOp
|
||||
op.Decode(encOp.Data)
|
||||
op := decodeInvalidateOp(encOp.Data)
|
||||
if !q.wakeup || op.At.Before(q.wakeupTime) {
|
||||
q.wakeup = true
|
||||
q.wakeupTime = op.At
|
||||
}
|
||||
case opconst.TypeProfile:
|
||||
var op system.ProfileOp
|
||||
op.Decode(encOp.Data, encOp.Refs)
|
||||
op := decodeProfileOp(encOp.Data, encOp.Refs)
|
||||
q.profHandlers = append(q.profHandlers, op.Key)
|
||||
}
|
||||
}
|
||||
@@ -141,3 +140,24 @@ func (h *handlerEvents) Clear() {
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user