pub struct Motion<T> { /* private fields */ }Expand description
A value the runtime animates for a widget.
Start a transition with ctx.animate(&mut motion, target, spec) and read
the value while painting with motion.get(ctx). The runtime invalidates the
widget every frame until the transition ends, so the widget needs no
animation-frame handling of its own. The value is a function of time, so
reading it at a frame’s time gives what is on screen then.
Transitions follow the MotionPolicy; retargeting mid-flight keeps
momentum (see MotionValue).
Implementations§
Source§impl<T: Copy> Motion<T>
impl<T: Copy> Motion<T>
pub const fn new(value: T) -> Self
Sourcepub const fn invalidating(self, kind: InvalidationKind) -> Self
pub const fn invalidating(self, kind: InvalidationKind) -> Self
What the runtime invalidates each frame while this animates: Paint
(the default) for values read while painting, Transform or Effect
for layer properties, Measure for sizes.
Sourcepub const fn movement(self) -> Self
pub const fn movement(self) -> Self
Mark this as movement, such as a sliding indicator: reduced motion finishes it immediately instead of animating it.
pub const fn invalidation(&self) -> InvalidationKind
pub const fn is_movement(&self) -> bool
Source§impl<T> Motion<T>
impl<T> Motion<T>
Sourcepub fn get(&self, clock: &impl FrameClock) -> T
pub fn get(&self, clock: &impl FrameClock) -> T
The value at the time of the frame clock is producing.
Sourcepub fn is_animating(&self, clock: &impl FrameClock) -> bool
pub fn is_animating(&self, clock: &impl FrameClock) -> bool
Whether a transition is running at the time of clock’s frame.
Sourcepub fn start(
&mut self,
target: T,
time: f64,
spec: AnimationSpec,
) -> Option<f64>
pub fn start( &mut self, target: T, time: f64, spec: AnimationSpec, ) -> Option<f64>
Start toward target at time with spec under the motion policy.
Returns when the transition ends if one started. Contexts’ animate
methods call this and keep the widget invalidated until then.
Sourcepub fn start_after(
&mut self,
target: T,
time: f64,
delay: f64,
spec: AnimationSpec,
) -> Option<f64>
pub fn start_after( &mut self, target: T, time: f64, delay: f64, spec: AnimationSpec, ) -> Option<f64>
Like Motion::start, delay seconds after time. The delay
follows the policy’s time scale, and is skipped when the policy makes
the transition instant.