diff --git a/internal/devicescale/devicescale.go b/internal/devicescale/devicescale.go index c2c646e98..9d1c05e50 100644 --- a/internal/devicescale/devicescale.go +++ b/internal/devicescale/devicescale.go @@ -27,6 +27,8 @@ var ( cache = map[pos]float64{} ) +// GetAt returns the device scale at (x, y). +// x and y are in device-dependent pixels. func GetAt(x, y int) float64 { m.Lock() defer m.Unlock() diff --git a/internal/uidriver/glfw/ui_unix.go b/internal/uidriver/glfw/ui_unix.go index e3b842115..69c8a2d82 100644 --- a/internal/uidriver/glfw/ui_unix.go +++ b/internal/uidriver/glfw/ui_unix.go @@ -25,6 +25,7 @@ import ( // fromGLFWMonitorPixel must be called from the main thread. func fromGLFWMonitorPixel(x float64, deviceScale float64) float64 { + // deviceScaleFactor is sometimes an unnice value (e.g., 1.502361). Use math.Ceil to clean the vaule. return math.Ceil(x / deviceScale) } @@ -45,6 +46,7 @@ func (u *UserInterface) toGLFWPixel(x float64) float64 { // toFramebufferPixel must be called from the main thread. func (u *UserInterface) toFramebufferPixel(x float64) float64 { s, _ := currentMonitor(u.window).GetContentScale() + // deviceScaleFactor is sometimes an unnice value (e.g., 1.502361). Use math.Ceil to clean the vaule. return math.Ceil(x * float64(s) / u.deviceScaleFactor()) }