diff --git a/internal/driver/common/driver.go b/internal/driver/common/driver.go index bcca9b8cde..b56fa80738 100644 --- a/internal/driver/common/driver.go +++ b/internal/driver/common/driver.go @@ -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) diff --git a/internal/driver/glfw/window.go b/internal/driver/glfw/window.go index 971fc486d0..7725a50ec1 100644 --- a/internal/driver/glfw/window.go +++ b/internal/driver/glfw/window.go @@ -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 ) @@ -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() diff --git a/internal/driver/mobile/canvas.go b/internal/driver/mobile/canvas.go index ec2375ba3b..4fd61cf06e 100644 --- a/internal/driver/mobile/canvas.go +++ b/internal/driver/mobile/canvas.go @@ -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 { @@ -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 { diff --git a/widget/entry.go b/widget/entry.go index 7e5383903c..c30d723015 100644 --- a/widget/entry.go +++ b/widget/entry.go @@ -14,6 +14,7 @@ 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" ) @@ -21,9 +22,6 @@ import ( 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 @@ -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 }