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
make_widget!(size_box)
.merge_props(size_box_props)
.named_slot("content", make_widget!(my_button))
.into()
}
§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: Scalar,
) -> Scalar
pub fn value_progress_factor_or( &self, anim_id: &str, value_name: &str, default: Scalar, ) -> Scalar
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,
) -> Scalar
pub fn value_progress_factor_or_zero( &self, anim_id: &str, value_name: &str, ) -> Scalar
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 moresource§impl Debug for AnimatorStates
impl Debug for AnimatorStates
source§impl Default for AnimatorStates
impl Default for AnimatorStates
source§fn default() -> AnimatorStates
fn default() -> AnimatorStates
source§impl<'de> Deserialize<'de> for AnimatorStates
impl<'de> Deserialize<'de> for AnimatorStates
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for AnimatorStates
impl RefUnwindSafe for AnimatorStates
impl Send for AnimatorStates
impl Sync for AnimatorStates
impl Unpin for AnimatorStates
impl UnwindSafe for AnimatorStates
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)