Class ColorTransition

java.lang.Object
limn.animation.ColorTransition

public final class ColorTransition extends Object
An animated Color: the color counterpart to Transition. It fades from the current color to a new target over a duration with an easing, so a widget can transition a fill/stroke/tint from a→b like a CSS color transition. Internally it drives a Transition for the 0→1 progress and blends with Color.lerp(limn.graphics.Color, float), so it inherits the same guarantees: it drives itself off the scene ticker only while moving, is UI-thread-confined, and snaps straight to the target when the owner is detached/headless or the animation is disabled.

 private final ColorTransition fill =
         new ColorTransition(this, Theme.current().primary)
                 .duration(Theme.current().animHover).easing(Theme.current().animEasing);
 // on state change:
 fill.to(hovered ? Theme.current().primaryHover : Theme.current().primary);
 // in onPaint:
 canvas.fillRoundRect(x, y, w, h, r, fill.value());
 
  • Constructor Details

    • ColorTransition

      public ColorTransition(Widget owner, Color initial)
      Rests at initial.
  • Method Details

    • duration

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

      public ColorTransition easing(Easing curve)
      The curve the interpolation follows.
    • enabled

      public ColorTransition enabled(boolean value)
      Turns animation off, so a new target takes effect on the next frame.
    • sceneTime

      public ColorTransition sceneTime(boolean value)
      See Transition.sceneTime(boolean). Off by default, like the transition it drives.
    • to

      public void to(Color target)
      Animates from the currently-shown color to target (snaps when detached/disabled).
    • snap

      public void snap(Color color)
      Jumps to color immediately, cancelling any animation.
    • value

      public Color value()
      Returns:
      the current interpolated color; read this each paint
    • target

      public Color target()
      Returns:
      the color it is heading toward
    • isAnimating

      public boolean isAnimating()
      Whether the colour is still moving towards its target.