pub struct AnimatorStates(pub HashMap<String, AnimatorState>);
Expand description
The current state of animations in a component
The AnimatorStates
can be accessed from the WidgetContext
to get information about the
current state of all component animations.
§Example
fn my_widget(context: WidgetContext) -> WidgetNode {
// Get the animator from our context
let WidgetContext { animator, .. } = context;
// Create the properties for a size box
let size_box_props = Props::new(SizeBoxProps {
transform: Transform {
// Get the `scale` value of the `my_anim` animation or and
// scale our button based on the animation progress
scale: Vec2::from(animator.value_progress_factor_or("my_anim", "scale", 1.)),
..Default::default()
},
..Default::default()
});
// Wrap our button in our animated size box
widget! { (size_box: {size_box_props} {
content = (my_button)
}) }
}
§Animations & Values
A component may have any number of different animations identified by a string anim_id
.
Additionally each animation can have more than one value that is animated and each of these
values has a value_name
that can be used to get the animated value.
Tuple Fields§
§0: HashMap<String, AnimatorState>
Implementations§
Source§impl AnimatorStates
impl AnimatorStates
Sourcepub fn in_progress(&self) -> bool
pub fn in_progress(&self) -> bool
Returns whether or not any of the animations for this component are in-progress
Sourcepub fn is_done(&self) -> bool
pub fn is_done(&self) -> bool
Returns true
if none of this component’s animations are currently running
Sourcepub fn has(&self, anim_id: &str) -> bool
pub fn has(&self, anim_id: &str) -> bool
Returns true if the widget has an animation with the given anim_id
Sourcepub fn value_progress(
&self,
anim_id: &str,
value_name: &str,
) -> Option<AnimatedValueProgress>
pub fn value_progress( &self, anim_id: &str, value_name: &str, ) -> Option<AnimatedValueProgress>
Get the current progress of the animation of a given value
This will return None
if the value is not currently being animated.
Sourcepub fn value_progress_factor_or(
&self,
anim_id: &str,
value_name: &str,
default: f32,
) -> f32
pub fn value_progress_factor_or( &self, anim_id: &str, value_name: &str, default: f32, ) -> f32
Same as value_progress_factor
but returning default
instead of None
Sourcepub fn value_progress_factor_or_zero(
&self,
anim_id: &str,
value_name: &str,
) -> f32
pub fn value_progress_factor_or_zero( &self, anim_id: &str, value_name: &str, ) -> f32
Same as value_progress_factor
but returning 0
instead of None
Trait Implementations§
Source§impl Clone for AnimatorStates
impl Clone for AnimatorStates
Source§fn clone(&self) -> AnimatorStates
fn clone(&self) -> AnimatorStates
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more