pub struct AnimatedValue { /* private fields */ }Expand description
An animated value that automatically registers with the scheduler
When the target changes, the value smoothly animates to it using spring physics. The animation is automatically registered with the scheduler and ticked each frame.
§Example
// Create an animated value (auto-registers with scheduler)
let opacity = AnimatedValue::new(ctx.animation_handle(), 1.0, SpringConfig::stiff());
// Change target - automatically animates
opacity.set_target(0.5);
// Get current animated value (interpolated)
let current = opacity.get();Implementations§
Source§impl AnimatedValue
impl AnimatedValue
Sourcepub fn new(
handle: SchedulerHandle,
initial: f32,
config: SpringConfig,
) -> AnimatedValue
pub fn new( handle: SchedulerHandle, initial: f32, config: SpringConfig, ) -> AnimatedValue
Create a new animated value with the given initial value
Sourcepub fn with_default(handle: SchedulerHandle, initial: f32) -> AnimatedValue
pub fn with_default(handle: SchedulerHandle, initial: f32) -> AnimatedValue
Create with default spring config (stiff)
Sourcepub fn set_target(&mut self, target: f32)
pub fn set_target(&mut self, target: f32)
Set the target value - starts animation if different from current
Sourcepub fn set_immediate(&mut self, value: f32)
pub fn set_immediate(&mut self, value: f32)
Set value immediately without animation
Sourcepub fn is_animating(&self) -> bool
pub fn is_animating(&self) -> bool
Check if currently animating
Returns true only while the spring is actively moving toward its target.
Once the spring has settled (reached target with near-zero velocity), this
returns false.
Sourcepub fn snap_to_target(&mut self)
pub fn snap_to_target(&mut self)
Snap immediately to the target value, stopping any active animation
This removes the spring entirely and sets the current value to the target. Useful for immediately completing an animation.
Trait Implementations§
Source§impl Clone for AnimatedValue
impl Clone for AnimatedValue
Source§fn clone(&self) -> AnimatedValue
fn clone(&self) -> AnimatedValue
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for AnimatedValue
impl RefUnwindSafe for AnimatedValue
impl Send for AnimatedValue
impl Sync for AnimatedValue
impl Unpin for AnimatedValue
impl UnsafeUnpin for AnimatedValue
impl UnwindSafe for AnimatedValue
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§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.