Class SlideTransition

  • All Implemented Interfaces:
    Transition

    public class SlideTransition
    extends Object
    implements Transition
    A transition that slides the incoming content in from one edge of the content area.

    The outgoing content does not move: it is the frame left on the display, and a frame can only draw over it. The incoming content starts fully off the direction's edge and travels to its place, the travel being shaped by an easing Function (a quadratic ease-out by default).

    On a TransitionContext.BACK navigation the direction is mirrored by default, so going back undoes visually what going forward did. A constructor flag turns that off for an application that wants one fixed direction whatever the navigation.

    Since:
    0.2.0
    • Constructor Summary

      Constructors 
      Constructor Description
      SlideTransition()
      Creates a right-to-left slide with the default duration and easing, mirrored on back navigations.
      SlideTransition​(int direction)
      Creates a slide in the given direction with the default duration and easing, mirrored on back navigations.
      SlideTransition​(int direction, int duration)
      Creates a slide in the given direction with the given duration and the default easing, mirrored on back navigations.
      SlideTransition​(int direction, int duration, Function easing)
      Creates a slide in the given direction with the given duration and easing, mirrored on back navigations.
      SlideTransition​(int direction, int duration, Function easing, boolean mirrorOnBack)
      Creates a slide in the given direction with the given duration and easing, mirroring the direction on back navigations only if asked to.
    • Field Detail

      • RIGHT_TO_LEFT

        public static final int RIGHT_TO_LEFT
        Direction where the incoming content enters from the right edge.
        See Also:
        Constant Field Values
      • LEFT_TO_RIGHT

        public static final int LEFT_TO_RIGHT
        Direction where the incoming content enters from the left edge.
        See Also:
        Constant Field Values
      • BOTTOM_TO_TOP

        public static final int BOTTOM_TO_TOP
        Direction where the incoming content enters from the bottom edge.
        Since:
        2.0.0
        See Also:
        Constant Field Values
      • TOP_TO_BOTTOM

        public static final int TOP_TO_BOTTOM
        Direction where the incoming content enters from the top edge.
        Since:
        2.0.0
        See Also:
        Constant Field Values
    • Constructor Detail

      • SlideTransition

        public SlideTransition()
        Creates a right-to-left slide with the default duration and easing, mirrored on back navigations.
      • SlideTransition

        public SlideTransition​(int direction,
                               int duration)
        Creates a slide in the given direction with the given duration and the default easing, mirrored on back navigations.
        Parameters:
        direction - RIGHT_TO_LEFT, LEFT_TO_RIGHT, BOTTOM_TO_TOP, or TOP_TO_BOTTOM.
        duration - the slide duration, in milliseconds; must be strictly positive.
        Throws:
        IllegalArgumentException - if the given direction is none of the four, or if the given duration is not strictly positive.
      • SlideTransition

        public SlideTransition​(int direction,
                               int duration,
                               Function easing)
        Creates a slide in the given direction with the given duration and easing, mirrored on back navigations.
        Parameters:
        direction - RIGHT_TO_LEFT, LEFT_TO_RIGHT, BOTTOM_TO_TOP, or TOP_TO_BOTTOM.
        duration - the slide duration, in milliseconds; must be strictly positive.
        easing - the function shaping the travel over the duration.
        Throws:
        IllegalArgumentException - if the given direction is none of the four, or if the given duration is not strictly positive.
        Since:
        2.0.0
      • SlideTransition

        public SlideTransition​(int direction,
                               int duration,
                               Function easing,
                               boolean mirrorOnBack)
        Creates a slide in the given direction with the given duration and easing, mirroring the direction on back navigations only if asked to.
        Parameters:
        direction - RIGHT_TO_LEFT, LEFT_TO_RIGHT, BOTTOM_TO_TOP, or TOP_TO_BOTTOM.
        duration - the slide duration, in milliseconds; must be strictly positive.
        easing - the function shaping the travel over the duration.
        mirrorOnBack - true to mirror the direction on a TransitionContext.BACK navigation, false to always slide in the given direction.
        Throws:
        IllegalArgumentException - if the given direction is none of the four, or if the given duration is not strictly positive.
        Since:
        2.0.0
    • Method Detail

      • getDuration

        public int getDuration()
        Description copied from interface: Transition
        Returns how long this transition lasts, in milliseconds.

        A duration of 0 or less makes the page change instant: the navigator shows the incoming content immediately, without starting this transition and without drawing a single frame.

        Specified by:
        getDuration in interface Transition
        Returns:
        the duration in milliseconds.
      • start

        public void start​(TransitionContext context)
        Description copied from interface: Transition
        Prepares this transition for the page change described by the given context.

        Called once per navigation, before the first frame, and only when Transition.getDuration() is strictly positive. The incoming content is already captured, so an implementation may read the content area size and the navigation kind here. Nothing is drawn during this call.

        Specified by:
        start in interface Transition
        Parameters:
        context - the context of the page change about to be animated.
      • render

        public void render​(GraphicsContext g,
                           TransitionContext context,
                           float progress)
        Description copied from interface: Transition
        Draws one frame of this transition.

        The given graphics context is translated and clipped to the content area, and already holds the pixels of the previous frame — the outgoing content. An implementation draws the incoming content over them through the given context.

        Specified by:
        render in interface Transition
        Parameters:
        g - the graphics context to draw the frame with, translated and clipped to the content area.
        context - the context of the page change being animated.
        progress - how far the transition has advanced: the elapsed time divided by the duration, at least 0 and strictly less than 1.