Skip to content

Commit 58932d4

Browse files
Make the scroll amount configurable (#380)
* Make the scroll amount configurable * change default scroll amount to 100
1 parent dc5c5d5 commit 58932d4

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

application.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,10 @@ func (a *Application) Run() error {
327327
a.window.SetCursorEnterCallback(windowManager.glfwCursorEnterCallback)
328328
a.window.SetCursorPosCallback(windowManager.glfwCursorPosCallback)
329329
a.window.SetMouseButtonCallback(windowManager.glfwMouseButtonCallback)
330-
a.window.SetScrollCallback(windowManager.glfwScrollCallback)
330+
a.window.SetScrollCallback(
331+
func(window *glfw.Window, xoff float64, yoff float64) {
332+
windowManager.glfwScrollCallback(window, xoff, yoff, a.config.scrollAmount)
333+
})
331334

332335
// Shutdown the engine if we return from this function (on purpose or panic)
333336
defer a.engine.Shutdown()

glfw.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ func (m *windowManager) glfwMouseButtonCallback(window *glfw.Window, key glfw.Mo
188188
}
189189
}
190190

191-
func (m *windowManager) glfwScrollCallback(window *glfw.Window, xoff float64, yoff float64) {
192-
const scrollModifier = -50
191+
func (m *windowManager) glfwScrollCallback(window *glfw.Window, xoff float64, yoff float64, scrollAmount float64) {
192+
scrollModifier := -scrollAmount
193193
m.sendPointerEventScroll(window, xoff*scrollModifier, yoff*scrollModifier)
194194
}
195195

option.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type config struct {
2222

2323
forcePixelRatio float64
2424
keyboardLayout KeyboardShortcuts
25+
scrollAmount float64
2526

2627
plugins []Plugin
2728
}
@@ -53,6 +54,7 @@ var defaultApplicationConfig = config{
5354
keyboardLayout: KeyboardQwertyLayout,
5455
windowMode: WindowModeDefault,
5556
windowAlwaysOnTop: false,
57+
scrollAmount: 100.0,
5658
}
5759

5860
// Option for Application
@@ -226,3 +228,10 @@ func VirtualKeyboardHide(hideCallback func()) Option {
226228
defaultTextinputPlugin.virtualKeyboardHide = hideCallback
227229
}
228230
}
231+
232+
// ScrollAmount sets the number of pixels to scroll with the mouse wheel
233+
func ScrollAmount(amount float64) Option {
234+
return func(c *config) {
235+
c.scrollAmount = amount
236+
}
237+
}

0 commit comments

Comments
 (0)