pub struct PropertyTransition<K: TransitionValueKind>{ /* private fields */ }Expand description
Tracks one visual property and starts a transition when its target value changes.
The first observed value becomes the stable target baseline and does not start an animation. Later different values register a two-keyframe animation from the previous visual result to the new target value.
use aura_anim_iced::{
AnimationRuntime, AnimationTargetId, Duration, OPACITY, PropertyTransition,
PropertyValue, Timing,
};
let mut runtime = AnimationRuntime::testing();
let target = AnimationTargetId::new();
let mut opacity = PropertyTransition::new(target, OPACITY)
.with_timing(Timing::new(100.0));
opacity.transition_to(&mut runtime, 0.0);
let first = opacity.transition_to(&mut runtime, 1.0).unwrap();
runtime.clock_mut().set_now(Duration::from_millis(40.0));
runtime.tick();
// Retargeting starts from the active animation's sampled visual value.
let retargeted = opacity.retarget_to(&mut runtime, 0.25).unwrap();
assert_eq!(retargeted.replaced(), Some(first.handle()));
let start = retargeted.registration().properties().unwrap();
let entry = start.find_property(&OPACITY.raw()).unwrap();
assert!(matches!(entry.value(), PropertyValue::Scalar(value) if (*value - 0.4).abs() < 0.001));Implementations§
Source§impl<K> PropertyTransition<K>
impl<K> PropertyTransition<K>
Sourcepub fn new(target: AnimationTargetId, property: PropertySpec<K>) -> Self
pub fn new(target: AnimationTargetId, property: PropertySpec<K>) -> Self
Creates a property transition tracker with default timing.
Sourcepub const fn from_rule(
target: AnimationTargetId,
rule: &BehaviorRule<K>,
) -> Self
pub const fn from_rule( target: AnimationTargetId, rule: &BehaviorRule<K>, ) -> Self
Creates a property transition tracker from a reusable behavior rule.
Sourcepub const fn with_timing(self, timing: Timing) -> Self
pub const fn with_timing(self, timing: Timing) -> Self
Replaces the timing used for newly registered transitions.
Sourcepub const fn target(&self) -> AnimationTargetId
pub const fn target(&self) -> AnimationTargetId
Returns the target that receives transition animations.
Sourcepub const fn property(&self) -> PropertySpec<K>
pub const fn property(&self) -> PropertySpec<K>
Returns the tracked property.
Sourcepub const fn current_value(&self) -> Option<K::Inner>
pub const fn current_value(&self) -> Option<K::Inner>
Returns the last target value observed by this tracker.
Sourcepub const fn active_handle(&self) -> Option<AnimationHandle>
pub const fn active_handle(&self) -> Option<AnimationHandle>
Returns the active runtime handle created by this tracker, if any.
Sourcepub fn is_active<C: AnimationClock>(
&self,
runtime: &AnimationRuntime<C>,
) -> bool
pub fn is_active<C: AnimationClock>( &self, runtime: &AnimationRuntime<C>, ) -> bool
Returns whether this tracker currently owns a runtime animation handle.
Sourcepub fn handle_completion<C: AnimationClock>(
&mut self,
runtime: &AnimationRuntime<C>,
) -> bool
pub fn handle_completion<C: AnimationClock>( &mut self, runtime: &AnimationRuntime<C>, ) -> bool
Clears this tracker’s active handle when it appears in completed output.
Returns true when this transition handled its own completion.
Sourcepub const fn active_transition(&self) -> Option<&ActivePropertyTransition<K>>
pub const fn active_transition(&self) -> Option<&ActivePropertyTransition<K>>
Returns metadata for the active property transition, if any.
Sourcepub fn active_progress_at(
&self,
timestamp: Duration,
) -> Option<PropertyTransitionProgress<K>>
pub fn active_progress_at( &self, timestamp: Duration, ) -> Option<PropertyTransitionProgress<K>>
Returns sampled progress for the active transition at timestamp.
Sourcepub fn transition_to<C: AnimationClock>(
&mut self,
runtime: &mut AnimationRuntime<C>,
value: K::Inner,
) -> Option<PropertyTransitionRegistration>
pub fn transition_to<C: AnimationClock>( &mut self, runtime: &mut AnimationRuntime<C>, value: K::Inner, ) -> Option<PropertyTransitionRegistration>
Observes a new target value and registers an animation when it changed.
Returns None when the value only seeded the baseline or did not change.
If a previous transition is still running, the replacement starts from
that transition’s last sampled visual value.
Sourcepub fn transition_from_visual<C: AnimationClock>(
&mut self,
runtime: &mut AnimationRuntime<C>,
visual: K::Inner,
value: K::Inner,
) -> Option<PropertyTransitionRegistration>
pub fn transition_from_visual<C: AnimationClock>( &mut self, runtime: &mut AnimationRuntime<C>, visual: K::Inner, value: K::Inner, ) -> Option<PropertyTransitionRegistration>
Observes a new target value with an explicit current visual value.
This is useful when application code already stores the rendered value
from the latest tick. The registered animation starts from visual
even if the previous target or runtime handle no longer represents what
is currently on screen.
Sourcepub fn retarget_to<C: AnimationClock>(
&mut self,
runtime: &mut AnimationRuntime<C>,
value: K::Inner,
) -> Option<PropertyTransitionRegistration>
pub fn retarget_to<C: AnimationClock>( &mut self, runtime: &mut AnimationRuntime<C>, value: K::Inner, ) -> Option<PropertyTransitionRegistration>
Retargets a currently running transition to a new destination.
Returns None when there is no active runtime animation, the active
handle is stale, or the new destination is already the current target.
The replacement animation starts from the active animation’s last
sampled visual value.
Sourcepub fn interrupt_from_visual<C: AnimationClock>(
&mut self,
runtime: &mut AnimationRuntime<C>,
visual: K::Inner,
value: K::Inner,
) -> Option<PropertyTransitionRegistration>
pub fn interrupt_from_visual<C: AnimationClock>( &mut self, runtime: &mut AnimationRuntime<C>, visual: K::Inner, value: K::Inner, ) -> Option<PropertyTransitionRegistration>
Interrupts the current transition and continues from an explicit visual value.
Unlike transition_from_visual, this
method can replace an active animation even when value is already the
current target. This is useful when an external interaction interrupts
playback and application code wants the replacement animation to start
from the exact value currently rendered on screen.
Trait Implementations§
Source§impl<K: Clone + TransitionValueKind> Clone for PropertyTransition<K>
impl<K: Clone + TransitionValueKind> Clone for PropertyTransition<K>
Source§fn clone(&self) -> PropertyTransition<K>
fn clone(&self) -> PropertyTransition<K>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<K: Debug + TransitionValueKind> Debug for PropertyTransition<K>
impl<K: Debug + TransitionValueKind> Debug for PropertyTransition<K>
Source§impl<K: PartialEq + TransitionValueKind> PartialEq for PropertyTransition<K>
impl<K: PartialEq + TransitionValueKind> PartialEq for PropertyTransition<K>
Source§fn eq(&self, other: &PropertyTransition<K>) -> bool
fn eq(&self, other: &PropertyTransition<K>) -> bool
self and other values to be equal, and is used by ==.impl<K: TransitionValueKind> StructuralPartialEq for PropertyTransition<K>
Auto Trait Implementations§
impl<K> Freeze for PropertyTransition<K>
impl<K> RefUnwindSafe for PropertyTransition<K>
impl<K> Send for PropertyTransition<K>
impl<K> Sync for PropertyTransition<K>
impl<K> Unpin for PropertyTransition<K>
impl<K> UnsafeUnpin for PropertyTransition<K>
impl<K> UnwindSafe for PropertyTransition<K>
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.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<State, Message> IntoBoot<State, Message> for State
impl<State, Message> IntoBoot<State, Message> for State
Source§fn into_boot(self) -> (State, Task<Message>)
fn into_boot(self) -> (State, Task<Message>)
Application.