Class SpringAnimation
- All Implemented Interfaces:
Proxy
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.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
SpringAnimation.Builder<B extends SpringAnimation.Builder<B>>
Inner class implementing a builder pattern to construct a GObject with properties.static class
Nested classes/interfaces inherited from class org.gnome.adw.Animation
Animation.AnimationClass, Animation.AnimationImpl, Animation.DoneCallback
Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass
-
Constructor Summary
ConstructorDescriptionSpringAnimation
(MemorySegment address) Create a SpringAnimation proxy instance for the provided memory address.SpringAnimation
(Widget widget, double from, double to, SpringParams springParams, AnimationTarget target) Creates a newAdwSpringAnimation
onwidget
. -
Method Summary
Modifier and TypeMethodDescriptionprotected SpringAnimation
asParent()
Returns this instance as if it were its parent type.static SpringAnimation.Builder
<? extends SpringAnimation.Builder> builder()
ASpringAnimation.Builder
object constructs aSpringAnimation
with the specified properties.double
calculateValue
(int time) Calculates the value this SpringAnimation will have attime
.double
calculateVelocity
(int time) Calculates the velocity this SpringAnimation will have attime
.boolean
getClamp()
Gets whether this SpringAnimation should be clamped.double
Gets the precision of the spring.int
Gets the estimated duration of this SpringAnimation, in milliseconds.double
Gets the initial velocity of this SpringAnimation.Gets the physical parameters of the spring of this SpringAnimation.static Type
getType()
Get the GType of the SpringAnimation classdouble
Gets the value this SpringAnimation will animate from.double
Gets the value this SpringAnimation will animate to.double
Gets the current velocity of this SpringAnimation.void
setClamp
(boolean clamp) Sets whether this SpringAnimation should be clamped.void
setEpsilon
(double epsilon) Sets the precision of the spring.void
setInitialVelocity
(double velocity) Sets the initial velocity of this SpringAnimation.void
setSpringParams
(SpringParams springParams) Sets the physical parameters of the spring of this SpringAnimation.void
setValueFrom
(double value) Sets the value this SpringAnimation will animate from.void
setValueTo
(double value) Sets the value this SpringAnimation will animate to.Methods inherited from class org.gnome.adw.Animation
emitDone, getFollowEnableAnimationsSetting, getMemoryLayout, getState, getTarget, getValue, getWidget, onDone, pause, play, reset, resume, setFollowEnableAnimationsSetting, setTarget, skip
Methods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newInstance, newInstance, newv, notify_, notify_, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withProperties
Methods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, getPrivate, readGClass, writeGClass
Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
SpringAnimation
Create a SpringAnimation proxy 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 newAdwSpringAnimation
onwidget
.The animation will animate
target
fromfrom
toto
with the dynamics of a spring described byspringParams
.- Parameters:
widget
- a widget to create animation onfrom
- a value to animate fromto
- a value to animate tospringParams
- physical parameters of the springtarget
- a target value to animate
-
-
Method Details
-
getType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuper
keyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()
doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName()
. This will call the native function pointer of this virtual method in the typeclass of the parent type. -
calculateValue
public double calculateValue(int time) Calculates the value this SpringAnimation will have attime
.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
-
calculateVelocity
public double calculateVelocity(int time) Calculates the velocity this SpringAnimation will have attime
.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
-
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 this SpringAnimation, 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 this SpringAnimation.- Returns:
- the initial velocity
-
getSpringParams
Gets the physical parameters of the spring of this SpringAnimation.- 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 this SpringAnimation.- 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 negativeSpringAnimation: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 this SpringAnimation.Initial velocity affects only the animation curve, but not its duration.
- Parameters:
velocity
- the initial velocity
-
setSpringParams
Sets the physical parameters of the spring of this SpringAnimation.- 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
ASpringAnimation.Builder
object constructs aSpringAnimation
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withSpringAnimation.Builder.build()
.
-