Skip to content

Commit

Permalink
Attempt some mouse acceleration
Browse files Browse the repository at this point in the history
a simple approach to try and adjust for expectatios for faster-than-hardware scrolling.
Fixes #775
  • Loading branch information
andydotxyz committed Sep 9, 2021
1 parent cf92185 commit 747a4e9
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions internal/driver/glfw/window.go
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"image"
_ "image/png" // for the icon
"math"
"runtime"
"sync"
"time"
Expand All @@ -22,8 +23,10 @@ import (
)

const (
scrollSpeed = float32(10)
doubleClickDelay = 300 // ms (maximum interval between clicks for double click detection)
scrollAccelerateRate = float64(5)
scrollAccelerateCutoff = float64(5)
scrollSpeed = float32(10)
doubleClickDelay = 300 // ms (maximum interval between clicks for double click detection)
)

var (
Expand Down Expand Up @@ -929,6 +932,13 @@ func (w *window) mouseScrolled(viewport *glfw.Window, xoff float64, yoff float64
viewport.GetKey(glfw.KeyRightShift) == glfw.Press) {
xoff, yoff = yoff, xoff
}
if math.Abs(xoff) >= scrollAccelerateCutoff {
xoff *= scrollAccelerateRate
}
if math.Abs(yoff) >= scrollAccelerateCutoff {
yoff *= scrollAccelerateRate
}

ev := &fyne.ScrollEvent{}
ev.Scrolled = fyne.NewDelta(float32(xoff)*scrollSpeed, float32(yoff)*scrollSpeed)
ev.Position = pos
Expand Down

0 comments on commit 747a4e9

Please sign in to comment.