pub struct MomentumPosition<B: MomentumBehavior> {
pub behavior: B,
/* private fields */
}Expand description
Animated position with momentum physics
Models a 1D position that can be dragged and released with momentum. The position continues moving after release based on the configured behavior.
§Example
ⓘ
use armas_basic::animation::{MomentumPosition, ContinuousWithMomentum};
let mut pos = MomentumPosition::new(ContinuousWithMomentum::new().friction(0.08));
pos.set_limits(0.0, 100.0);
// During drag:
pos.begin_drag();
pos.drag(delta_from_start);
pos.end_drag();
// Each frame:
pos.update(dt);
let current = pos.position();Fields§
§behavior: BThe behavior that controls momentum physics
Implementations§
Source§impl<B: MomentumBehavior> MomentumPosition<B>
impl<B: MomentumBehavior> MomentumPosition<B>
Sourcepub const fn set_limits(&mut self, min: f64, max: f64)
pub const fn set_limits(&mut self, min: f64, max: f64)
Set the position limits
Sourcepub const fn set_position(&mut self, position: f64)
pub const fn set_position(&mut self, position: f64)
Set position directly (stops any animation)
Sourcepub const fn is_dragging(&self) -> bool
pub const fn is_dragging(&self) -> bool
Check if currently being dragged
Sourcepub const fn is_animating(&self) -> bool
pub const fn is_animating(&self) -> bool
Check if momentum animation is active
Sourcepub const fn begin_drag(&mut self)
pub const fn begin_drag(&mut self)
Begin a drag operation
Trait Implementations§
Source§impl<B: Clone + MomentumBehavior> Clone for MomentumPosition<B>
impl<B: Clone + MomentumBehavior> Clone for MomentumPosition<B>
Source§fn clone(&self) -> MomentumPosition<B>
fn clone(&self) -> MomentumPosition<B>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl<B> Freeze for MomentumPosition<B>where
B: Freeze,
impl<B> RefUnwindSafe for MomentumPosition<B>where
B: RefUnwindSafe,
impl<B> Send for MomentumPosition<B>where
B: Send,
impl<B> Sync for MomentumPosition<B>where
B: Sync,
impl<B> Unpin for MomentumPosition<B>where
B: Unpin,
impl<B> UnsafeUnpin for MomentumPosition<B>where
B: UnsafeUnpin,
impl<B> UnwindSafe for MomentumPosition<B>where
B: UnwindSafe,
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