Class SpringAnimation

All Implemented Interfaces:
Proxy

@Generated("org.javagi.JavaGI") public final class SpringAnimation extends Animation

A spring-based Animation.

AdwSpringAnimation implements an animation driven by a physical model of a spring described by SpringParams, with a resting position in SpringAnimation:value-to, stretched to SpringAnimation:value-from.

Since the animation is physically simulated, spring animations don't have a fixed duration. The animation will stop when the simulated spring comes to a rest - when the amplitude of the oscillations becomes smaller than SpringAnimation:epsilon, or immediately when it reaches SpringAnimation:value-to if SpringAnimation:clamp is set to TRUE. The estimated duration can be obtained with SpringAnimation:estimated-duration.

Due to the nature of spring-driven motion the animation can overshoot SpringAnimation:value-to before coming to a rest. Whether the animation will overshoot or not depends on the damping ratio of the spring. See SpringParams for more information about specific damping ratio values.

If SpringAnimation:clamp is TRUE, the animation will abruptly end as soon as it reaches the final value, preventing overshooting.

Animations can have an initial velocity value, set via SpringAnimation:initial-velocity, which adjusts the curve without changing the duration. This makes spring animations useful for deceleration at the end of gestures.

If the initial and final values are equal, and the initial velocity is not 0, the animation value will bounce and return to its resting position.

  • Constructor Details

    • SpringAnimation

      public SpringAnimation(MemorySegment address)
      Create a SpringAnimation instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • SpringAnimation

      public SpringAnimation(Widget widget, double from, double to, SpringParams springParams, AnimationTarget target)

      Creates a new AdwSpringAnimation on widget.

      The animation will animate target from from to to with the dynamics of a spring described by springParams.

      Parameters:
      widget - a widget to create animation on
      from - a value to animate from
      to - a value to animate to
      springParams - physical parameters of the spring
      target - a target value to animate
    • SpringAnimation

      public SpringAnimation()
      Create a new SpringAnimation.
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the SpringAnimation class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • asParent

      protected SpringAnimation asParent()
      Return this instance as if it were its parent type. Comparable to the Java super keyword, but ensures the parent typeclass is also used in native code.
      Overrides:
      asParent in class Animation
      Returns:
      the instance as if it were its parent type
    • calculateValue

      public double calculateValue(int time)

      Calculates the value this SpringAnimation will have at time.

      The time starts at 0 and ends at SpringAnimation:estimated_duration.

      See also calculateVelocity(int).

      Parameters:
      time - elapsed time, in milliseconds
      Returns:
      the value at time
      Since:
      1.3
    • calculateVelocity

      public double calculateVelocity(int time)

      Calculates the velocity this SpringAnimation will have at time.

      The time starts at 0 and ends at SpringAnimation:estimated_duration.

      See also calculateValue(int).

      Parameters:
      time - elapsed time, in milliseconds
      Returns:
      the velocity at time
      Since:
      1.3
    • getClamp

      public boolean getClamp()
      Gets whether this SpringAnimation should be clamped.
      Returns:
      whether this SpringAnimation is clamped
    • getEpsilon

      public double getEpsilon()
      Gets the precision of the spring.
      Returns:
      the epsilon value
    • getEstimatedDuration

      public int getEstimatedDuration()

      Gets the estimated duration of self, in milliseconds.

      Can be DURATION_INFINITE if the spring damping is set to 0.

      Returns:
      the estimated duration
    • getInitialVelocity

      public double getInitialVelocity()
      Gets the initial velocity of self.
      Returns:
      the initial velocity
    • getSpringParams

      public SpringParams getSpringParams()
      Gets the physical parameters of the spring of self.
      Returns:
      the spring parameters
    • getValueFrom

      public double getValueFrom()
      Gets the value this SpringAnimation will animate from.
      Returns:
      the value to animate from
    • getValueTo

      public double getValueTo()
      Gets the value this SpringAnimation will animate to.
      Returns:
      the value to animate to
    • getVelocity

      public double getVelocity()
      Gets the current velocity of self.
      Returns:
      the current velocity
    • setClamp

      public void setClamp(boolean clamp)

      Sets whether this SpringAnimation should be clamped.

      If set to TRUE, the animation will abruptly end as soon as it reaches the final value, preventing overshooting.

      It won't prevent overshooting SpringAnimation:value-from if a relative negative SpringAnimation:initial-velocity is set.

      Parameters:
      clamp - the new value
    • setEpsilon

      public void setEpsilon(double epsilon)

      Sets the precision of the spring.

      The level of precision used to determine when the animation has come to a rest, that is, when the amplitude of the oscillations becomes smaller than this value.

      If the epsilon value is too small, the animation will take a long time to stop after the animated value has stopped visibly changing.

      If the epsilon value is too large, the animation will end prematurely.

      The default value is 0.001.

      Parameters:
      epsilon - the new value
    • setInitialVelocity

      public void setInitialVelocity(double velocity)

      Sets the initial velocity of self.

      Initial velocity affects only the animation curve, but not its duration.

      Parameters:
      velocity - the initial velocity
    • setSpringParams

      public void setSpringParams(SpringParams springParams)
      Sets the physical parameters of the spring of self.
      Parameters:
      springParams - the new spring parameters
    • setValueFrom

      public void setValueFrom(double value)

      Sets the value this SpringAnimation will animate from.

      The animation will start at this value and end at SpringAnimation:value-to.

      Parameters:
      value - the value to animate from
    • setValueTo

      public void setValueTo(double value)

      Sets the value this SpringAnimation will animate to.

      The animation will start at SpringAnimation:value-from and end at this value.

      Parameters:
      value - the value to animate to
    • builder

      public static SpringAnimation.Builder<? extends SpringAnimation.Builder> builder()
      A SpringAnimation.Builder object constructs a SpringAnimation with the specified properties. Use the various set...() methods to set properties, and finish construction with SpringAnimation.Builder.build().
      Returns:
      the builder object