Class VFXScrollPaneBehavior
BehaviorBase and default behavior implementation for VFXScrollPane.
Most of the work related to scrolling is already handled by the scroll bars present in the VFXScrollPaneSkin.
This just implements the methods necessary to make the VFXScrollPane.dragToScrollProperty() feature work.
You can fine-tune the VFXScrollPane.dragSmoothScrollProperty() by changing the properties:
- SMOOTH_DRAG_SENSIBILITY (this is basically a multiplier to scroll more/less and make the smooth scroll
more significant)
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondoubleio.github.palexdev.mfxcore.base.beans.SizebooleanbooleanvoidkeyPressed(KeyEvent ke) Action performed whenKeyEvent.KEY_PRESSEDevents occurs.voidAction performed when aMouseEvent.MOUSE_DRAGGEDevent occurs.voidAction performed when aMouseEvent.MOUSE_PRESSEDevent occurs.voidAction performed when aMouseEvent.MOUSE_RELEASEDevent occurs.voidsetCanHScroll(boolean canHScroll) This is called by the default skin to make the behavior class aware of the horizontal scroll bar's visibility.voidsetCanVScroll(boolean canVScroll) This is called by the default skin to make the behavior class aware of the vertical scroll bar's visibility.voidsetDragThreshold(double dragThreshold) Sets the number of pixels that act as a threshold before the scroll happens on drag.voidsetViewportSize(io.github.palexdev.mfxcore.base.beans.Size viewportSize) This is called by the default skin to make the viewport's size available to the behavior.protected io.github.palexdev.mfxeffects.animations.MomentumTransitionwithMomentum(double delta) Convenience method to build aMomentumTransitionusingMomentumTransition.fromTime(double, double)with the given parameter.Methods inherited from class io.github.palexdev.mfxcore.behavior.BehaviorBase
dispose, getActions, getNode, init, keyPressed, keyReleased, keyReleased, keyTyped, keyTyped, mouseClicked, mouseClicked, mouseDragged, mouseEntered, mouseEntered, mouseExited, mouseExited, mouseMoved, mouseMoved, mousePressed, mouseReleased, register, scroll, scroll, touchMoved, touchMoved, touchPressed, touchPressed, touchReleased, touchReleased, touchStationary, touchStationary
-
Field Details
-
DRAG_SMOOTH_SCROLL_DURATION
-
DRAG_SMOOTH_SCROLL_CURVE
-
SMOOTH_DRAG_SENSIBILITY
protected double SMOOTH_DRAG_SENSIBILITY
-
-
Constructor Details
-
VFXScrollPaneBehavior
-
-
Method Details
-
withMomentum
protected io.github.palexdev.mfxeffects.animations.MomentumTransition withMomentum(double delta) Convenience method to build aMomentumTransitionusingMomentumTransition.fromTime(double, double)with the given parameter. UsesDRAG_SMOOTH_SCROLL_DURATIONas the duration andDRAG_SMOOTH_SCROLL_CURVEas the interpolator. -
mousePressed
Action performed when aMouseEvent.MOUSE_PRESSEDevent occurs. Stores both the mouse position and the scroll values which will be needed bymouseDragged(MouseEvent)to compute how much to scroll if the drag to scroll feature is active.- Overrides:
mousePressedin classio.github.palexdev.mfxcore.behavior.BehaviorBase<VFXScrollPane>
-
mouseDragged
Action performed when aMouseEvent.MOUSE_DRAGGEDevent occurs. Adjusts both the vertical or the horizontal scroll values according to the mouse movement, immediately via setters or with an animation (withMomentum(double)) if the "smooth drag to scroll feature" is active.There are several conditions that get checked here:
1) Exits if either the feature is off or the content is null
2) Does not allow diagonal scrolling for a more pleasant UX and so the dominant axis is determined by how much the mouse moved vertically and horizontally since the press of the mouse.
3) The scroll starts only after a certain threshold, by default 16px.
4) The scroll occurs only if the bar for the determined axis is visible. This is managed by the
The displacement is computed as follows:canVScrollandcanHScrollflags. The default skin does not allow the scroll when a bar is hidden, either because the content is smaller than the viewport on its axis or if the policies hide the bar.-
mouseX - dragStartXfor the horizontal axis-
Also, if the values are adjusted by animations, every time one is played themouseY - dragStartYfor the vertical axisdragStartpositions are updated for a better user experience.- Overrides:
mouseDraggedin classio.github.palexdev.mfxcore.behavior.BehaviorBase<VFXScrollPane>- See Also:
-
mouseReleased
Action performed when aMouseEvent.MOUSE_RELEASEDevent occurs. Resets the properties needed bymouseDragged(MouseEvent).- Overrides:
mouseReleasedin classio.github.palexdev.mfxcore.behavior.BehaviorBase<VFXScrollPane>
-
keyPressed
Action performed whenKeyEvent.KEY_PRESSEDevents occurs.- Overrides:
keyPressedin classio.github.palexdev.mfxcore.behavior.BehaviorBase<VFXScrollPane>
-
getViewportSize
public io.github.palexdev.mfxcore.base.beans.Size getViewportSize()- See Also:
-
setViewportSize
public void setViewportSize(io.github.palexdev.mfxcore.base.beans.Size viewportSize) This is called by the default skin to make the viewport's size available to the behavior. These values are important for the drag to scroll feature to work properly. -
isCanVScroll
public boolean isCanVScroll()- See Also:
-
setCanVScroll
public void setCanVScroll(boolean canVScroll) This is called by the default skin to make the behavior class aware of the vertical scroll bar's visibility. This information is important for the drag to scroll feature to work properly. -
isCanHScroll
public boolean isCanHScroll()- See Also:
-
setCanHScroll
public void setCanHScroll(boolean canHScroll) This is called by the default skin to make the behavior class aware of the horizontal scroll bar's visibility. This information is important for the drag to scroll feature to work properly. -
getDragThreshold
public double getDragThreshold()- See Also:
-
setDragThreshold
public void setDragThreshold(double dragThreshold) Sets the number of pixels that act as a threshold before the scroll happens on drag.- See Also:
-