mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-03 08:25:34 +00:00
ui/key,ui/pointer: rename HandlerOp to InputOp
"Input" is more specific and reads better than "handler". Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -96,8 +96,8 @@ func (q *keyQueue) resolveFocus(events *handlerEvents) (input.Key, listenerPrior
|
|||||||
loop:
|
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.TypeKeyInput:
|
||||||
op := decodeKeyHandlerOp(encOp.Data, encOp.Refs)
|
op := decodeKeyInputOp(encOp.Data, encOp.Refs)
|
||||||
var newPri listenerPriority
|
var newPri listenerPriority
|
||||||
switch {
|
switch {
|
||||||
case op.Focus:
|
case op.Focus:
|
||||||
@@ -139,11 +139,11 @@ func (p listenerPriority) replaces(p2 listenerPriority) bool {
|
|||||||
return p > p2 || p == p2 && p == priNewFocus
|
return p > p2 || p == p2 && p == priNewFocus
|
||||||
}
|
}
|
||||||
|
|
||||||
func decodeKeyHandlerOp(d []byte, refs []interface{}) key.HandlerOp {
|
func decodeKeyInputOp(d []byte, refs []interface{}) key.InputOp {
|
||||||
if opconst.OpType(d[0]) != opconst.TypeKeyHandler {
|
if opconst.OpType(d[0]) != opconst.TypeKeyInput {
|
||||||
panic("invalid op")
|
panic("invalid op")
|
||||||
}
|
}
|
||||||
return key.HandlerOp{
|
return key.InputOp{
|
||||||
Focus: d[1] != 0,
|
Focus: d[1] != 0,
|
||||||
Key: refs[0].(input.Key),
|
Key: refs[0].(input.Key),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,8 +88,8 @@ func (q *pointerQueue) collectHandlers(r *ops.Reader, events *handlerEvents, t u
|
|||||||
case opconst.TypeTransform:
|
case opconst.TypeTransform:
|
||||||
op := ops.DecodeTransformOp(encOp.Data)
|
op := ops.DecodeTransformOp(encOp.Data)
|
||||||
t = t.Multiply(ui.TransformOp(op))
|
t = t.Multiply(ui.TransformOp(op))
|
||||||
case opconst.TypePointerHandler:
|
case opconst.TypePointerInput:
|
||||||
op := decodePointerHandlerOp(encOp.Data, encOp.Refs)
|
op := decodePointerInputOp(encOp.Data, encOp.Refs)
|
||||||
q.hitTree = append(q.hitTree, hitNode{
|
q.hitTree = append(q.hitTree, hitNode{
|
||||||
next: node,
|
next: node,
|
||||||
area: area,
|
area: area,
|
||||||
@@ -314,11 +314,11 @@ func (op *areaOp) Hit(pos f32.Point) bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func decodePointerHandlerOp(d []byte, refs []interface{}) pointer.HandlerOp {
|
func decodePointerInputOp(d []byte, refs []interface{}) pointer.InputOp {
|
||||||
if opconst.OpType(d[0]) != opconst.TypePointerHandler {
|
if opconst.OpType(d[0]) != opconst.TypePointerInput {
|
||||||
panic("invalid op")
|
panic("invalid op")
|
||||||
}
|
}
|
||||||
return pointer.HandlerOp{
|
return pointer.InputOp{
|
||||||
Grab: d[1] != 0,
|
Grab: d[1] != 0,
|
||||||
Key: refs[0].(input.Key),
|
Key: refs[0].(input.Key),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ const (
|
|||||||
|
|
||||||
// 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 *ui.Ops) {
|
func (c *Click) Add(ops *ui.Ops) {
|
||||||
op := pointer.HandlerOp{Key: c}
|
op := pointer.InputOp{Key: c}
|
||||||
op.Add(ops)
|
op.Add(ops)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -159,7 +159,7 @@ func (c *Click) Next(q input.Queue) (ClickEvent, bool) {
|
|||||||
|
|
||||||
// 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 *ui.Ops) {
|
func (s *Scroll) Add(ops *ui.Ops) {
|
||||||
oph := pointer.HandlerOp{Key: s, Grab: s.grab}
|
oph := pointer.InputOp{Key: s, Grab: s.grab}
|
||||||
oph.Add(ops)
|
oph.Add(ops)
|
||||||
if s.flinger.Active() {
|
if s.flinger.Active() {
|
||||||
ui.InvalidateOp{}.Add(ops)
|
ui.InvalidateOp{}.Add(ops)
|
||||||
|
|||||||
+1
-1
@@ -25,7 +25,7 @@ The following example marks a handler ready for key input:
|
|||||||
|
|
||||||
ops := new(ui.Ops)
|
ops := new(ui.Ops)
|
||||||
var h *Handler = ...
|
var h *Handler = ...
|
||||||
key.HandlerOp{Key: h}.Add(ops)
|
key.InputOp{Key: h}.Add(ops)
|
||||||
|
|
||||||
*/
|
*/
|
||||||
package input
|
package input
|
||||||
|
|||||||
+23
-23
@@ -17,9 +17,9 @@ const (
|
|||||||
TypePaint
|
TypePaint
|
||||||
TypeColor
|
TypeColor
|
||||||
TypeArea
|
TypeArea
|
||||||
TypePointerHandler
|
TypePointerInput
|
||||||
TypePass
|
TypePass
|
||||||
TypeKeyHandler
|
TypeKeyInput
|
||||||
TypeHideInput
|
TypeHideInput
|
||||||
TypePush
|
TypePush
|
||||||
TypePop
|
TypePop
|
||||||
@@ -29,24 +29,24 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
TypeMacroDefLen = 1 + 4 + 4
|
TypeMacroDefLen = 1 + 4 + 4
|
||||||
TypeMacroLen = 1 + 4 + 4 + 4
|
TypeMacroLen = 1 + 4 + 4 + 4
|
||||||
TypeTransformLen = 1 + 4*2
|
TypeTransformLen = 1 + 4*2
|
||||||
TypeLayerLen = 1
|
TypeLayerLen = 1
|
||||||
TypeRedrawLen = 1 + 8
|
TypeRedrawLen = 1 + 8
|
||||||
TypeImageLen = 1 + 4*4
|
TypeImageLen = 1 + 4*4
|
||||||
TypePaintLen = 1 + 4*4
|
TypePaintLen = 1 + 4*4
|
||||||
TypeColorLen = 1 + 4
|
TypeColorLen = 1 + 4
|
||||||
TypeAreaLen = 1 + 1 + 4*4
|
TypeAreaLen = 1 + 1 + 4*4
|
||||||
TypePointerHandlerLen = 1 + 1
|
TypePointerInputLen = 1 + 1
|
||||||
TypePassLen = 1 + 1
|
TypePassLen = 1 + 1
|
||||||
TypeKeyHandlerLen = 1 + 1
|
TypeKeyInputLen = 1 + 1
|
||||||
TypeHideInputLen = 1
|
TypeHideInputLen = 1
|
||||||
TypePushLen = 1
|
TypePushLen = 1
|
||||||
TypePopLen = 1
|
TypePopLen = 1
|
||||||
TypeAuxLen = 1 + 4
|
TypeAuxLen = 1 + 4
|
||||||
TypeClipLen = 1 + 4*4
|
TypeClipLen = 1 + 4*4
|
||||||
TypeProfileLen = 1
|
TypeProfileLen = 1
|
||||||
)
|
)
|
||||||
|
|
||||||
func (t OpType) Size() int {
|
func (t OpType) Size() int {
|
||||||
@@ -60,9 +60,9 @@ func (t OpType) Size() int {
|
|||||||
TypePaintLen,
|
TypePaintLen,
|
||||||
TypeColorLen,
|
TypeColorLen,
|
||||||
TypeAreaLen,
|
TypeAreaLen,
|
||||||
TypePointerHandlerLen,
|
TypePointerInputLen,
|
||||||
TypePassLen,
|
TypePassLen,
|
||||||
TypeKeyHandlerLen,
|
TypeKeyInputLen,
|
||||||
TypeHideInputLen,
|
TypeHideInputLen,
|
||||||
TypePushLen,
|
TypePushLen,
|
||||||
TypePopLen,
|
TypePopLen,
|
||||||
@@ -74,7 +74,7 @@ func (t OpType) Size() int {
|
|||||||
|
|
||||||
func (t OpType) NumRefs() int {
|
func (t OpType) NumRefs() int {
|
||||||
switch t {
|
switch t {
|
||||||
case TypeMacro, TypeImage, TypeKeyHandler, TypePointerHandler, TypeProfile:
|
case TypeMacro, TypeImage, TypeKeyInput, TypePointerInput, TypeProfile:
|
||||||
return 1
|
return 1
|
||||||
default:
|
default:
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
+6
-6
@@ -4,7 +4,7 @@
|
|||||||
Package key implements key and text events and
|
Package key implements key and text events and
|
||||||
operations.
|
operations.
|
||||||
|
|
||||||
The HandlerOp operations is used for declaring key
|
The InputOp operations is used for declaring key
|
||||||
input handlers. Use the Queue interface from package
|
input handlers. Use the Queue interface from package
|
||||||
input to receive events.
|
input to receive events.
|
||||||
*/
|
*/
|
||||||
@@ -16,11 +16,11 @@ import (
|
|||||||
"gioui.org/ui/internal/opconst"
|
"gioui.org/ui/internal/opconst"
|
||||||
)
|
)
|
||||||
|
|
||||||
// HandlerOp declares a handler ready for key events.
|
// InputOp declares a handler ready for key events.
|
||||||
// Key events are in general only delivered to the
|
// Key events are in general only delivered to the
|
||||||
// focused key handler. Set the Focus flag to request
|
// focused key handler. Set the Focus flag to request
|
||||||
// the focus.
|
// the focus.
|
||||||
type HandlerOp struct {
|
type InputOp struct {
|
||||||
Key input.Key
|
Key input.Key
|
||||||
Focus bool
|
Focus bool
|
||||||
}
|
}
|
||||||
@@ -87,9 +87,9 @@ func (m Modifiers) Contain(m2 Modifiers) bool {
|
|||||||
return m&m2 == m2
|
return m&m2 == m2
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h HandlerOp) Add(o *ui.Ops) {
|
func (h InputOp) Add(o *ui.Ops) {
|
||||||
data := make([]byte, opconst.TypeKeyHandlerLen)
|
data := make([]byte, opconst.TypeKeyInputLen)
|
||||||
data[0] = byte(opconst.TypeKeyHandler)
|
data[0] = byte(opconst.TypeKeyInput)
|
||||||
if h.Focus {
|
if h.Focus {
|
||||||
data[1] = 1
|
data[1] = 1
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-8
@@ -5,14 +5,14 @@ Package pointer implements pointer events and operations.
|
|||||||
A pointer is either a mouse controlled cursor or a touch
|
A pointer is either a mouse controlled cursor or a touch
|
||||||
object such as a finger.
|
object such as a finger.
|
||||||
|
|
||||||
The HandlerOp operation is used to declare a handler ready
|
The InputOp operation is used to declare a handler ready
|
||||||
for pointer events. Use a Queue from package input to
|
for pointer events. Use a Queue from package input to
|
||||||
receive events.
|
receive events.
|
||||||
|
|
||||||
Areas
|
Areas
|
||||||
|
|
||||||
The area operations are used for specifying the area where
|
The area operations are used for specifying the area where
|
||||||
subsequent HandlerOps are active.
|
subsequent InputOp are active.
|
||||||
|
|
||||||
For example, to set up a rectangular hit area:
|
For example, to set up a rectangular hit area:
|
||||||
|
|
||||||
@@ -21,7 +21,7 @@ For example, to set up a rectangular hit area:
|
|||||||
|
|
||||||
r := image.Rectangle{...}
|
r := image.Rectangle{...}
|
||||||
pointer.RectAreaOp{Rect: r}.Add(ops)
|
pointer.RectAreaOp{Rect: r}.Add(ops)
|
||||||
pointer.HandlerOp{Key: h}.Add(ops)
|
pointer.InputOp{Key: h}.Add(ops)
|
||||||
|
|
||||||
Note that areas compound: the effective area of multiple area
|
Note that areas compound: the effective area of multiple area
|
||||||
operations is the intersection of the areas.
|
operations is the intersection of the areas.
|
||||||
@@ -39,11 +39,11 @@ For example:
|
|||||||
var h1, h2 *Handler
|
var h1, h2 *Handler
|
||||||
|
|
||||||
stack.Push(ops)
|
stack.Push(ops)
|
||||||
pointer.HandlerOp{Key: h1}.Add(Ops)
|
pointer.InputOp{Key: h1}.Add(Ops)
|
||||||
stack.Pop()
|
stack.Pop()
|
||||||
|
|
||||||
stack.Push(ops)
|
stack.Push(ops)
|
||||||
pointer.HandlerOp{Key: h2}.Add(ops)
|
pointer.InputOp{Key: h2}.Add(ops)
|
||||||
stack.Pop()
|
stack.Pop()
|
||||||
|
|
||||||
implies a tree of two inner nodes, each with one pointer handler.
|
implies a tree of two inner nodes, each with one pointer handler.
|
||||||
@@ -64,7 +64,7 @@ handlers have the same area (the entire screen).
|
|||||||
Pass-through
|
Pass-through
|
||||||
|
|
||||||
The PassOp operations controls the pass-through setting. A handler's
|
The PassOp operations controls the pass-through setting. A handler's
|
||||||
pass-through setting is recorded along with the HandlerOp.
|
pass-through setting is recorded along with the InputOp.
|
||||||
|
|
||||||
Pass-through handlers are useful for overlay widgets such as a hidden
|
Pass-through handlers are useful for overlay widgets such as a hidden
|
||||||
side drawer. When the user touches the side, both the (transparent)
|
side drawer. When the user touches the side, both the (transparent)
|
||||||
@@ -81,11 +81,11 @@ matching handlers receive all events.
|
|||||||
When a pointer is pressed, the set of matching handlers is
|
When a pointer is pressed, the set of matching handlers is
|
||||||
recorded. The set is not updated according to the pointer position
|
recorded. The set is not updated according to the pointer position
|
||||||
and hit areas. Rather, handlers stay in the matching set until they
|
and hit areas. Rather, handlers stay in the matching set until they
|
||||||
no longer appear in a HandlerOp or when another handler in the set
|
no longer appear in a InputOp or when another handler in the set
|
||||||
grabs the pointer.
|
grabs the pointer.
|
||||||
|
|
||||||
A handler can exclude all other handler from its matching sets
|
A handler can exclude all other handler from its matching sets
|
||||||
by setting the Grab flag in its HandlerOp. The Grab flag is sticky
|
by setting the Grab flag in its InputOp. The Grab flag is sticky
|
||||||
and stays in effect until the handler no longer appears in any
|
and stays in effect until the handler no longer appears in any
|
||||||
matching sets.
|
matching sets.
|
||||||
|
|
||||||
|
|||||||
@@ -61,9 +61,9 @@ type areaOp struct {
|
|||||||
rect image.Rectangle
|
rect image.Rectangle
|
||||||
}
|
}
|
||||||
|
|
||||||
// HandlerOp declares an input handler ready for pointer
|
// InputOp declares an input handler ready for pointer
|
||||||
// events.
|
// events.
|
||||||
type HandlerOp struct {
|
type InputOp struct {
|
||||||
Key input.Key
|
Key input.Key
|
||||||
// Grab, if set, request that the handler get
|
// Grab, if set, request that the handler get
|
||||||
// Grabbed priority.
|
// Grabbed priority.
|
||||||
@@ -150,9 +150,9 @@ func (op areaOp) add(o *ui.Ops) {
|
|||||||
o.Write(data)
|
o.Write(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h HandlerOp) Add(o *ui.Ops) {
|
func (h InputOp) Add(o *ui.Ops) {
|
||||||
data := make([]byte, opconst.TypePointerHandlerLen)
|
data := make([]byte, opconst.TypePointerInputLen)
|
||||||
data[0] = byte(opconst.TypePointerHandler)
|
data[0] = byte(opconst.TypePointerInput)
|
||||||
if h.Grab {
|
if h.Grab {
|
||||||
data[1] = 1
|
data[1] = 1
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -196,7 +196,7 @@ func (e *Editor) Layout(cfg ui.Config, queue input.Queue, ops *ui.Ops, cs layout
|
|||||||
Min: image.Point{X: 0, Y: 0},
|
Min: image.Point{X: 0, Y: 0},
|
||||||
Max: image.Point{X: e.viewSize.X, Y: e.viewSize.Y},
|
Max: image.Point{X: e.viewSize.X, Y: e.viewSize.Y},
|
||||||
}
|
}
|
||||||
key.HandlerOp{Key: e, Focus: e.requestFocus}.Add(ops)
|
key.InputOp{Key: e, Focus: e.requestFocus}.Add(ops)
|
||||||
e.requestFocus = false
|
e.requestFocus = false
|
||||||
e.it = lineIterator{
|
e.it = lineIterator{
|
||||||
Lines: lines,
|
Lines: lines,
|
||||||
|
|||||||
Reference in New Issue
Block a user