Class ScrollUtils
java.lang.Object
io.github.palexdev.virtualizedfx.utils.ScrollUtils
Utility class for ScrollPanes and MFXFlowlessListViews.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic ScrollUtils.ScrollDirection
determineScrollDirection(ScrollEvent event)
Determines the scroll direction of the given ScrollEvent.static boolean
isTrackPad(ScrollEvent event, ScrollUtils.ScrollDirection scrollDirection)
Determines if the given ScrollEvent comes from a trackpad.
-
Method Details
-
isTrackPad
Determines if the given ScrollEvent comes from a trackpad. Although this method works in most cases, it is not very accurate. Since in JavaFX there's no way to tell if a ScrollEvent comes from a trackpad or a mouse we use this trick: I noticed that a mouse scroll has a delta of 32 (don't know if it changes depending on the device or OS) and trackpad scrolls have a way smaller delta. So depending on the scroll direction we check if the delta is lesser than 10 (trackpad event) or greater(mouse event).- See Also:
ScrollEvent.getDeltaX()
,ScrollEvent.getDeltaY()
-
determineScrollDirection
Determines the scroll direction of the given ScrollEvent. Although this method works fine, it is not very accurate. In JavaFX there's no concept of scroll direction, if you try to scroll with a trackpad you'll notice that you can scroll in both directions at the same time, both deltaX and deltaY won't be 0. For this method to work we assume that this behavior is not possible. If deltaY is 0 we return LEFT or RIGHT depending on deltaX (respectively if lesser or greater than 0).Else we return DOWN or UP depending on deltaY (respectively if lesser or greater than 0).
- See Also:
ScrollEvent.getDeltaX()
,ScrollEvent.getDeltaY()
-