Skip to main content

AnimationController

Struct AnimationController 

Source
pub struct AnimationController { /* private fields */ }
Expand description

时间驱动的动画控制器

纯逻辑:不持有时钟、不触发副作用。典型用法(runtime 侧):

ⓘ
let mut ctrl = AnimationController::new(3000)
    .with_curve(Curve::EaseInOut)
    .with_repeat(Repeat::Loop);
ctrl.forward(now_ms());
// 每帧:
if let TickOutcome::Value(t) = ctrl.tick(now_ms()) {
    hue.set(t);           // 响应式 → rebuild → 重画
    window.request_redraw();
}

value(now_ms) 是无状态查询(不推进 status),适合 hit_test / 立即绘制。

内部用 锚点模型:anchor_ms 时刻的线性进度为 anchor_progress, 之后按播放方向推进。forward/reverse 可在任意时刻无缝切换 (切换即重新锚定到当前进度),不依赖可回退的时钟。

Implementations§

Source§

impl AnimationController

Source

pub fn new(duration_ms: u64) -> Self

Source

pub fn with_curve(self, curve: Curve) -> Self

Source

pub fn with_repeat(self, repeat: Repeat) -> Self

Source

pub fn with_on_status_changed( self, cb: impl FnMut(AnimationStatus) + 'static, ) -> Self

Source

pub fn status(&self) -> AnimationStatus

Source

pub fn is_animating(&self) -> bool

是否在播放(AboutToWait 里决定要不要 request_redraw)

Source

pub fn curve(&self) -> Curve

Source

pub fn repeat(&self) -> Repeat

Source

pub fn duration_ms(&self) -> u64

Source

pub fn forward(&mut self, now_ms: u64)

从当前进度正向播放(Dismissed/Completed → 从 0 重新开始)

Source

pub fn reverse(&mut self, now_ms: u64)

从当前进度反向播放(Dismissed → 立即结束;Completed → 从 1 往回)

Source

pub fn stop(&mut self)

立即停止;tick 之后返回 Idle(value 冻结在当前端点语义)

Source

pub fn value(&self, now_ms: u64) -> f32

无状态查询当前插值(0..1,已过曲线;不播放时返回端点值)

Source

pub fn tick(&mut self, now_ms: u64) -> TickOutcome

推进状态机到 now_ms,返回本轮结果。

Trait Implementations§

Source§

impl Debug for AnimationController

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.