MCPcopy
hub / github.com/g3n/engine / onScroll

Method onScroll

gui/scroller.go:277–313  ·  view source on GitHub ↗

onScroll receives mouse scroll events when this scroller has the scroll focus (set by OnMouseEnter)

(evname string, ev interface{})

Source from the content-addressed store, hash-verified

275
276// onScroll receives mouse scroll events when this scroller has the scroll focus (set by OnMouseEnter)
277func (s *Scroller) onScroll(evname string, ev interface{}) {
278
279 sev := ev.(*window.ScrollEvent)
280
281 vScrollVisible := (s.vscroll != nil) && s.vscroll.Visible()
282 hScrollVisible := (s.hscroll != nil) && s.hscroll.Visible()
283
284 mult := float32(1) / float32(10)
285 offsetX := sev.Xoffset * mult
286 offsetY := sev.Yoffset * mult
287
288 // If modifier key is pressed (left shift by default) - then scroll in the horizontal direction
289 if sev.Mods&ScrollModifierKey > 0 {
290 if math32.Abs(offsetY) > math32.Abs(offsetX) {
291 offsetX = offsetY
292 }
293 offsetY = 0
294 }
295
296 log.Error("X: %v, Y: %v", offsetX, offsetY)
297
298 if vScrollVisible {
299 if hScrollVisible {
300 // Both scrollbars are present - scroll both
301 s.vscroll.SetValue(float32(s.vscroll.Value()) - offsetY)
302 s.hscroll.SetValue(float32(s.hscroll.Value()) - offsetX)
303 } else {
304 // Only vertical scrollbar present - scroll it
305 s.vscroll.SetValue(float32(s.vscroll.Value()) - offsetY)
306 }
307 } else if hScrollVisible {
308 // Only horizontal scrollbar present - scroll it
309 s.hscroll.SetValue(float32(s.hscroll.Value()) - offsetX)
310 }
311
312 s.recalc()
313}
314
315// onResize receives resize events
316func (s *Scroller) onResize(evname string, ev interface{}) {

Callers

nothing calls this directly

Calls 6

recalcMethod · 0.95
AbsFunction · 0.92
ErrorMethod · 0.80
VisibleMethod · 0.65
SetValueMethod · 0.45
ValueMethod · 0.45

Tested by

no test coverage detected