Class Transition

java.lang.Object
limn.animation.Transition

public final class Transition extends Object
One animated float property: the toolkit's reusable "CSS transition". A widget owns a Transition per property it wants to animate (opacity, a fill level, a lerp factor, a position, …), configures it once, then just moves the target with to(float); value(), read each paint, eases toward it.

Like a CSS transition, the developer controls whether it animates (enabled), the duration, the easing curve and whether it repeats, for any property, since the value is just a number the widget maps onto whatever it draws.

Optimized: it drives itself off the scene's frame ticker only while moving and unregisters the instant it settles, so an idle widget costs nothing. Safe: to / snap(float) are UI-thread-confined, and when the owner has no scene (headless, or detached) it simply jumps to the target: the same "final state, no animation" a test or an off-screen widget wants.


 private final Transition fade = new Transition(this).duration(0.15).easing(Easing.EASE_OUT);
 // on state change:
 fade.to(visible ? 1 : 0);
 // in onPaint:
 color.withAlpha(fade.value());
 
  • Constructor Details

    • Transition

      public Transition(Widget owner)
      A transition starting (and resting) at 0.
    • Transition

      public Transition(Widget owner, float initial)
      A transition starting at initial, repainting owner as it runs.
  • Method Details

    • duration

      public Transition duration(double seconds)
      Sets the animation length in seconds (0 = no animation; to snaps).
    • easing

      public Transition easing(Easing curve)
      Sets the timing curve (default Easing.EASE_OUT).
    • enabled

      public Transition enabled(boolean value)
      When false, to jumps instead of animating (default true).
    • repeat

      public Transition repeat(boolean value)
      When true, the animation ping-pongs between its endpoints forever (a pulse/breathe) until snap(float) or repeat(false) stops it.
    • sceneTime

      public Transition sceneTime(boolean value)
      Whether this transition runs on the scene's scene time (and so obeys Scene.setPaused(boolean) and Scene.setTimeScale(double)) instead of wall time. Default false.

      The default is what every widget in the toolkit wants: a hover, focus or press fade is shell feedback, and feedback that stops responding while an app pauses its own animation reads as a hang, not as a pause. Turn it on for a transition that animates content (a game object's position, a value the simulation owns), which is exactly what pausing is supposed to stop.

      Read when the transition registers itself with the scene, so flipping it mid-animation takes effect on the next run rather than the current one.

    • duration

      public double duration()
      Duration of one run, in seconds.
    • isEnabled

      public boolean isEnabled()
      Whether animating at all; when off, the value jumps to its target.
    • repeats

      public boolean repeats()
      Whether the transition restarts on completion instead of settling.
    • to

      public void to(float target)
      Animates the value toward target. Jumps immediately (no animation) when disabled, zero-duration, or the owner is detached from a scene. UI thread.
    • snap

      public void snap(float value)
      Jumps to value immediately, cancelling any animation. UI thread.
    • value

      public float value()
      Returns:
      the current (eased) value; read this each paint
    • target

      public float target()
      Returns:
      the value it is heading toward
    • isAnimating

      public boolean isAnimating()
      Whether the value is still moving: false once it has settled on its target.