From 7fa56013073b7773bf51cf9e9447556a5952f5c4 Mon Sep 17 00:00:00 2001 From: Sander Schobers Date: Mon, 7 Jun 2021 07:48:24 +0200 Subject: [PATCH] Added Pos methods to DisplayDrag{Enter,Move}Event. --- ui/dragdrop.go | 2 +- ui/event.go | 10 +++++++++- ui/examples/03_dragdrop/dragdrop.go | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/ui/dragdrop.go b/ui/dragdrop.go index ae90a22..ac0b23b 100644 --- a/ui/dragdrop.go +++ b/ui/dragdrop.go @@ -34,7 +34,7 @@ func (t *dragDropEventTarget) DragEnter(pos geom.PointF32, files []string) { } func (t *dragDropEventTarget) DragMove(pos geom.PointF32) { - t.pushEvent(&DisplayDragMoveEnter{EventBase: t.eventBase(), X: pos.X, Y: pos.Y}) + t.pushEvent(&DisplayDragMoveEvent{EventBase: t.eventBase(), X: pos.X, Y: pos.Y}) } func (t *dragDropEventTarget) DragLeave() { diff --git a/ui/event.go b/ui/event.go index 790dee7..ae7da2b 100644 --- a/ui/event.go +++ b/ui/event.go @@ -12,15 +12,23 @@ type DisplayDragEnterEvent struct { Files []string } +func (e DisplayDragEnterEvent) Pos() geom.PointF32 { + return geom.PtF32(e.X, e.Y) +} + type DisplayDragLeaveEvent struct { EventBase } -type DisplayDragMoveEnter struct { +type DisplayDragMoveEvent struct { EventBase X, Y float32 } +func (e DisplayDragMoveEvent) Pos() geom.PointF32 { + return geom.PtF32(e.X, e.Y) +} + type DisplayDropEvent struct { EventBase X, Y float32 diff --git a/ui/examples/03_dragdrop/dragdrop.go b/ui/examples/03_dragdrop/dragdrop.go index 3fae73e..2ccd0e6 100644 --- a/ui/examples/03_dragdrop/dragdrop.go +++ b/ui/examples/03_dragdrop/dragdrop.go @@ -45,7 +45,7 @@ func (p *ping) Render(ctx ui.Context) { func (d *dropFiles) Handle(ctx ui.Context, e ui.Event) bool { switch e := e.(type) { - case *ui.DisplayDragMoveEnter: + case *ui.DisplayDragMoveEvent: d.ping.tick = time.Now() d.ping.position = geom.PtF32(e.X, e.Y) d.ping.over = true