mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 01:45:36 +00:00
op: add package op for operations
Extract operation types from package ui into package op. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -12,11 +12,11 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"gioui.org/ui"
|
||||
"gioui.org/app/internal/gl"
|
||||
"gioui.org/f32"
|
||||
"gioui.org/internal/opconst"
|
||||
"gioui.org/internal/ops"
|
||||
"gioui.org/op"
|
||||
"gioui.org/paint"
|
||||
"golang.org/x/image/draw"
|
||||
)
|
||||
@@ -74,7 +74,7 @@ type drawOps struct {
|
||||
|
||||
type drawState struct {
|
||||
clip f32.Rectangle
|
||||
t ui.TransformOp
|
||||
t op.TransformOp
|
||||
cpath *pathOp
|
||||
rect bool
|
||||
z int
|
||||
@@ -398,7 +398,7 @@ func (g *GPU) Refresh() {
|
||||
g.setErr(<-g.refreshErr)
|
||||
}
|
||||
|
||||
func (g *GPU) Draw(profile bool, viewport image.Point, root *ui.Ops) {
|
||||
func (g *GPU) Draw(profile bool, viewport image.Point, root *op.Ops) {
|
||||
if g.err != nil {
|
||||
return
|
||||
}
|
||||
@@ -678,7 +678,7 @@ func (d *drawOps) reset(cache *resourceCache, viewport image.Point) {
|
||||
d.pathOpCache = d.pathOpCache[:0]
|
||||
}
|
||||
|
||||
func (d *drawOps) collect(cache *resourceCache, root *ui.Ops, viewport image.Point) {
|
||||
func (d *drawOps) collect(cache *resourceCache, root *op.Ops, viewport image.Point) {
|
||||
d.reset(cache, viewport)
|
||||
clip := f32.Rectangle{
|
||||
Max: f32.Point{X: float32(viewport.X), Y: float32(viewport.Y)},
|
||||
@@ -704,8 +704,8 @@ loop:
|
||||
for encOp, ok := r.Decode(); ok; encOp, ok = r.Decode() {
|
||||
switch opconst.OpType(encOp.Data[0]) {
|
||||
case opconst.TypeTransform:
|
||||
op := ops.DecodeTransformOp(encOp.Data)
|
||||
state.t = state.t.Multiply(ui.TransformOp(op))
|
||||
dop := ops.DecodeTransformOp(encOp.Data)
|
||||
state.t = state.t.Multiply(op.TransformOp(dop))
|
||||
case opconst.TypeAux:
|
||||
aux = encOp.Data[opconst.TypeAuxLen:]
|
||||
auxKey = encOp.Key
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"gioui.org/internal/ops"
|
||||
"gioui.org/io/event"
|
||||
"gioui.org/io/key"
|
||||
"gioui.org/ui"
|
||||
"gioui.org/op"
|
||||
)
|
||||
|
||||
type TextInputState uint8
|
||||
@@ -44,7 +44,7 @@ func (q *keyQueue) InputState() TextInputState {
|
||||
return q.state
|
||||
}
|
||||
|
||||
func (q *keyQueue) Frame(root *ui.Ops, events *handlerEvents) {
|
||||
func (q *keyQueue) Frame(root *op.Ops, events *handlerEvents) {
|
||||
if q.handlers == nil {
|
||||
q.handlers = make(map[event.Key]*keyHandler)
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"gioui.org/internal/ops"
|
||||
"gioui.org/io/event"
|
||||
"gioui.org/io/pointer"
|
||||
"gioui.org/ui"
|
||||
"gioui.org/op"
|
||||
)
|
||||
|
||||
type pointerQueue struct {
|
||||
@@ -42,7 +42,7 @@ type pointerInfo struct {
|
||||
type pointerHandler struct {
|
||||
area int
|
||||
active bool
|
||||
transform ui.TransformOp
|
||||
transform op.TransformOp
|
||||
wantsGrab bool
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ type areaOp struct {
|
||||
}
|
||||
|
||||
type areaNode struct {
|
||||
trans ui.TransformOp
|
||||
trans op.TransformOp
|
||||
next int
|
||||
area areaOp
|
||||
}
|
||||
@@ -64,7 +64,7 @@ const (
|
||||
areaEllipse
|
||||
)
|
||||
|
||||
func (q *pointerQueue) collectHandlers(r *ops.Reader, events *handlerEvents, t ui.TransformOp, area, node int, pass bool) {
|
||||
func (q *pointerQueue) collectHandlers(r *ops.Reader, events *handlerEvents, t op.TransformOp, area, node int, pass bool) {
|
||||
for encOp, ok := r.Decode(); ok; encOp, ok = r.Decode() {
|
||||
switch opconst.OpType(encOp.Data[0]) {
|
||||
case opconst.TypePush:
|
||||
@@ -86,8 +86,8 @@ func (q *pointerQueue) collectHandlers(r *ops.Reader, events *handlerEvents, t u
|
||||
})
|
||||
node = len(q.hitTree) - 1
|
||||
case opconst.TypeTransform:
|
||||
op := ops.DecodeTransformOp(encOp.Data)
|
||||
t = t.Multiply(ui.TransformOp(op))
|
||||
dop := ops.DecodeTransformOp(encOp.Data)
|
||||
t = t.Multiply(op.TransformOp(dop))
|
||||
case opconst.TypePointerInput:
|
||||
op := decodePointerInputOp(encOp.Data, encOp.Refs)
|
||||
q.hitTree = append(q.hitTree, hitNode{
|
||||
@@ -158,7 +158,7 @@ func (q *pointerQueue) init() {
|
||||
}
|
||||
}
|
||||
|
||||
func (q *pointerQueue) Frame(root *ui.Ops, events *handlerEvents) {
|
||||
func (q *pointerQueue) Frame(root *op.Ops, events *handlerEvents) {
|
||||
q.init()
|
||||
for _, h := range q.handlers {
|
||||
// Reset handler.
|
||||
@@ -167,7 +167,7 @@ func (q *pointerQueue) Frame(root *ui.Ops, events *handlerEvents) {
|
||||
q.hitTree = q.hitTree[:0]
|
||||
q.areas = q.areas[:0]
|
||||
q.reader.Reset(root)
|
||||
q.collectHandlers(&q.reader, events, ui.TransformOp{}, -1, -1, false)
|
||||
q.collectHandlers(&q.reader, events, op.TransformOp{}, -1, -1, false)
|
||||
for k, h := range q.handlers {
|
||||
if !h.active {
|
||||
q.dropHandler(k)
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
"gioui.org/io/key"
|
||||
"gioui.org/io/pointer"
|
||||
"gioui.org/io/profile"
|
||||
"gioui.org/ui"
|
||||
"gioui.org/op"
|
||||
)
|
||||
|
||||
// Router is a Queue implementation that routes events from
|
||||
@@ -53,7 +53,7 @@ func (q *Router) Events(k event.Key) []event.Event {
|
||||
return events
|
||||
}
|
||||
|
||||
func (q *Router) Frame(ops *ui.Ops) {
|
||||
func (q *Router) Frame(ops *op.Ops) {
|
||||
q.handlers.Clear()
|
||||
q.wakeup = false
|
||||
q.profHandlers = q.profHandlers[:0]
|
||||
@@ -160,12 +160,12 @@ func decodeProfileOp(d []byte, refs []interface{}) profile.Op {
|
||||
}
|
||||
}
|
||||
|
||||
func decodeInvalidateOp(d []byte) ui.InvalidateOp {
|
||||
func decodeInvalidateOp(d []byte) op.InvalidateOp {
|
||||
bo := binary.LittleEndian
|
||||
if opconst.OpType(d[0]) != opconst.TypeInvalidate {
|
||||
panic("invalid op")
|
||||
}
|
||||
var o ui.InvalidateOp
|
||||
var o op.InvalidateOp
|
||||
if nanos := bo.Uint64(d[1:]); nanos > 0 {
|
||||
o.At = time.Unix(0, int64(nanos))
|
||||
}
|
||||
|
||||
+6
-5
@@ -12,6 +12,7 @@ import (
|
||||
"gioui.org/app/internal/input"
|
||||
"gioui.org/io/event"
|
||||
"gioui.org/io/profile"
|
||||
"gioui.org/op"
|
||||
"gioui.org/ui"
|
||||
)
|
||||
|
||||
@@ -36,7 +37,7 @@ type Window struct {
|
||||
in chan event.Event
|
||||
ack chan struct{}
|
||||
invalidates chan struct{}
|
||||
frames chan *ui.Ops
|
||||
frames chan *op.Ops
|
||||
|
||||
stage Stage
|
||||
animating bool
|
||||
@@ -99,7 +100,7 @@ func NewWindow(options ...WindowOption) *Window {
|
||||
out: make(chan event.Event),
|
||||
ack: make(chan struct{}),
|
||||
invalidates: make(chan struct{}, 1),
|
||||
frames: make(chan *ui.Ops),
|
||||
frames: make(chan *op.Ops),
|
||||
}
|
||||
go w.run(opts)
|
||||
return w
|
||||
@@ -120,11 +121,11 @@ func (w *Window) Queue() *Queue {
|
||||
// window contents, input operations declare input handlers,
|
||||
// and so on. The supplied operations list completely replaces
|
||||
// the window state from previous calls.
|
||||
func (w *Window) Update(frame *ui.Ops) {
|
||||
func (w *Window) Update(frame *op.Ops) {
|
||||
w.frames <- frame
|
||||
}
|
||||
|
||||
func (w *Window) draw(size image.Point, frame *ui.Ops) {
|
||||
func (w *Window) draw(size image.Point, frame *op.Ops) {
|
||||
var drawDur time.Duration
|
||||
if !w.drawStart.IsZero() {
|
||||
drawDur = time.Since(w.drawStart)
|
||||
@@ -265,7 +266,7 @@ func (w *Window) run(opts *windowOptions) {
|
||||
w.drawStart = time.Now()
|
||||
w.hasNextFrame = false
|
||||
w.out <- e
|
||||
var frame *ui.Ops
|
||||
var frame *op.Ops
|
||||
// Wait for either a frame or the ack event,
|
||||
// which meant that the client didn't draw.
|
||||
select {
|
||||
|
||||
Reference in New Issue
Block a user