Class SpringAnimation

All Implemented Interfaces:
PointerInterface

public class SpringAnimation extends Animation
A spring-based [class@Animation].

`AdwSpringAnimation` implements an animation driven by a physical model of a
spring described by [struct@SpringParams], with a resting position in
[property@SpringAnimation:value-to], stretched to
[property@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
[property@SpringAnimation:epsilon], or immediately when it reaches
[property@SpringAnimation:value-to] if
[property@SpringAnimation:clamp] is set to `TRUE`. The estimated duration can
be obtained with [property@SpringAnimation:estimated-duration].

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

If [property@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
[property@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.

https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.SpringAnimation.html

  • Constructor Details

    • SpringAnimation

      public SpringAnimation(PointerContainer pointer)
    • SpringAnimation

      public SpringAnimation(@Nonnull Widget widget, double from, double to, @Nonnull SpringParams spring_params, @Nonnull 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 @spring_params.
      Parameters:
      widget - a widget to create animation on
      from - a value to animate from
      to - a value to animate to
      spring_params - physical parameters of the spring
      target - a target value to animate
  • Method Details

    • getClassHandler

      public static ClassHandler getClassHandler()
    • getClamp

      public boolean getClamp()
      Gets whether @self should be clamped.
      Returns:
      whether @self 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.

      Can be [const@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 @self will animate from.
      Returns:
      the value to animate from
    • getValueTo

      public double getValueTo()
      Gets the value @self 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 @self 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 [property@SpringAnimation:value-from] if a
      relative negative [property@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(@Nonnull SpringParams spring_params)
      Sets the physical parameters of the spring of @self.
      Parameters:
      spring_params - the new spring parameters
    • setValueFrom

      public void setValueFrom(double value)
      Sets the value @self will animate from.

      The animation will start at this value and end at
      [property@SpringAnimation:value-to].
      Parameters:
      value - the value to animate from
    • setValueTo

      public void setValueTo(double value)
      Sets the value @self will animate to.

      The animation will start at [property@SpringAnimation:value-from] and end at
      this value.
      Parameters:
      value - the value to animate to
    • getTypeID

      public static long getTypeID()
    • getParentTypeID

      public static long getParentTypeID()
    • getTypeSize

      public static TypeSystem.TypeSize getTypeSize()
    • getParentTypeSize

      public static TypeSystem.TypeSize getParentTypeSize()
    • getInstanceSize

      public static int getInstanceSize()