Skip to main content

MomentumPosition

Struct MomentumPosition 

Source
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: B

The behavior that controls momentum physics

Implementations§

Source§

impl<B: MomentumBehavior> MomentumPosition<B>

Source

pub const fn new(behavior: B) -> Self

Create a new momentum position with the given behavior

Source

pub const fn set_limits(&mut self, min: f64, max: f64)

Set the position limits

Source

pub const fn position(&self) -> f64

Get current position

Source

pub const fn set_position(&mut self, position: f64)

Set position directly (stops any animation)

Source

pub const fn is_dragging(&self) -> bool

Check if currently being dragged

Source

pub const fn is_animating(&self) -> bool

Check if momentum animation is active

Source

pub const fn begin_drag(&mut self)

Begin a drag operation

Source

pub fn drag(&mut self, delta: f64, elapsed_since_last: f64)

Update position during drag

delta is the total offset from where the drag started elapsed_since_last is time since last drag() call (for velocity calculation)

Source

pub fn end_drag(&mut self)

End the drag and start momentum animation

Source

pub fn nudge(&mut self, delta: f64)

Apply a nudge (like from mouse wheel)

Source

pub fn update(&mut self, dt: f64) -> bool

Update the animation (call each frame)

Returns true if the position changed

Trait Implementations§

Source§

impl<B: Clone + MomentumBehavior> Clone for MomentumPosition<B>

Source§

fn clone(&self) -> MomentumPosition<B>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<B: Debug + MomentumBehavior> Debug for MomentumPosition<B>

Source§

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

Formats the value using the given formatter. Read more

Auto 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> 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> SerializableAny for T
where T: 'static + Any + Clone + for<'a> Send + Sync,