forked from google/gxui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
control.go
192 lines (146 loc) · 6.94 KB
/
control.go
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package gxui
import "github.com/google/gxui/math"
// Control is the interface exposed by all UI control elements.
type Control interface {
// Size returns the size of the control. If the control is not attached, then
// the returned size is undefined.
Size() math.Size
// SetSize sets the size of the control to the specified value.
// SetSize should only be called by the parent of the control during layout.
SetSize(math.Size)
// Draw draws the control's visual apperance into the returned, new canvas.
// Draw is typically called by the parent of the control - calling Draw will
// not issue a re-draw of an attached control.
Draw() Canvas
// Parent returns the parent of the control.
Parent() Parent
// SetParent sets the parent of the control.
// SetParent should only be called by the new parent of the control.
SetParent(Parent)
// Attached returns true if the control is directly or indirectly attached
// to a window.
Attached() bool
// Attach is called when the control is directly or indirectly attached to a
// window.
// Attach should only be called by the parent of the control.
Attach()
// Detach is called when the control is directly or indirectly detached from a
// window.
// Detach should only be called by the parent of the control.
Detach()
// DesiredSize returns the desired size of the control based on the min and
// max size limits. The parent control may ignore the desired size.
DesiredSize(min, max math.Size) math.Size
// Margin returns the desired spacing between sibling controls.
Margin() math.Spacing
// SetMargin set the desired spacing between sibling controls, issuing a
// relayout if the margin has changed.
SetMargin(math.Spacing)
// IsVisible returns true if the control is visible.
IsVisible() bool
// SetVisible sets the visibility of the control.
SetVisible(bool)
// ContainsPoint returns true if the specified local-space point is considered
// within the control.
ContainsPoint(math.Point) bool
// IsMouseOver returns true if the mouse cursor was last reported within the
// control.
IsMouseOver() bool
// IsMouseDown returns true if button was last reported pressed on the
// control.
IsMouseDown(button MouseButton) bool
// Click is called when the mouse is pressed and released on the control.
// If Click returns true, then the click event is consumed by the control,
// otherwise the next control below the should be considered for the click
// event.
Click(MouseEvent) (consume bool)
// DoubleClick is called when the mouse is double-clicked on the control.
// If DoubleClick returns true, then the double-click event is consumed by the
// control, otherwise the next control below the should be considered for the
// double-click event.
DoubleClick(MouseEvent) (consume bool)
// KeyPress is called when a keyboard key is pressed while the control (or
// non-consuming child) has focus. If KeyPress returns true, then the
// key-press event is consumed by the control, otherwise the parent control
// should be considered for the key-press event.
KeyPress(KeyboardEvent) (consume bool)
// KeyStroke is called when a key-storke is made while the control (or
// non-consuming child) has focus. If KeyStroke returns true, then the
// key-stroke event is consumed by the control, otherwise the parent control
// should be considered for the key-stroke event.
KeyStroke(KeyStrokeEvent) (consume bool)
// MouseScroll is called when a mouse scroll is made while the control (or
// non-consuming child) has focus. If MouseScroll returns true, then the
// mouse-scroll event is consumed by the control, otherwise the parent control
// should be considered for the key-stroke event.
MouseScroll(MouseEvent) (consume bool)
// MouseMove is called when the mouse cursor moves over the control.
MouseMove(MouseEvent)
// MouseEnter is called when the mouse cursor transitions from outside to
// inside the bounds of the control.
MouseEnter(MouseEvent)
// MouseExit is called when the mouse cursor transitions from inside to
// outside the bounds of the control.
MouseExit(MouseEvent)
// MouseDown is called when a mouse button is pressed while the mouse cursor
// is over the control.
MouseDown(MouseEvent)
// MouseUp is called when a mouse button is released while the mouse cursor
// is over the control.
MouseUp(MouseEvent)
// KeyDown is called when a keyboard button is pressed while the control (or
// child control) has focus.
KeyDown(KeyboardEvent)
// KeyUp is called when a keyboard button is released while the control (or
// child control) has focus.
KeyUp(KeyboardEvent)
// KeyRepeat is called when a keyboard button held long enough for a
// repeat-key event while the control (or child control) has focus.
KeyRepeat(KeyboardEvent)
// OnAttach subscribes f to be called whenever the control is attached.
OnAttach(f func()) EventSubscription
// OnDetach subscribes f to be called whenever the control is detached.
OnDetach(f func()) EventSubscription
// OnKeyPress subscribes f to be called whenever the control receives a
// key-press event.
OnKeyPress(f func(KeyboardEvent)) EventSubscription
// OnKeyStroke subscribes f to be called whenever the control receives a
// key-stroke event.
OnKeyStroke(f func(KeyStrokeEvent)) EventSubscription
// OnClick subscribes f to be called whenever the control receives a click
// event.
OnClick(f func(MouseEvent)) EventSubscription
// OnDoubleClick subscribes f to be called whenever the control receives a
// double-click event.
OnDoubleClick(f func(MouseEvent)) EventSubscription
// OnMouseMove subscribes f to be called whenever the control receives a
// mouse-move event.
OnMouseMove(f func(MouseEvent)) EventSubscription
// OnMouseEnter subscribes f to be called whenever the control receives a
// mouse-enter event.
OnMouseEnter(f func(MouseEvent)) EventSubscription
// OnMouseExit subscribes f to be called whenever the control receives a
// mouse-exit event.
OnMouseExit(f func(MouseEvent)) EventSubscription
// OnMouseDown subscribes f to be called whenever the control receives a
// mouse-down event.
OnMouseDown(f func(MouseEvent)) EventSubscription
// OnMouseUp subscribes f to be called whenever the control receives a
// mouse-up event.
OnMouseUp(f func(MouseEvent)) EventSubscription
// OnMouseScroll subscribes f to be called whenever the control receives a
// mouse-scroll event.
OnMouseScroll(f func(MouseEvent)) EventSubscription
// OnKeyDown subscribes f to be called whenever the control receives a
// key-down event.
OnKeyDown(f func(KeyboardEvent)) EventSubscription
// OnKeyUp subscribes f to be called whenever the control receives a
// key-up event.
OnKeyUp(f func(KeyboardEvent)) EventSubscription
// OnKeyRepeat subscribes f to be called whenever the control receives a
// key-repeat event.
OnKeyRepeat(f func(KeyboardEvent)) EventSubscription
}