Class VFXScrollBarBehavior
BehaviorBase and default behavior implementation for VFXScrollBar.
This offers all the methods to manage scrolling and smooth scrolling, track press/release,
buttons press/release, thumb press/drag/release. And a bunch of other misc methods.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Interpolatorprotected Durationprotected Durationprotected Durationprotected Interpolatorprotected Durationprotected Duration -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidbuttonPressed(MouseEvent me, int mul) Action performed when either the increase or decrease buttons are pressed.voidAction performed when either the increase or decrease buttons are released.voiddispose()protected AnimationfirstTick(double targetVal) Convenience method to build aTimelineanimation for the "first tick".protected intgetAndSetScrollDirection(boolean incrementing) protected doubleObtains the mouse position from the givenMouseEventdepending on the scroll bar's orientation.protected doubleObtains the scroll delta from the givenScrollEventdepending on the scroll bar's orientation.protected doubleRetrieves the scroll bar's track length from the givenMouseEvent.protected voidonDragging(boolean dragging) Simply enables or disabled the ":dragging"PseudoClasson the scroll bar depending on the given parameter.protected AnimationonHold(EventHandler<ActionEvent> handler) Convenience method to build aPauseTransitionused to detect "mouse hold" events.protected voidRequests focus for the scroll bar if it's not already focused and if it's focus traversable.voidscroll(ScrollEvent se, Consumer<ScrollEvent> callback) Action performed when aScrollEventoccurs.protected voidStops any currently playing animation, including smooth scroll animations, hold animation (those responsible for detecting mouse press and hold), and any other scroll animation (typically the ones created inside hold animations)voidAction performed when the thumb is being dragged.voidAction performed when the thumb is pressed.voidAction performed when the thumb is released.voidAction performed when the track is pressed.voidAction performed when the track is releasedprotected io.github.palexdev.mfxeffects.animations.MomentumTransitionwithMomentum(double delta, Duration duration) Convenience method to build aMomentumTransitionusingMomentumTransition.fromTime(double, double)with the two given parameters.Methods inherited from class io.github.palexdev.mfxcore.behavior.BehaviorBase
getActions, getNode, init, keyPressed, keyPressed, keyReleased, keyReleased, keyTyped, keyTyped, mouseClicked, mouseClicked, mouseDragged, mouseDragged, mouseEntered, mouseEntered, mouseExited, mouseExited, mouseMoved, mouseMoved, mousePressed, mousePressed, mouseReleased, mouseReleased, register, scroll, touchMoved, touchMoved, touchPressed, touchPressed, touchReleased, touchReleased, touchStationary, touchStationary
-
Field Details
-
FIRST_TICK_DURATION
-
FIRST_TICK_CURVE
-
SMOOTH_SCROLL_DURATION
-
TRACK_SMOOTH_SCROLL_DURATION
-
SMOOTH_SCROLL_CURVE
-
MAX_BUTTONS_SCROLL_DURATION
-
HOLD_DELAY
-
-
Constructor Details
-
VFXScrollBarBehavior
-
-
Method Details
-
thumbPressed
Action performed when the thumb is pressed. The first steps are to stop any animation (seestopAnimations()) thenrequestFocus()and update thedragStartposition usinggetMousePos(MouseEvent), in case the next user action is dragging the thumb. -
thumbDragged
Action performed when the thumb is being dragged. First we callonDragging(boolean). Then we acquire the mouse position withgetMousePos(MouseEvent)to compute the traveled distance since the press event ascurrentPos - dragStart.We convert the traveled distance to the corresponding delta value by using
NumberUtils.mapOneRangeToAnother(double, DoubleRange, DoubleRange). A call togetAndSetScrollDirection(boolean)updates theVFXScrollBar.scrollDirectionProperty()and returns a multiplier (1 or -1) used to adjust the scroll bar's value by the found delta value:bar.setValue(bar.getValue() + deltaVal * mul). -
thumbReleased
Action performed when the thumb is released. The dragStart position is reset to 0.0, and the dragging property set to false. -
onDragging
protected void onDragging(boolean dragging) Simply enables or disabled the ":dragging"PseudoClasson the scroll bar depending on the given parameter. -
trackPressed
Action performed when the track is pressed. The first steps are to stop any animation (seestopAnimations()) thenrequestFocus(). Then we check whether smooth scroll and track smooth scroll features have been enabled, in such case the method exists as the scroll will be handled bytrackReleased(MouseEvent). Otherwise, we get the mouse position withgetMousePos(MouseEvent)and the track length withgetTrackLength(MouseEvent). We define the target value asmousePos / trackLand the delta value astargetVal - bar.getValue(). Finally, the scroll direction is determined bygetAndSetScrollDirection(boolean). At this point, two animations are built:The first animation is responsible for the "first tick". When you press the track you expect the thumb to move towards the mouse position by the specified
Both the second animation and the innerVFXScrollBar.trackIncrementProperty(). Then we must also consider what happens when the value has been adjusted, but the mouse is still pressed. Here's when the second animation comes into play. This animation basically detects if the mouse is still pressed (the delay is specified byHOLD_DELAY) and makes the thumb reposition towards the mouse position with aMomentumTransition. Before doing so, of course, it checks if the thumb is already at the mouse position or beyond, in such cases it simply does nothing.MomentumTransitionare assigned to variables so that if any event occurs in the meanwhile which requires the animations to stop it can be done. -
trackReleased
Action performed when the track is released The first step is to stop any animation (seestopAnimations()).The rest of the method executes only if both the smooth scroll and track smooth scroll features are enabled.
As usual,we get the mouse position with
getMousePos(MouseEvent)and the track length withgetTrackLength(MouseEvent). We define the target value asmousePos / trackLand the delta value astargetVal - bar.getValue(). Finally, the scroll direction is determined bygetAndSetScrollDirection(boolean).The scroll bar's value is adjusted with a
MomentumTransition. -
getTrackLength
Retrieves the scroll bar's track length from the givenMouseEvent. This can be done on events intercepted by the track because we get the node thanks toPickResult.getIntersectedNode(). The returned value depends on the orientation. -
buttonPressed
Action performed when either the increase or decrease buttons are pressed. Themulparameters indicates which one is pressed and therefore whether to increment (1) or decrement(-1) theVFXScrollBar.valueProperty()by the amount specified by theVFXScrollBar.unitIncrementProperty(). The first step is to stop any animation (seestopAnimations()) and to acquire focus withrequestFocus().Two animations are built:
The first animation is responsible for the "first tick". When you press the button you expect the thumb to move by the specified
VFXScrollBar.unitIncrementProperty(). Then we must also consider what happens when the value has been adjusted, but the mouse is still pressed. Here's when the second animation comes into play. It basically detects if the mouse is being hold (the delay is specified byHOLD_DELAY) and makes the thumb reposition with aConsumerTransition. -
buttonReleased
Action performed when either the increase or decrease buttons are released.Simply calls
stopAnimations(). -
getMousePos
Obtains the mouse position from the givenMouseEventdepending on the scroll bar's orientation. -
getAndSetScrollDirection
protected int getAndSetScrollDirection(boolean incrementing) -
getScrollDelta
Obtains the scroll delta from the givenScrollEventdepending on the scroll bar's orientation. -
requestFocus
protected void requestFocus()Requests focus for the scroll bar if it's not already focused and if it's focus traversable. -
stopAnimations
protected void stopAnimations()Stops any currently playing animation, including smooth scroll animations, hold animation (those responsible for detecting mouse press and hold), and any other scroll animation (typically the ones created inside hold animations) -
firstTick
Convenience method to build aTimelineanimation for the "first tick". UsesFIRST_TICK_DURATIONandFIRST_TICK_CURVEand moves the scroll bar's value towards the given target value. -
onHold
Convenience method to build aPauseTransitionused to detect "mouse hold" events. The duration is set toHOLD_DELAYand the given handler determines what happens when the animation ends. -
withMomentum
protected io.github.palexdev.mfxeffects.animations.MomentumTransition withMomentum(double delta, Duration duration) Convenience method to build aMomentumTransitionusingMomentumTransition.fromTime(double, double)with the two given parameters. UsesSMOOTH_SCROLL_CURVEas the interpolator. -
scroll
Action performed when aScrollEventoccurs. First the scroll delta is computed withgetScrollDelta(ScrollEvent)and in case it's 0 it immediately exits.Then we determine the scroll direction with
getAndSetScrollDirection(boolean)and depending on theVFXScrollBar.smoothScrollProperty()the scroll value is adjuster either by aMomentumTransitionor by the setter.- Overrides:
scrollin classio.github.palexdev.mfxcore.behavior.BehaviorBase<VFXScrollBar>
-
dispose
public void dispose()- Overrides:
disposein classio.github.palexdev.mfxcore.behavior.BehaviorBase<VFXScrollBar>
-