mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +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:
|
||||
for encOp, ok := q.reader.Decode(); ok; encOp, ok = q.reader.Decode() {
|
||||
switch opconst.OpType(encOp.Data[0]) {
|
||||
case opconst.TypeKeyHandler:
|
||||
op := decodeKeyHandlerOp(encOp.Data, encOp.Refs)
|
||||
case opconst.TypeKeyInput:
|
||||
op := decodeKeyInputOp(encOp.Data, encOp.Refs)
|
||||
var newPri listenerPriority
|
||||
switch {
|
||||
case op.Focus:
|
||||
@@ -139,11 +139,11 @@ func (p listenerPriority) replaces(p2 listenerPriority) bool {
|
||||
return p > p2 || p == p2 && p == priNewFocus
|
||||
}
|
||||
|
||||
func decodeKeyHandlerOp(d []byte, refs []interface{}) key.HandlerOp {
|
||||
if opconst.OpType(d[0]) != opconst.TypeKeyHandler {
|
||||
func decodeKeyInputOp(d []byte, refs []interface{}) key.InputOp {
|
||||
if opconst.OpType(d[0]) != opconst.TypeKeyInput {
|
||||
panic("invalid op")
|
||||
}
|
||||
return key.HandlerOp{
|
||||
return key.InputOp{
|
||||
Focus: d[1] != 0,
|
||||
Key: refs[0].(input.Key),
|
||||
}
|
||||
|
||||
@@ -88,8 +88,8 @@ func (q *pointerQueue) collectHandlers(r *ops.Reader, events *handlerEvents, t u
|
||||
case opconst.TypeTransform:
|
||||
op := ops.DecodeTransformOp(encOp.Data)
|
||||
t = t.Multiply(ui.TransformOp(op))
|
||||
case opconst.TypePointerHandler:
|
||||
op := decodePointerHandlerOp(encOp.Data, encOp.Refs)
|
||||
case opconst.TypePointerInput:
|
||||
op := decodePointerInputOp(encOp.Data, encOp.Refs)
|
||||
q.hitTree = append(q.hitTree, hitNode{
|
||||
next: node,
|
||||
area: area,
|
||||
@@ -314,11 +314,11 @@ func (op *areaOp) Hit(pos f32.Point) bool {
|
||||
}
|
||||
}
|
||||
|
||||
func decodePointerHandlerOp(d []byte, refs []interface{}) pointer.HandlerOp {
|
||||
if opconst.OpType(d[0]) != opconst.TypePointerHandler {
|
||||
func decodePointerInputOp(d []byte, refs []interface{}) pointer.InputOp {
|
||||
if opconst.OpType(d[0]) != opconst.TypePointerInput {
|
||||
panic("invalid op")
|
||||
}
|
||||
return pointer.HandlerOp{
|
||||
return pointer.InputOp{
|
||||
Grab: d[1] != 0,
|
||||
Key: refs[0].(input.Key),
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ const (
|
||||
|
||||
// Add the handler to the operation list to receive click events.
|
||||
func (c *Click) Add(ops *ui.Ops) {
|
||||
op := pointer.HandlerOp{Key: c}
|
||||
op := pointer.InputOp{Key: c}
|
||||
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.
|
||||
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)
|
||||
if s.flinger.Active() {
|
||||
ui.InvalidateOp{}.Add(ops)
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ The following example marks a handler ready for key input:
|
||||
|
||||
ops := new(ui.Ops)
|
||||
var h *Handler = ...
|
||||
key.HandlerOp{Key: h}.Add(ops)
|
||||
key.InputOp{Key: h}.Add(ops)
|
||||
|
||||
*/
|
||||
package input
|
||||
|
||||
+23
-23
@@ -17,9 +17,9 @@ const (
|
||||
TypePaint
|
||||
TypeColor
|
||||
TypeArea
|
||||
TypePointerHandler
|
||||
TypePointerInput
|
||||
TypePass
|
||||
TypeKeyHandler
|
||||
TypeKeyInput
|
||||
TypeHideInput
|
||||
TypePush
|
||||
TypePop
|
||||
@@ -29,24 +29,24 @@ const (
|
||||
)
|
||||
|
||||
const (
|
||||
TypeMacroDefLen = 1 + 4 + 4
|
||||
TypeMacroLen = 1 + 4 + 4 + 4
|
||||
TypeTransformLen = 1 + 4*2
|
||||
TypeLayerLen = 1
|
||||
TypeRedrawLen = 1 + 8
|
||||
TypeImageLen = 1 + 4*4
|
||||
TypePaintLen = 1 + 4*4
|
||||
TypeColorLen = 1 + 4
|
||||
TypeAreaLen = 1 + 1 + 4*4
|
||||
TypePointerHandlerLen = 1 + 1
|
||||
TypePassLen = 1 + 1
|
||||
TypeKeyHandlerLen = 1 + 1
|
||||
TypeHideInputLen = 1
|
||||
TypePushLen = 1
|
||||
TypePopLen = 1
|
||||
TypeAuxLen = 1 + 4
|
||||
TypeClipLen = 1 + 4*4
|
||||
TypeProfileLen = 1
|
||||
TypeMacroDefLen = 1 + 4 + 4
|
||||
TypeMacroLen = 1 + 4 + 4 + 4
|
||||
TypeTransformLen = 1 + 4*2
|
||||
TypeLayerLen = 1
|
||||
TypeRedrawLen = 1 + 8
|
||||
TypeImageLen = 1 + 4*4
|
||||
TypePaintLen = 1 + 4*4
|
||||
TypeColorLen = 1 + 4
|
||||
TypeAreaLen = 1 + 1 + 4*4
|
||||
TypePointerInputLen = 1 + 1
|
||||
TypePassLen = 1 + 1
|
||||
TypeKeyInputLen = 1 + 1
|
||||
TypeHideInputLen = 1
|
||||
TypePushLen = 1
|
||||
TypePopLen = 1
|
||||
TypeAuxLen = 1 + 4
|
||||
TypeClipLen = 1 + 4*4
|
||||
TypeProfileLen = 1
|
||||
)
|
||||
|
||||
func (t OpType) Size() int {
|
||||
@@ -60,9 +60,9 @@ func (t OpType) Size() int {
|
||||
TypePaintLen,
|
||||
TypeColorLen,
|
||||
TypeAreaLen,
|
||||
TypePointerHandlerLen,
|
||||
TypePointerInputLen,
|
||||
TypePassLen,
|
||||
TypeKeyHandlerLen,
|
||||
TypeKeyInputLen,
|
||||
TypeHideInputLen,
|
||||
TypePushLen,
|
||||
TypePopLen,
|
||||
@@ -74,7 +74,7 @@ func (t OpType) Size() int {
|
||||
|
||||
func (t OpType) NumRefs() int {
|
||||
switch t {
|
||||
case TypeMacro, TypeImage, TypeKeyHandler, TypePointerHandler, TypeProfile:
|
||||
case TypeMacro, TypeImage, TypeKeyInput, TypePointerInput, TypeProfile:
|
||||
return 1
|
||||
default:
|
||||
return 0
|
||||
|
||||
+6
-6
@@ -4,7 +4,7 @@
|
||||
Package key implements key and text events and
|
||||
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 to receive events.
|
||||
*/
|
||||
@@ -16,11 +16,11 @@ import (
|
||||
"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
|
||||
// focused key handler. Set the Focus flag to request
|
||||
// the focus.
|
||||
type HandlerOp struct {
|
||||
type InputOp struct {
|
||||
Key input.Key
|
||||
Focus bool
|
||||
}
|
||||
@@ -87,9 +87,9 @@ func (m Modifiers) Contain(m2 Modifiers) bool {
|
||||
return m&m2 == m2
|
||||
}
|
||||
|
||||
func (h HandlerOp) Add(o *ui.Ops) {
|
||||
data := make([]byte, opconst.TypeKeyHandlerLen)
|
||||
data[0] = byte(opconst.TypeKeyHandler)
|
||||
func (h InputOp) Add(o *ui.Ops) {
|
||||
data := make([]byte, opconst.TypeKeyInputLen)
|
||||
data[0] = byte(opconst.TypeKeyInput)
|
||||
if h.Focus {
|
||||
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
|
||||
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
|
||||
receive events.
|
||||
|
||||
Areas
|
||||
|
||||
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:
|
||||
|
||||
@@ -21,7 +21,7 @@ For example, to set up a rectangular hit area:
|
||||
|
||||
r := image.Rectangle{...}
|
||||
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
|
||||
operations is the intersection of the areas.
|
||||
@@ -39,11 +39,11 @@ For example:
|
||||
var h1, h2 *Handler
|
||||
|
||||
stack.Push(ops)
|
||||
pointer.HandlerOp{Key: h1}.Add(Ops)
|
||||
pointer.InputOp{Key: h1}.Add(Ops)
|
||||
stack.Pop()
|
||||
|
||||
stack.Push(ops)
|
||||
pointer.HandlerOp{Key: h2}.Add(ops)
|
||||
pointer.InputOp{Key: h2}.Add(ops)
|
||||
stack.Pop()
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
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
|
||||
recorded. The set is not updated according to the pointer position
|
||||
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.
|
||||
|
||||
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
|
||||
matching sets.
|
||||
|
||||
|
||||
@@ -61,9 +61,9 @@ type areaOp struct {
|
||||
rect image.Rectangle
|
||||
}
|
||||
|
||||
// HandlerOp declares an input handler ready for pointer
|
||||
// InputOp declares an input handler ready for pointer
|
||||
// events.
|
||||
type HandlerOp struct {
|
||||
type InputOp struct {
|
||||
Key input.Key
|
||||
// Grab, if set, request that the handler get
|
||||
// Grabbed priority.
|
||||
@@ -150,9 +150,9 @@ func (op areaOp) add(o *ui.Ops) {
|
||||
o.Write(data)
|
||||
}
|
||||
|
||||
func (h HandlerOp) Add(o *ui.Ops) {
|
||||
data := make([]byte, opconst.TypePointerHandlerLen)
|
||||
data[0] = byte(opconst.TypePointerHandler)
|
||||
func (h InputOp) Add(o *ui.Ops) {
|
||||
data := make([]byte, opconst.TypePointerInputLen)
|
||||
data[0] = byte(opconst.TypePointerInput)
|
||||
if h.Grab {
|
||||
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},
|
||||
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.it = lineIterator{
|
||||
Lines: lines,
|
||||
|
||||
Reference in New Issue
Block a user