mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
io/pointer: [API] rename PointerEvent.Type to Kind
Kind is the idiomatic field name for distinguishing a struct without using separate types. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+1
-1
@@ -31,7 +31,7 @@ func (d *Draggable) Layout(gtx layout.Context, w, drag layout.Widget) layout.Dim
|
||||
}
|
||||
pos := d.pos
|
||||
for _, ev := range d.drag.Events(gtx.Metric, gtx.Queue, gesture.Both) {
|
||||
switch ev.Type {
|
||||
switch ev.Kind {
|
||||
case pointer.Press:
|
||||
d.click = ev.Position
|
||||
pos = f32.Point{}
|
||||
|
||||
+3
-3
@@ -39,15 +39,15 @@ func TestDraggable(t *testing.T) {
|
||||
r.Queue(
|
||||
pointer.Event{
|
||||
Position: f32.Pt(10, 10),
|
||||
Type: pointer.Press,
|
||||
Kind: pointer.Press,
|
||||
},
|
||||
pointer.Event{
|
||||
Position: f32.Pt(20, 10),
|
||||
Type: pointer.Move,
|
||||
Kind: pointer.Move,
|
||||
},
|
||||
pointer.Event{
|
||||
Position: f32.Pt(20, 10),
|
||||
Type: pointer.Release,
|
||||
Kind: pointer.Release,
|
||||
},
|
||||
)
|
||||
ofr := &offer{data: "hello"}
|
||||
|
||||
+2
-2
@@ -278,10 +278,10 @@ func (e *Editor) processPointer(gtx layout.Context) {
|
||||
case pointer.Event:
|
||||
release := false
|
||||
switch {
|
||||
case evt.Type == pointer.Release && evt.Source == pointer.Mouse:
|
||||
case evt.Kind == pointer.Release && evt.Source == pointer.Mouse:
|
||||
release = true
|
||||
fallthrough
|
||||
case evt.Type == pointer.Drag && evt.Source == pointer.Mouse:
|
||||
case evt.Kind == pointer.Drag && evt.Source == pointer.Mouse:
|
||||
if e.dragging {
|
||||
e.blinkStart = gtx.Now
|
||||
e.text.MoveCoord(image.Point{
|
||||
|
||||
@@ -159,17 +159,17 @@ func TestEditorReadOnly(t *testing.T) {
|
||||
gtx.Ops.Reset()
|
||||
gtx.Queue = &testQueue{events: []event.Event{
|
||||
pointer.Event{
|
||||
Type: pointer.Press,
|
||||
Kind: pointer.Press,
|
||||
Buttons: pointer.ButtonPrimary,
|
||||
Position: f32.Pt(float32(dims.Size.X)*.5, 5),
|
||||
},
|
||||
pointer.Event{
|
||||
Type: pointer.Drag,
|
||||
Kind: pointer.Drag,
|
||||
Buttons: pointer.ButtonPrimary,
|
||||
Position: layout.FPt(dims.Size).Mul(.5),
|
||||
},
|
||||
pointer.Event{
|
||||
Type: pointer.Release,
|
||||
Kind: pointer.Release,
|
||||
Buttons: pointer.ButtonPrimary,
|
||||
Position: layout.FPt(dims.Size).Mul(.5),
|
||||
},
|
||||
@@ -947,13 +947,13 @@ g 2 4 6 8 g
|
||||
events: []event.Event{
|
||||
pointer.Event{
|
||||
Buttons: pointer.ButtonPrimary,
|
||||
Type: pointer.Press,
|
||||
Kind: pointer.Press,
|
||||
Source: pointer.Mouse,
|
||||
Time: tim,
|
||||
Position: f32.Pt(textWidth(e, startPos.lineCol.line, 0, startPos.lineCol.col), textBaseline(e, startPos.lineCol.line)),
|
||||
},
|
||||
pointer.Event{
|
||||
Type: pointer.Release,
|
||||
Kind: pointer.Release,
|
||||
Source: pointer.Mouse,
|
||||
Time: tim,
|
||||
Position: f32.Pt(textWidth(e, endPos.lineCol.line, 0, endPos.lineCol.col), textBaseline(e, endPos.lineCol.line)),
|
||||
|
||||
@@ -47,13 +47,13 @@ func ExampleClickable_passthrough() {
|
||||
pointer.Event{
|
||||
Source: pointer.Mouse,
|
||||
Buttons: pointer.ButtonPrimary,
|
||||
Type: pointer.Press,
|
||||
Kind: pointer.Press,
|
||||
Position: f32.Pt(50, 50),
|
||||
},
|
||||
pointer.Event{
|
||||
Source: pointer.Mouse,
|
||||
Buttons: pointer.ButtonPrimary,
|
||||
Type: pointer.Release,
|
||||
Kind: pointer.Release,
|
||||
Position: f32.Pt(50, 50),
|
||||
},
|
||||
)
|
||||
@@ -125,15 +125,15 @@ func ExampleDraggable_Layout() {
|
||||
// Send drag and drop gesture events.
|
||||
r.Queue(
|
||||
pointer.Event{
|
||||
Type: pointer.Press,
|
||||
Kind: pointer.Press,
|
||||
Position: f32.Pt(5, 5), // in the drag area
|
||||
},
|
||||
pointer.Event{
|
||||
Type: pointer.Move,
|
||||
Kind: pointer.Move,
|
||||
Position: f32.Pt(5, 5), // in the drop area
|
||||
},
|
||||
pointer.Event{
|
||||
Type: pointer.Release,
|
||||
Kind: pointer.Release,
|
||||
Position: f32.Pt(30, 30), // in the drop area
|
||||
},
|
||||
)
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ func (f *Float) Layout(gtx layout.Context, axis layout.Axis, min, max float32, i
|
||||
|
||||
var de *pointer.Event
|
||||
for _, e := range f.drag.Events(gtx.Metric, gtx, gesture.Axis(axis)) {
|
||||
if e.Type == pointer.Press || e.Type == pointer.Drag {
|
||||
if e.Kind == pointer.Press || e.Kind == pointer.Drag {
|
||||
de = &e
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -81,7 +81,7 @@ func (s *Scrollbar) Layout(gtx layout.Context, axis layout.Axis, viewportStart,
|
||||
|
||||
// Offset to account for any drags.
|
||||
for _, event := range s.drag.Events(gtx.Metric, gtx, gesture.Axis(axis)) {
|
||||
switch event.Type {
|
||||
switch event.Kind {
|
||||
case pointer.Drag:
|
||||
case pointer.Release, pointer.Cancel:
|
||||
s.dragging = false
|
||||
|
||||
@@ -271,10 +271,10 @@ func (e *Selectable) processPointer(gtx layout.Context) {
|
||||
case pointer.Event:
|
||||
release := false
|
||||
switch {
|
||||
case evt.Type == pointer.Release && evt.Source == pointer.Mouse:
|
||||
case evt.Kind == pointer.Release && evt.Source == pointer.Mouse:
|
||||
release = true
|
||||
fallthrough
|
||||
case evt.Type == pointer.Drag && evt.Source == pointer.Mouse:
|
||||
case evt.Kind == pointer.Drag && evt.Source == pointer.Mouse:
|
||||
if e.dragging {
|
||||
e.text.MoveCoord(image.Point{
|
||||
X: int(math.Round(float64(evt.Position.X))),
|
||||
|
||||
@@ -35,12 +35,12 @@ func TestBool(t *testing.T) {
|
||||
r.Queue(
|
||||
pointer.Event{
|
||||
Source: pointer.Touch,
|
||||
Type: pointer.Press,
|
||||
Kind: pointer.Press,
|
||||
Position: f32.Pt(50, 50),
|
||||
},
|
||||
pointer.Event{
|
||||
Source: pointer.Touch,
|
||||
Type: pointer.Release,
|
||||
Kind: pointer.Release,
|
||||
Position: f32.Pt(50, 50),
|
||||
},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user