Skip to content

Commit 6afd8b9

Browse files
committed
gesture: [API] rename ClickType to ClickKind
"Kind" is the Go idiomatic name for distinguishing structs outside of the type system. Signed-off-by: Elias Naur <[email protected]>
1 parent 45657d7 commit 6afd8b9

File tree

7 files changed

+31
-31
lines changed

7 files changed

+31
-31
lines changed

gesture/gesture.go

+18-18
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ type Click struct {
8787
}
8888

8989
// ClickEvent represent a click action, either a
90-
// TypePress for the beginning of a click or a
91-
// TypeClick for a completed click.
90+
// KindPress for the beginning of a click or a
91+
// KindClick for a completed click.
9292
type ClickEvent struct {
93-
Type ClickType
93+
Kind ClickKind
9494
Position image.Point
9595
Source pointer.Source
9696
Modifiers key.Modifiers
@@ -99,7 +99,7 @@ type ClickEvent struct {
9999
NumClicks int
100100
}
101101

102-
type ClickType uint8
102+
type ClickKind uint8
103103

104104
// Drag detects drag gestures in the form of pointer.Drag events.
105105
type Drag struct {
@@ -136,15 +136,15 @@ const (
136136
)
137137

138138
const (
139-
// TypePress is reported for the first pointer
139+
// KindPress is reported for the first pointer
140140
// press.
141-
TypePress ClickType = iota
142-
// TypeClick is reported when a click action
141+
KindPress ClickKind = iota
142+
// KindClick is reported when a click action
143143
// is complete.
144-
TypeClick
145-
// TypeCancel is reported when the gesture is
144+
KindClick
145+
// KindCancel is reported when the gesture is
146146
// cancelled.
147-
TypeCancel
147+
KindCancel
148148
)
149149

150150
const (
@@ -192,17 +192,17 @@ func (c *Click) Events(q event.Queue) []ClickEvent {
192192
}
193193
c.pressed = false
194194
if !c.entered || c.hovered {
195-
events = append(events, ClickEvent{Type: TypeClick, Position: e.Position.Round(), Source: e.Source, Modifiers: e.Modifiers, NumClicks: c.clicks})
195+
events = append(events, ClickEvent{Kind: KindClick, Position: e.Position.Round(), Source: e.Source, Modifiers: e.Modifiers, NumClicks: c.clicks})
196196
} else {
197-
events = append(events, ClickEvent{Type: TypeCancel})
197+
events = append(events, ClickEvent{Kind: KindCancel})
198198
}
199199
case pointer.Cancel:
200200
wasPressed := c.pressed
201201
c.pressed = false
202202
c.hovered = false
203203
c.entered = false
204204
if wasPressed {
205-
events = append(events, ClickEvent{Type: TypeCancel})
205+
events = append(events, ClickEvent{Kind: KindCancel})
206206
}
207207
case pointer.Press:
208208
if c.pressed {
@@ -224,7 +224,7 @@ func (c *Click) Events(q event.Queue) []ClickEvent {
224224
c.clicks = 1
225225
}
226226
c.clickedAt = e.Time
227-
events = append(events, ClickEvent{Type: TypePress, Position: e.Position.Round(), Source: e.Source, Modifiers: e.Modifiers, NumClicks: c.clicks})
227+
events = append(events, ClickEvent{Kind: KindPress, Position: e.Position.Round(), Source: e.Source, Modifiers: e.Modifiers, NumClicks: c.clicks})
228228
case pointer.Leave:
229229
if !c.pressed {
230230
c.pid = e.PointerID
@@ -444,13 +444,13 @@ func (a Axis) String() string {
444444
}
445445
}
446446

447-
func (ct ClickType) String() string {
447+
func (ct ClickKind) String() string {
448448
switch ct {
449-
case TypePress:
449+
case KindPress:
450450
return "TypePress"
451-
case TypeClick:
451+
case KindClick:
452452
return "TypeClick"
453-
case TypeCancel:
453+
case KindCancel:
454454
return "TypeCancel"
455455
default:
456456
panic("invalid ClickType")

gesture/gesture_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func mouseClickEvents(times ...time.Duration) []event.Event {
110110
func filterMouseClicks(events []ClickEvent) []ClickEvent {
111111
var clicks []ClickEvent
112112
for _, ev := range events {
113-
if ev.Type == TypeClick {
113+
if ev.Kind == KindClick {
114114
clicks = append(clicks, ev)
115115
}
116116
}

widget/button.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -149,23 +149,23 @@ func (b *Clickable) update(gtx layout.Context) {
149149
b.prevClicks = n
150150

151151
for _, e := range b.click.Events(gtx) {
152-
switch e.Type {
153-
case gesture.TypeClick:
152+
switch e.Kind {
153+
case gesture.KindClick:
154154
b.clicks = append(b.clicks, Click{
155155
Modifiers: e.Modifiers,
156156
NumClicks: e.NumClicks,
157157
})
158158
if l := len(b.history); l > 0 {
159159
b.history[l-1].End = gtx.Now
160160
}
161-
case gesture.TypeCancel:
161+
case gesture.KindCancel:
162162
for i := range b.history {
163163
b.history[i].Cancelled = true
164164
if b.history[i].End.IsZero() {
165165
b.history[i].End = gtx.Now
166166
}
167167
}
168-
case gesture.TypePress:
168+
case gesture.KindPress:
169169
if e.Source == pointer.Mouse {
170170
key.FocusOp{Tag: &b.keyTag}.Add(gtx.Ops)
171171
}

widget/editor.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@ func (e *Editor) processPointer(gtx layout.Context) {
238238
switch evt := evt.(type) {
239239
case gesture.ClickEvent:
240240
switch {
241-
case evt.Type == gesture.TypePress && evt.Source == pointer.Mouse,
242-
evt.Type == gesture.TypeClick && evt.Source != pointer.Mouse:
241+
case evt.Kind == gesture.KindPress && evt.Source == pointer.Mouse,
242+
evt.Kind == gesture.KindClick && evt.Source != pointer.Mouse:
243243
prevCaretPos, _ := e.text.Selection()
244244
e.blinkStart = gtx.Now
245245
e.text.MoveCoord(image.Point{

widget/enum.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ func (e *Enum) Layout(gtx layout.Context, k string, content layout.Widget) layou
7474
}
7575
clk := &state.click
7676
for _, ev := range clk.Events(gtx) {
77-
switch ev.Type {
78-
case gesture.TypePress:
77+
switch ev.Kind {
78+
case gesture.KindPress:
7979
if ev.Source == pointer.Mouse {
8080
key.FocusOp{Tag: &state.tag}.Add(gtx.Ops)
8181
}
82-
case gesture.TypeClick:
82+
case gesture.KindClick:
8383
if state.key != e.Value {
8484
e.Value = state.key
8585
e.changed = true

widget/list.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (s *Scrollbar) Layout(gtx layout.Context, axis layout.Axis, viewportStart,
6262

6363
// Jump to a click in the track.
6464
for _, event := range s.track.Events(gtx) {
65-
if event.Type != gesture.TypeClick ||
65+
if event.Kind != gesture.KindClick ||
6666
event.Modifiers != key.Modifiers(0) ||
6767
event.NumClicks > 1 {
6868
continue

widget/selectable.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,8 @@ func (e *Selectable) processPointer(gtx layout.Context) {
236236
switch evt := evt.(type) {
237237
case gesture.ClickEvent:
238238
switch {
239-
case evt.Type == gesture.TypePress && evt.Source == pointer.Mouse,
240-
evt.Type == gesture.TypeClick && evt.Source != pointer.Mouse:
239+
case evt.Kind == gesture.KindPress && evt.Source == pointer.Mouse,
240+
evt.Kind == gesture.KindClick && evt.Source != pointer.Mouse:
241241
prevCaretPos, _ := e.text.Selection()
242242
e.text.MoveCoord(image.Point{
243243
X: int(math.Round(float64(evt.Position.X))),

0 commit comments

Comments
 (0)