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
impl AnimationController
pub fn new(duration_ms: u64) -> Self
pub fn with_curve(self, curve: Curve) -> Self
pub fn with_repeat(self, repeat: Repeat) -> Self
pub fn with_on_status_changed( self, cb: impl FnMut(AnimationStatus) + 'static, ) -> Self
pub fn status(&self) -> AnimationStatus
Sourcepub fn is_animating(&self) -> bool
pub fn is_animating(&self) -> bool
是否在播放(AboutToWait 里决定要不要 request_redraw)
pub fn curve(&self) -> Curve
pub fn repeat(&self) -> Repeat
pub fn duration_ms(&self) -> u64
Sourcepub fn tick(&mut self, now_ms: u64) -> TickOutcome
pub fn tick(&mut self, now_ms: u64) -> TickOutcome
推进状态机到 now_ms,返回本轮结果。
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for AnimationController
impl !Send for AnimationController
impl !Sync for AnimationController
impl !UnwindSafe for AnimationController
impl Freeze for AnimationController
impl Unpin for AnimationController
impl UnsafeUnpin for AnimationController
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
Mutably borrows from an owned value. Read more