ScrollHandler

The ScrollHandler class manages scrolling behavior in UI elements, such as context menus, supporting mouse wheel and drag-based scrolling with momentum and bounds checking. This automatically handles smooth scrolling as seen in MinecraftSkin and ModernSkin.

Key Properties

  • scrollOffset: Current scroll position (clamped to 0 and maxScrollOffset).

  • scrollVelocity: Scroll speed for momentum effects.

  • maxScrollOffset: Maximum scrollable distance.

  • isDragging: Tracks drag state.

  • SCROLL_SPEED: Scroll sensitivity (default: 1).

Key Methods

  • updateScrollOffset(int): Updates offset with bounds checking and momentum.

  • mouseScrolled(double): Adjusts scrollVelocity for wheel scrolling.

  • startDragging(double), stopDragging(): Manages drag scrolling.

  • updateScrollPosition(double): Updates offset during dragging.

  • setScrollSpeed(double): Sets scroll sensitivity.

Negative maxScrollOffset is coerced to 0.

Last updated

Was this helpful?