Skip to content

Commit

Permalink
Switch event type for dragging and drop all but the last drag event i…
Browse files Browse the repository at this point in the history
…n a series
  • Loading branch information
sdassow committed Nov 22, 2024
1 parent 29c2216 commit b25428a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
13 changes: 13 additions & 0 deletions event.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,16 @@ type SimpleEventFunc func()
func (fn SimpleEventFunc) Execute() {
fn()
}

type DragEventFunc struct {
wid Draggable
ev *DragEvent
}

func NewDragEventFunc(wid Draggable, ev *DragEvent) *DragEventFunc {
return &DragEventFunc{wid, ev}
}

func (drag *DragEventFunc) Execute() {
drag.wid.Dragged(drag.ev)
}
28 changes: 26 additions & 2 deletions internal/driver/common/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,32 @@ func (w *Window) QueueEvent(fn fyne.EventFunc) {
// RunEventQueue runs the event queue. This should called inside a go routine.
// This function blocks.
func (w *Window) RunEventQueue() {
for fn := range w.eventQueue.Out() {
fn.Execute()
for evfn := range w.eventQueue.Out() {
if dragfn, ok := evfn.(*fyne.DragEventFunc); ok {
evfn = nil

L: for {
select {
case nevfn := <- w.eventQueue.Out():
ndragfn, ok := nevfn.(*fyne.DragEventFunc)
if !ok {
evfn = nevfn
break L
}
dragfn = ndragfn
default:
break L
}
}

dragfn.Execute()
if evfn != nil {
evfn.Execute()
}
continue
}

evfn.Execute()
}
}

Expand Down
3 changes: 1 addition & 2 deletions internal/driver/glfw/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,7 @@ func (w *window) processMouseMoved(xpos float64, ypos float64) {
ev.AbsolutePosition = mousePos
ev.Position = mousePos.Subtract(mouseDraggedOffset).Add(draggedObjDelta)
ev.Dragged = fyne.NewDelta(mousePos.X-mouseDragPos.X, mousePos.Y-mouseDragPos.Y)
wd := mouseDragged
w.QueueEvent(fyne.SimpleEventFunc(func() { wd.Dragged(ev) }))
w.QueueEvent(fyne.NewDragEventFunc(mouseDragged, ev))
}

w.mouseLock.Lock()
Expand Down
2 changes: 1 addition & 1 deletion internal/driver/mobile/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ func (d *driver) tapMoveCanvas(w *window, x, y float32, tapID touch.Sequence) {
pos := fyne.NewPos(tapX, tapY+tapYOffset)

w.canvas.tapMove(pos, int(tapID), func(wid fyne.Draggable, ev *fyne.DragEvent) {
w.QueueEvent(fyne.SimpleEventFunc(func() { wid.Dragged(ev) }))
w.QueueEvent(fyne.NewDragEventFunc(wid, ev))
})
}

Expand Down

0 comments on commit b25428a

Please sign in to comment.