Skip to content

Commit

Permalink
share definitions of double click delay between driver and Entry widget
Browse files Browse the repository at this point in the history
  • Loading branch information
dweymouth committed Oct 24, 2023
1 parent 583af44 commit 1caa28e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
8 changes: 8 additions & 0 deletions internal/driver/common/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ import (
"fyne.io/fyne/v2/internal/cache"
)

const (
// moved here from the platform driver packages to allow
// referencing in widget package without an import cycle

DesktopDoubleClickDelay = 300 // ms
MobileDoubleClickDelay = 500 // ms
)

// CanvasForObject returns the canvas for the specified object.
func CanvasForObject(obj fyne.CanvasObject) fyne.Canvas {
return cache.GetCanvasForObject(obj)
Expand Down
5 changes: 2 additions & 3 deletions internal/driver/glfw/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ import (
)

const (
doubleClickDelay = 300 // ms (maximum interval between clicks for double click detection)
dragMoveThreshold = 2 // how far can we move before it is a drag
dragMoveThreshold = 2 // how far can we move before it is a drag
windowIconSize = 256
)

Expand Down Expand Up @@ -652,7 +651,7 @@ func (w *window) mouseClickedHandleTapDoubleTap(co fyne.CanvasObject, ev *fyne.P
func (w *window) waitForDoubleTap(co fyne.CanvasObject, ev *fyne.PointEvent) {
var ctx context.Context
w.mouseLock.Lock()
ctx, w.mouseCancelFunc = context.WithDeadline(context.TODO(), time.Now().Add(time.Millisecond*doubleClickDelay))
ctx, w.mouseCancelFunc = context.WithDeadline(context.TODO(), time.Now().Add(time.Millisecond*common.DesktopDoubleClickDelay))
defer w.mouseCancelFunc()
w.mouseLock.Unlock()

Expand Down
6 changes: 1 addition & 5 deletions internal/driver/mobile/canvas.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ import (
"fyne.io/fyne/v2/widget"
)

const (
doubleClickDelay = 500 // ms (maximum interval between clicks for double click detection)
)

var _ fyne.Canvas = (*mobileCanvas)(nil)

type mobileCanvas struct {
Expand Down Expand Up @@ -378,7 +374,7 @@ func (c *mobileCanvas) tapUp(pos fyne.Position, tapID int,

func (c *mobileCanvas) waitForDoubleTap(co fyne.CanvasObject, ev *fyne.PointEvent, tapCallback func(fyne.Tappable, *fyne.PointEvent), doubleTapCallback func(fyne.DoubleTappable, *fyne.PointEvent)) {
var ctx context.Context
ctx, c.touchCancelFunc = context.WithDeadline(context.TODO(), time.Now().Add(time.Millisecond*doubleClickDelay))
ctx, c.touchCancelFunc = context.WithDeadline(context.TODO(), time.Now().Add(time.Millisecond*common.MobileDoubleClickDelay))
defer c.touchCancelFunc()
<-ctx.Done()
if c.touchTapCount == 2 && c.touchLastTapped == co {
Expand Down
8 changes: 3 additions & 5 deletions widget/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,14 @@ import (
"fyne.io/fyne/v2/driver/desktop"
"fyne.io/fyne/v2/driver/mobile"
"fyne.io/fyne/v2/internal/cache"
"fyne.io/fyne/v2/internal/driver/common"
"fyne.io/fyne/v2/internal/widget"
"fyne.io/fyne/v2/theme"
)

const (
bindIgnoreDelay = time.Millisecond * 100 // ignore incoming DataItem fire after we have called Set
multiLineRows = 3

desktopDoubleClickDelay = 300 // ms - keep in sync with internal/driver/glfw/window.go
mobileDoubleClickDelay = 500 // ms - keep in sync with internal/driver/mobile/canvas.go
)

// Declare conformity with interfaces
Expand Down Expand Up @@ -258,9 +256,9 @@ func (e *Entry) DoubleTapped(p *fyne.PointEvent) {
}

func (e *Entry) isTripleTap(nowMilli int64) bool {
doubleClickDelay := int64(desktopDoubleClickDelay)
doubleClickDelay := int64(common.DesktopDoubleClickDelay)
if fyne.CurrentDevice().IsMobile() {
doubleClickDelay = mobileDoubleClickDelay
doubleClickDelay = common.MobileDoubleClickDelay
}
return nowMilli-e.doubleTappedAtUnixMillis <= doubleClickDelay
}
Expand Down

0 comments on commit 1caa28e

Please sign in to comment.