forked from joejulian/gio
all: rename io/event.Key to Tag
Key had an unfortunate association with keyboard input.
This is an API change. The following rewrites were run to fixup
Gio code:
$ gofmt -r 'pointer.InputOp{Key:a} -> pointer.InputOp{Tag:a}' -w .
$ gofmt -r 'pointer.InputOp{Key:a, Grab:b} -> pointer.InputOp{Tag:a, Grab:b}' -w .
$ gofmt -r 'key.InputOp{Key:a} -> key.InputOp{Tag:a}' -w .
$ gofmt -r 'key.InputOp{Key:a, Focus:b} -> key.InputOp{Tag:a, Focus:b}' -w .
$ gofmt -r 'event.Key -> event.Tag' -w .
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+1
-1
@@ -390,7 +390,7 @@ func (w *Window) run(opts *window.Options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *queue) Events(k event.Key) []event.Event {
|
func (q *queue) Events(k event.Tag) []event.Event {
|
||||||
return q.q.Events(k)
|
return q.q.Events(k)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -112,7 +112,7 @@ var touchSlop = unit.Dp(3)
|
|||||||
|
|
||||||
// Add the handler to the operation list to receive click events.
|
// Add the handler to the operation list to receive click events.
|
||||||
func (c *Click) Add(ops *op.Ops) {
|
func (c *Click) Add(ops *op.Ops) {
|
||||||
op := pointer.InputOp{Key: c}
|
op := pointer.InputOp{Tag: c}
|
||||||
op.Add(ops)
|
op.Add(ops)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,7 +168,7 @@ func (c *Click) Events(q event.Queue) []ClickEvent {
|
|||||||
|
|
||||||
// Add the handler to the operation list to receive scroll events.
|
// Add the handler to the operation list to receive scroll events.
|
||||||
func (s *Scroll) Add(ops *op.Ops) {
|
func (s *Scroll) Add(ops *op.Ops) {
|
||||||
oph := pointer.InputOp{Key: s, Grab: s.grab}
|
oph := pointer.InputOp{Tag: s, Grab: s.grab}
|
||||||
oph.Add(ops)
|
oph.Add(ops)
|
||||||
if s.flinger.Active() {
|
if s.flinger.Active() {
|
||||||
op.InvalidateOp{}.Add(ops)
|
op.InvalidateOp{}.Add(ops)
|
||||||
|
|||||||
+7
-7
@@ -25,7 +25,7 @@ The following example declares a handler ready for key input:
|
|||||||
|
|
||||||
ops := new(op.Ops)
|
ops := new(op.Ops)
|
||||||
var h *Handler = ...
|
var h *Handler = ...
|
||||||
key.InputOp{Key: h}.Add(ops)
|
key.InputOp{Tag: h}.Add(ops)
|
||||||
|
|
||||||
*/
|
*/
|
||||||
package event
|
package event
|
||||||
@@ -33,14 +33,14 @@ package event
|
|||||||
// Queue maps an event handler key to the events
|
// Queue maps an event handler key to the events
|
||||||
// available to the handler.
|
// available to the handler.
|
||||||
type Queue interface {
|
type Queue interface {
|
||||||
// Events returns the available events for a
|
// Events returns the available events for an
|
||||||
// Key.
|
// event handler tag.
|
||||||
Events(k Key) []Event
|
Events(t Tag) []Event
|
||||||
}
|
}
|
||||||
|
|
||||||
// Key is the stable identifier for an event handler.
|
// Tag is the stable identifier for an event handler.
|
||||||
// For a handler h, the key is typically &h.
|
// For a handler h, the tag is typically &h.
|
||||||
type Key interface{}
|
type Tag interface{}
|
||||||
|
|
||||||
// Event is the marker interface for events.
|
// Event is the marker interface for events.
|
||||||
type Event interface {
|
type Event interface {
|
||||||
|
|||||||
+2
-2
@@ -22,7 +22,7 @@ import (
|
|||||||
// focused key handler. Set the Focus flag to request
|
// focused key handler. Set the Focus flag to request
|
||||||
// the focus.
|
// the focus.
|
||||||
type InputOp struct {
|
type InputOp struct {
|
||||||
Key event.Key
|
Tag event.Tag
|
||||||
Focus bool
|
Focus bool
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,7 +97,7 @@ func (m Modifiers) Contain(m2 Modifiers) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h InputOp) Add(o *op.Ops) {
|
func (h InputOp) Add(o *op.Ops) {
|
||||||
data := o.Write(opconst.TypeKeyInputLen, h.Key)
|
data := o.Write(opconst.TypeKeyInputLen, h.Tag)
|
||||||
data[0] = byte(opconst.TypeKeyInput)
|
data[0] = byte(opconst.TypeKeyInput)
|
||||||
if h.Focus {
|
if h.Focus {
|
||||||
data[1] = 1
|
data[1] = 1
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ type AreaOp struct {
|
|||||||
// InputOp declares an input handler ready for pointer
|
// InputOp declares an input handler ready for pointer
|
||||||
// events.
|
// events.
|
||||||
type InputOp struct {
|
type InputOp struct {
|
||||||
Key event.Key
|
Tag event.Tag
|
||||||
// Grab, if set, request that the handler get
|
// Grab, if set, request that the handler get
|
||||||
// Grabbed priority.
|
// Grabbed priority.
|
||||||
Grab bool
|
Grab bool
|
||||||
@@ -155,7 +155,7 @@ func (op AreaOp) Add(o *op.Ops) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h InputOp) Add(o *op.Ops) {
|
func (h InputOp) Add(o *op.Ops) {
|
||||||
data := o.Write(opconst.TypePointerInputLen, h.Key)
|
data := o.Write(opconst.TypePointerInputLen, h.Tag)
|
||||||
data[0] = byte(opconst.TypePointerInput)
|
data[0] = byte(opconst.TypePointerInput)
|
||||||
if h.Grab {
|
if h.Grab {
|
||||||
data[1] = 1
|
data[1] = 1
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
// Op registers a handler for receiving
|
// Op registers a handler for receiving
|
||||||
// Events.
|
// Events.
|
||||||
type Op struct {
|
type Op struct {
|
||||||
Key event.Key
|
Tag event.Tag
|
||||||
}
|
}
|
||||||
|
|
||||||
// Event contains profile data from a single
|
// Event contains profile data from a single
|
||||||
@@ -24,7 +24,7 @@ type Event struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p Op) Add(o *op.Ops) {
|
func (p Op) Add(o *op.Ops) {
|
||||||
data := o.Write(opconst.TypeProfileLen, p.Key)
|
data := o.Write(opconst.TypeProfileLen, p.Tag)
|
||||||
data[0] = byte(opconst.TypeProfile)
|
data[0] = byte(opconst.TypeProfile)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+11
-11
@@ -13,8 +13,8 @@ import (
|
|||||||
type TextInputState uint8
|
type TextInputState uint8
|
||||||
|
|
||||||
type keyQueue struct {
|
type keyQueue struct {
|
||||||
focus event.Key
|
focus event.Tag
|
||||||
handlers map[event.Key]*keyHandler
|
handlers map[event.Tag]*keyHandler
|
||||||
reader ops.Reader
|
reader ops.Reader
|
||||||
state TextInputState
|
state TextInputState
|
||||||
}
|
}
|
||||||
@@ -46,7 +46,7 @@ func (q *keyQueue) InputState() TextInputState {
|
|||||||
|
|
||||||
func (q *keyQueue) Frame(root *op.Ops, events *handlerEvents) {
|
func (q *keyQueue) Frame(root *op.Ops, events *handlerEvents) {
|
||||||
if q.handlers == nil {
|
if q.handlers == nil {
|
||||||
q.handlers = make(map[event.Key]*keyHandler)
|
q.handlers = make(map[event.Tag]*keyHandler)
|
||||||
}
|
}
|
||||||
for _, h := range q.handlers {
|
for _, h := range q.handlers {
|
||||||
h.active = false
|
h.active = false
|
||||||
@@ -89,8 +89,8 @@ func (q *keyQueue) Push(e event.Event, events *handlerEvents) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *keyQueue) resolveFocus(events *handlerEvents) (event.Key, listenerPriority, bool) {
|
func (q *keyQueue) resolveFocus(events *handlerEvents) (event.Tag, listenerPriority, bool) {
|
||||||
var k event.Key
|
var k event.Tag
|
||||||
var pri listenerPriority
|
var pri listenerPriority
|
||||||
var hide bool
|
var hide bool
|
||||||
loop:
|
loop:
|
||||||
@@ -102,21 +102,21 @@ loop:
|
|||||||
switch {
|
switch {
|
||||||
case op.Focus:
|
case op.Focus:
|
||||||
newPri = priNewFocus
|
newPri = priNewFocus
|
||||||
case op.Key == q.focus:
|
case op.Tag == q.focus:
|
||||||
newPri = priCurrentFocus
|
newPri = priCurrentFocus
|
||||||
default:
|
default:
|
||||||
newPri = priDefault
|
newPri = priDefault
|
||||||
}
|
}
|
||||||
// Switch focus if higher priority or if focus requested.
|
// Switch focus if higher priority or if focus requested.
|
||||||
if newPri.replaces(pri) {
|
if newPri.replaces(pri) {
|
||||||
k, pri = op.Key, newPri
|
k, pri = op.Tag, newPri
|
||||||
}
|
}
|
||||||
h, ok := q.handlers[op.Key]
|
h, ok := q.handlers[op.Tag]
|
||||||
if !ok {
|
if !ok {
|
||||||
h = new(keyHandler)
|
h = new(keyHandler)
|
||||||
q.handlers[op.Key] = h
|
q.handlers[op.Tag] = h
|
||||||
// Reset the handler on (each) first appearance.
|
// Reset the handler on (each) first appearance.
|
||||||
events.Set(op.Key, []event.Event{key.FocusEvent{Focus: false}})
|
events.Set(op.Tag, []event.Event{key.FocusEvent{Focus: false}})
|
||||||
}
|
}
|
||||||
h.active = true
|
h.active = true
|
||||||
case opconst.TypeHideInput:
|
case opconst.TypeHideInput:
|
||||||
@@ -144,7 +144,7 @@ func decodeKeyInputOp(d []byte, refs []interface{}) key.InputOp {
|
|||||||
panic("invalid op")
|
panic("invalid op")
|
||||||
}
|
}
|
||||||
return key.InputOp{
|
return key.InputOp{
|
||||||
|
Tag: refs[0].(event.Tag),
|
||||||
Focus: d[1] != 0,
|
Focus: d[1] != 0,
|
||||||
Key: refs[0].(event.Key),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-14
@@ -17,14 +17,14 @@ import (
|
|||||||
type pointerQueue struct {
|
type pointerQueue struct {
|
||||||
hitTree []hitNode
|
hitTree []hitNode
|
||||||
areas []areaNode
|
areas []areaNode
|
||||||
handlers map[event.Key]*pointerHandler
|
handlers map[event.Tag]*pointerHandler
|
||||||
pointers []pointerInfo
|
pointers []pointerInfo
|
||||||
reader ops.Reader
|
reader ops.Reader
|
||||||
scratch []event.Key
|
scratch []event.Tag
|
||||||
|
|
||||||
// prev and curr are two additional scratch slices that track active
|
// prev and curr are two additional scratch slices that track active
|
||||||
// pointer event handlers from the previous and current frame
|
// pointer event handlers from the previous and current frame
|
||||||
prev, curr []event.Key
|
prev, curr []event.Tag
|
||||||
}
|
}
|
||||||
|
|
||||||
type hitNode struct {
|
type hitNode struct {
|
||||||
@@ -34,13 +34,13 @@ type hitNode struct {
|
|||||||
pass bool
|
pass bool
|
||||||
|
|
||||||
// For handler nodes.
|
// For handler nodes.
|
||||||
key event.Key
|
key event.Tag
|
||||||
}
|
}
|
||||||
|
|
||||||
type pointerInfo struct {
|
type pointerInfo struct {
|
||||||
id pointer.ID
|
id pointer.ID
|
||||||
pressed bool
|
pressed bool
|
||||||
handlers []event.Key
|
handlers []event.Tag
|
||||||
}
|
}
|
||||||
|
|
||||||
type pointerHandler struct {
|
type pointerHandler struct {
|
||||||
@@ -98,14 +98,14 @@ func (q *pointerQueue) collectHandlers(r *ops.Reader, events *handlerEvents, t o
|
|||||||
next: node,
|
next: node,
|
||||||
area: area,
|
area: area,
|
||||||
pass: pass,
|
pass: pass,
|
||||||
key: op.Key,
|
key: op.Tag,
|
||||||
})
|
})
|
||||||
node = len(q.hitTree) - 1
|
node = len(q.hitTree) - 1
|
||||||
h, ok := q.handlers[op.Key]
|
h, ok := q.handlers[op.Tag]
|
||||||
if !ok {
|
if !ok {
|
||||||
h = new(pointerHandler)
|
h = new(pointerHandler)
|
||||||
q.handlers[op.Key] = h
|
q.handlers[op.Tag] = h
|
||||||
events.Set(op.Key, []event.Event{pointer.Event{Type: pointer.Cancel}})
|
events.Set(op.Tag, []event.Event{pointer.Event{Type: pointer.Cancel}})
|
||||||
}
|
}
|
||||||
h.active = true
|
h.active = true
|
||||||
h.area = area
|
h.area = area
|
||||||
@@ -115,7 +115,7 @@ func (q *pointerQueue) collectHandlers(r *ops.Reader, events *handlerEvents, t o
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *pointerQueue) opHit(handlers *[]event.Key, pos f32.Point) {
|
func (q *pointerQueue) opHit(handlers *[]event.Tag, pos f32.Point) {
|
||||||
// Track whether we're passing through hits.
|
// Track whether we're passing through hits.
|
||||||
pass := true
|
pass := true
|
||||||
idx := len(q.hitTree) - 1
|
idx := len(q.hitTree) - 1
|
||||||
@@ -160,7 +160,7 @@ func (a *areaNode) hit(p f32.Point) bool {
|
|||||||
|
|
||||||
func (q *pointerQueue) init() {
|
func (q *pointerQueue) init() {
|
||||||
if q.handlers == nil {
|
if q.handlers == nil {
|
||||||
q.handlers = make(map[event.Key]*pointerHandler)
|
q.handlers = make(map[event.Tag]*pointerHandler)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,7 +182,7 @@ func (q *pointerQueue) Frame(root *op.Ops, events *handlerEvents) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *pointerQueue) dropHandler(k event.Key, events *handlerEvents) {
|
func (q *pointerQueue) dropHandler(k event.Tag, events *handlerEvents) {
|
||||||
events.Add(k, pointer.Event{Type: pointer.Cancel})
|
events.Add(k, pointer.Event{Type: pointer.Cancel})
|
||||||
q.handlers[k].wantsGrab = false
|
q.handlers[k].wantsGrab = false
|
||||||
for i := range q.pointers {
|
for i := range q.pointers {
|
||||||
@@ -278,7 +278,7 @@ func (q *pointerQueue) Push(e pointer.Event, events *handlerEvents) {
|
|||||||
// evTemplate but with the type specified by evType.
|
// evTemplate but with the type specified by evType.
|
||||||
//
|
//
|
||||||
// This is useful for delivering pointer.Enter and pointer.Leave events.
|
// This is useful for delivering pointer.Enter and pointer.Leave events.
|
||||||
func (q *pointerQueue) deliverEventsToMissingHandlers(a, b []event.Key, evType pointer.Type, evTemplate pointer.Event, events *handlerEvents) {
|
func (q *pointerQueue) deliverEventsToMissingHandlers(a, b []event.Tag, evType pointer.Type, evTemplate pointer.Event, events *handlerEvents) {
|
||||||
for _, newH := range b {
|
for _, newH := range b {
|
||||||
found := false
|
found := false
|
||||||
for _, oldH := range a {
|
for _, oldH := range a {
|
||||||
@@ -350,8 +350,8 @@ func decodePointerInputOp(d []byte, refs []interface{}) pointer.InputOp {
|
|||||||
panic("invalid op")
|
panic("invalid op")
|
||||||
}
|
}
|
||||||
return pointer.InputOp{
|
return pointer.InputOp{
|
||||||
|
Tag: refs[0].(event.Tag),
|
||||||
Grab: d[1] != 0,
|
Grab: d[1] != 0,
|
||||||
Key: refs[0].(event.Key),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+10
-10
@@ -22,7 +22,7 @@ func TestPointerDrag(t *testing.T) {
|
|||||||
Y: 100,
|
Y: 100,
|
||||||
},
|
},
|
||||||
}).Add(&ops)
|
}).Add(&ops)
|
||||||
pointer.InputOp{Key: handler}.Add(&ops)
|
pointer.InputOp{Tag: handler}.Add(&ops)
|
||||||
|
|
||||||
var r Router
|
var r Router
|
||||||
r.Frame(&ops)
|
r.Frame(&ops)
|
||||||
@@ -62,7 +62,7 @@ func TestPointerMove(t *testing.T) {
|
|||||||
Y: 100,
|
Y: 100,
|
||||||
},
|
},
|
||||||
}).Add(&ops)
|
}).Add(&ops)
|
||||||
pointer.InputOp{Key: handler1}.Add(&ops)
|
pointer.InputOp{Tag: handler1}.Add(&ops)
|
||||||
// Handler 2 area: (50, 50) - (100, 100) (areas intersect).
|
// Handler 2 area: (50, 50) - (100, 100) (areas intersect).
|
||||||
pointer.Rect(image.Rectangle{
|
pointer.Rect(image.Rectangle{
|
||||||
Min: image.Point{
|
Min: image.Point{
|
||||||
@@ -74,7 +74,7 @@ func TestPointerMove(t *testing.T) {
|
|||||||
Y: 200,
|
Y: 200,
|
||||||
},
|
},
|
||||||
}).Add(&ops)
|
}).Add(&ops)
|
||||||
pointer.InputOp{Key: handler2}.Add(&ops)
|
pointer.InputOp{Tag: handler2}.Add(&ops)
|
||||||
|
|
||||||
var r Router
|
var r Router
|
||||||
r.Frame(&ops)
|
r.Frame(&ops)
|
||||||
@@ -146,7 +146,7 @@ func TestPointerEnterLeave(t *testing.T) {
|
|||||||
Y: 100,
|
Y: 100,
|
||||||
},
|
},
|
||||||
}).Add(&ops)
|
}).Add(&ops)
|
||||||
pointer.InputOp{Key: handler1}.Add(&ops)
|
pointer.InputOp{Tag: handler1}.Add(&ops)
|
||||||
stack.Pop()
|
stack.Pop()
|
||||||
|
|
||||||
// Handler 2 area: (50, 50) - (100, 100) (areas intersect).
|
// Handler 2 area: (50, 50) - (100, 100) (areas intersect).
|
||||||
@@ -161,7 +161,7 @@ func TestPointerEnterLeave(t *testing.T) {
|
|||||||
Y: 200,
|
Y: 200,
|
||||||
},
|
},
|
||||||
}).Add(&ops)
|
}).Add(&ops)
|
||||||
pointer.InputOp{Key: handler2}.Add(&ops)
|
pointer.InputOp{Tag: handler2}.Add(&ops)
|
||||||
stack.Pop()
|
stack.Pop()
|
||||||
|
|
||||||
var r Router
|
var r Router
|
||||||
@@ -264,7 +264,7 @@ func TestPointerEnterLeaveNested(t *testing.T) {
|
|||||||
Y: 100,
|
Y: 100,
|
||||||
},
|
},
|
||||||
}).Add(&ops)
|
}).Add(&ops)
|
||||||
pointer.InputOp{Key: handler1}.Add(&ops)
|
pointer.InputOp{Tag: handler1}.Add(&ops)
|
||||||
|
|
||||||
// Handler 2 area: (25, 25) - (75, 75) (nested within first).
|
// Handler 2 area: (25, 25) - (75, 75) (nested within first).
|
||||||
pointer.Rect(image.Rectangle{
|
pointer.Rect(image.Rectangle{
|
||||||
@@ -277,7 +277,7 @@ func TestPointerEnterLeaveNested(t *testing.T) {
|
|||||||
Y: 75,
|
Y: 75,
|
||||||
},
|
},
|
||||||
}).Add(&ops)
|
}).Add(&ops)
|
||||||
pointer.InputOp{Key: handler2}.Add(&ops)
|
pointer.InputOp{Tag: handler2}.Add(&ops)
|
||||||
|
|
||||||
var r Router
|
var r Router
|
||||||
r.Frame(&ops)
|
r.Frame(&ops)
|
||||||
@@ -376,7 +376,7 @@ func TestPointerActiveInputDisappears(t *testing.T) {
|
|||||||
Y: 100,
|
Y: 100,
|
||||||
},
|
},
|
||||||
}).Add(ops)
|
}).Add(ops)
|
||||||
pointer.InputOp{Key: handler1}.Add(ops)
|
pointer.InputOp{Tag: handler1}.Add(ops)
|
||||||
stack.Pop()
|
stack.Pop()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -458,7 +458,7 @@ func BenchmarkRouterAdd(b *testing.B) {
|
|||||||
for i := startingHandlerCount; i < maxHandlerCount; i *= 3 {
|
for i := startingHandlerCount; i < maxHandlerCount; i *= 3 {
|
||||||
handlerCount := i
|
handlerCount := i
|
||||||
b.Run(fmt.Sprintf("%d-handlers", i), func(b *testing.B) {
|
b.Run(fmt.Sprintf("%d-handlers", i), func(b *testing.B) {
|
||||||
handlers := make([]event.Key, handlerCount)
|
handlers := make([]event.Tag, handlerCount)
|
||||||
for i := 0; i < handlerCount; i++ {
|
for i := 0; i < handlerCount; i++ {
|
||||||
h := new(int)
|
h := new(int)
|
||||||
*h = i
|
*h = i
|
||||||
@@ -473,7 +473,7 @@ func BenchmarkRouterAdd(b *testing.B) {
|
|||||||
Y: 100,
|
Y: 100,
|
||||||
},
|
},
|
||||||
}).Add(&ops)
|
}).Add(&ops)
|
||||||
pointer.InputOp{Key: handlers[i]}.Add(&ops)
|
pointer.InputOp{Tag: handlers[i]}.Add(&ops)
|
||||||
}
|
}
|
||||||
var r Router
|
var r Router
|
||||||
r.Frame(&ops)
|
r.Frame(&ops)
|
||||||
|
|||||||
+10
-10
@@ -39,17 +39,17 @@ type Router struct {
|
|||||||
|
|
||||||
// ProfileOp summary.
|
// ProfileOp summary.
|
||||||
profiling bool
|
profiling bool
|
||||||
profHandlers map[event.Key]struct{}
|
profHandlers map[event.Tag]struct{}
|
||||||
profile profile.Event
|
profile profile.Event
|
||||||
}
|
}
|
||||||
|
|
||||||
type handlerEvents struct {
|
type handlerEvents struct {
|
||||||
handlers map[event.Key][]event.Event
|
handlers map[event.Tag][]event.Event
|
||||||
hadEvents bool
|
hadEvents bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Events returns the available events for the handler key.
|
// Events returns the available events for the handler key.
|
||||||
func (q *Router) Events(k event.Key) []event.Event {
|
func (q *Router) Events(k event.Tag) []event.Event {
|
||||||
events := q.handlers.Events(k)
|
events := q.handlers.Events(k)
|
||||||
if _, isprof := q.profHandlers[k]; isprof {
|
if _, isprof := q.profHandlers[k]; isprof {
|
||||||
delete(q.profHandlers, k)
|
delete(q.profHandlers, k)
|
||||||
@@ -111,10 +111,10 @@ func (q *Router) collect() {
|
|||||||
case opconst.TypeProfile:
|
case opconst.TypeProfile:
|
||||||
op := decodeProfileOp(encOp.Data, encOp.Refs)
|
op := decodeProfileOp(encOp.Data, encOp.Refs)
|
||||||
if q.profHandlers == nil {
|
if q.profHandlers == nil {
|
||||||
q.profHandlers = make(map[event.Key]struct{})
|
q.profHandlers = make(map[event.Tag]struct{})
|
||||||
}
|
}
|
||||||
q.profiling = true
|
q.profiling = true
|
||||||
q.profHandlers[op.Key] = struct{}{}
|
q.profHandlers[op.Tag] = struct{}{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -133,17 +133,17 @@ func (q *Router) WakeupTime() (time.Time, bool) {
|
|||||||
|
|
||||||
func (h *handlerEvents) init() {
|
func (h *handlerEvents) init() {
|
||||||
if h.handlers == nil {
|
if h.handlers == nil {
|
||||||
h.handlers = make(map[event.Key][]event.Event)
|
h.handlers = make(map[event.Tag][]event.Event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *handlerEvents) Set(k event.Key, evts []event.Event) {
|
func (h *handlerEvents) Set(k event.Tag, evts []event.Event) {
|
||||||
h.init()
|
h.init()
|
||||||
h.handlers[k] = evts
|
h.handlers[k] = evts
|
||||||
h.hadEvents = true
|
h.hadEvents = true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *handlerEvents) Add(k event.Key, e event.Event) {
|
func (h *handlerEvents) Add(k event.Tag, e event.Event) {
|
||||||
h.init()
|
h.init()
|
||||||
h.handlers[k] = append(h.handlers[k], e)
|
h.handlers[k] = append(h.handlers[k], e)
|
||||||
h.hadEvents = true
|
h.hadEvents = true
|
||||||
@@ -155,7 +155,7 @@ func (h *handlerEvents) HadEvents() bool {
|
|||||||
return u
|
return u
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *handlerEvents) Events(k event.Key) []event.Event {
|
func (h *handlerEvents) Events(k event.Tag) []event.Event {
|
||||||
if events, ok := h.handlers[k]; ok {
|
if events, ok := h.handlers[k]; ok {
|
||||||
h.handlers[k] = h.handlers[k][:0]
|
h.handlers[k] = h.handlers[k][:0]
|
||||||
// Schedule another frame if we delivered events to the user
|
// Schedule another frame if we delivered events to the user
|
||||||
@@ -184,7 +184,7 @@ func decodeProfileOp(d []byte, refs []interface{}) profile.Op {
|
|||||||
panic("invalid op")
|
panic("invalid op")
|
||||||
}
|
}
|
||||||
return profile.Op{
|
return profile.Op{
|
||||||
Key: refs[0].(event.Key),
|
Tag: refs[0].(event.Tag),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -74,7 +74,7 @@ func (c *Context) Px(v unit.Value) int {
|
|||||||
|
|
||||||
// Events returns the events available for the key. If no
|
// Events returns the events available for the key. If no
|
||||||
// queue is configured, Events returns nil.
|
// queue is configured, Events returns nil.
|
||||||
func (c *Context) Events(k event.Key) []event.Event {
|
func (c *Context) Events(k event.Tag) []event.Event {
|
||||||
if c.queue == nil {
|
if c.queue == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -296,7 +296,7 @@ func (e *Editor) layout(gtx *layout.Context) {
|
|||||||
e.shapes = append(e.shapes, line{off, path})
|
e.shapes = append(e.shapes, line{off, path})
|
||||||
}
|
}
|
||||||
|
|
||||||
key.InputOp{Key: &e.eventKey, Focus: e.requestFocus}.Add(gtx.Ops)
|
key.InputOp{Tag: &e.eventKey, Focus: e.requestFocus}.Add(gtx.Ops)
|
||||||
e.requestFocus = false
|
e.requestFocus = false
|
||||||
pointerPadding := gtx.Px(unit.Dp(4))
|
pointerPadding := gtx.Px(unit.Dp(4))
|
||||||
r := image.Rectangle{Max: e.viewSize}
|
r := image.Rectangle{Max: e.viewSize}
|
||||||
|
|||||||
Reference in New Issue
Block a user