ref: a296903c76776fc1fca7fc09c53d5ca9c8059c03 gio/ui/pointer/doc.go -rw-r--r-- 3.7 KiB View raw
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// SPDX-License-Identifier: Unlicense OR MIT

/*
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
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.

For example, to set up a rectangular hit area:

	var ops ui.Ops
	var h *Handler = ...

	r := image.Rectangle{...}
	pointer.RectAreaOp{Rect: r}.Add(ops)
	pointer.HandlerOp{Key: h}.Add(ops)

Note that areas compound: the effective area of multiple area
operations is the intersection of the areas.

Matching events

StackOp operations and input handlers form an implicit tree.
Each stack operation is a node, and each input handler is associated
with the most recent node.

For example:

	ops := new(ui.Ops)
	var stack ui.StackOp
	var h1, h2 *Handler

	stack.Push(ops)
	pointer.HandlerOp{Key: h1}.Add(Ops)
	stack.Pop()

	stack.Push(ops)
	pointer.HandlerOp{Key: h2}.Add(ops)
	stack.Pop()

implies a tree of two inner nodes, each with one pointer handler.

When determining which handlers match an Event, only handlers whose
areas contain the event position are considered. The matching
proceeds as follows.

First, the foremost matching handler is included. If the handler
has pass-through enabled, this step is repeated.

Then, all matching handlers from the current node and all parent
nodes are included.

In the example above, all events will go to h2 only even though both
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 handlers are useful for overlay widgets such as a hidden
side drawer. When the user touches the side, both the (transparent)
drawer handle and the interface below should receive pointer events.

Disambiguation

When more than one handler matches a pointer event, the input queue
follows a set of rules for distributing the event.

As long as the pointer has not received a Press event, all
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
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
and stays in effect until the handler no longer appears in any
matching sets.

The losing handlers are notified by a Cancel event.

For multiple grabbing handlers, the foremost handler wins.

Priorities

Handlers know their position in a matching set of a pointer through
event priorities. The Shared and Foremost priorities are for matching sets
with multiple handlers; the Grabbed priority indicate exclusive access.

Priorities are useful for deferred gesture matching.

Consider a scrollable list of clickable elements. When the user touches an
element, it is unknown whether the gesture is a click on the element
or a drag (scroll) of the list. While the click handler might light up
the element in anticipation of a click, the scrolling handler does not
scroll on finger movements with lower than Grabbed priority.

Should the user release the finger, the click handler registers a click.

However, if the finger moves beyond a threshold, the scrolling handler
determines that the gesture is a drag and sets its Grab flag. The
click handler receives a Cancel (removing the highlight) and further
movements for the scroll handler has priority Grabbed, scrolling the
list.
*/
package pointer