Trait mina::StateAnimator
source · pub trait StateAnimator {
type State;
type Values;
// Required methods
fn advance(&mut self, elapsed_seconds: f32);
fn current_state(&self) -> &Self::State;
fn current_values(&self) -> &Self::Values;
fn set_state(&mut self, state: &Self::State);
}Expand description
Animates a collection of values over time, automatically selecting the correct animation based on current state and blending with any previous animation still in progress.
To create a StateAnimator, use the StateAnimatorBuilder helper.
Animator vs. Timeline
Timelines are stateless types that represent a single animation and are able to query the
animated values at any given point in time. They are generally only useful for non-interactive
scenarios, coordinating many related animations, etc. Typically, a timeline might be defined as
a shared resource and used many times throughout an app.
StateAnimators encapsulate an entire animated “component”, including both the animation
definitions (timelines) and the current animator values, e.g. the “style”. If there are many
animatable widgets in a UI, each one of those widgets will have its own animator. Animators are
more opinionated than timelines, but also model transitions between timelines and the states
that trigger them.
Required Associated Types§
sourcetype State
type State
State enum that determines which animation to play. Most often this describes the state of
user interaction and includes values such as MouseOver, MouseDown, etc.
sourcetype Values
type Values
Target values animated by this type, i.e. the “Style” of the component being animated.
Typical fields might include a transform (x, y, scale, etc.), colors or alpha
values, or anything else that describes the visual appearance.
Any type supported by a Timeline may be used, but in practice this should almost always
be a struct decorated with the Animate macro.
Required Methods§
sourcefn advance(&mut self, elapsed_seconds: f32)
fn advance(&mut self, elapsed_seconds: f32)
Advances whichever animation is currently playing by elapsed_seconds (time since the most
recent update).
If the current animation has ended and does not repeat, this has no effect.
sourcefn current_state(&self) -> &Self::State
fn current_state(&self) -> &Self::State
Gets the current state of the animator.
sourcefn current_values(&self) -> &Self::Values
fn current_values(&self) -> &Self::Values
Gets a reference to the current values, corresponding to the current State and current
position on the timeline for that state.
sourcefn set_state(&mut self, state: &Self::State)
fn set_state(&mut self, state: &Self::State)
Transitions to a new state.
This has no immediate effect on the current_values, but will start
to take effect on the next advance. As time elapses, the values will
gradually animate from where they were before set_state to where they should be at the
first keyframe (excluding any keyframe at 0%) of the Timeline configured for the new
state. Afterward, they will follow the normal timeline for that state.
If the current state is already equal to state, this is ignored. If the state has changed,
but the new state does not have any associated timeline, then the previous animation will
be stopped but the values will not be changed.