pub struct Spring { /* private fields */ }Expand description
单自由度物理弹簧状态机(Copy,可直接嵌入 View 状态字段)。
Implementations§
Source§impl Spring
impl Spring
Sourcepub const fn new(initial: f32, config: SpringConfig) -> Self
pub const fn new(initial: f32, config: SpringConfig) -> Self
创建一个初始静止在 initial 处的物理弹簧。
Sourcepub const fn is_settled(&self) -> bool
pub const fn is_settled(&self) -> bool
弹簧是否已完全收敛静止(静止后可停止调用 cx.request_frame() 进入 0% CPU 休眠)。
Sourcepub const fn is_running(&self) -> bool
pub const fn is_running(&self) -> bool
弹簧是否仍在运动中。
Sourcepub fn animate_to(&mut self, target: f32)
pub fn animate_to(&mut self, target: f32)
平滑更改目标值(自动保留当前瞬时速度 velocity,打断进行中的动画绝不突变)。
Sourcepub fn set_velocity(&mut self, velocity: f32)
pub fn set_velocity(&mut self, velocity: f32)
直接设置瞬时速度(单位/秒)。
Sourcepub fn set_config(&mut self, config: SpringConfig)
pub fn set_config(&mut self, config: SpringConfig)
动态更新弹簧物理参数(刚度、阻尼、质量),不打断当前位移与速度。
Trait Implementations§
Auto Trait Implementations§
impl Forget for Spring
impl Freeze for Spring
impl Move for Spring
impl RefUnwindSafe for Spring
impl Send for Spring
impl Sync for Spring
impl Unpin for Spring
impl UnsafeUnpin for Spring
impl UnwindSafe for Spring
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FluentBuilder for T
impl<T> FluentBuilder for T
Source§fn when(self, condition: bool, then: impl FnOnce(Self) -> Self) -> Self
fn when(self, condition: bool, then: impl FnOnce(Self) -> Self) -> Self
当
condition 为 true 时执行闭包修饰自身,否则原样返回。Source§fn when_else(
self,
condition: bool,
then: impl FnOnce(Self) -> Self,
else_fn: impl FnOnce(Self) -> Self,
) -> Self
fn when_else( self, condition: bool, then: impl FnOnce(Self) -> Self, else_fn: impl FnOnce(Self) -> Self, ) -> Self
根据
condition 在两个修饰分支之间二选一。Source§fn when_some<O>(
self,
option: Option<O>,
then: impl FnOnce(Self, O) -> Self,
) -> Self
fn when_some<O>( self, option: Option<O>, then: impl FnOnce(Self, O) -> Self, ) -> Self
当
option 为 Some(value) 时执行闭包修饰自身,否则原样返回。