Skip to main content

VelocityDrag

Struct VelocityDrag 

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

State for velocity-based dragging

This helper manages drag state for sliders, knobs, or any parameter control that benefits from velocity-sensitive adjustment.

§Example

use armas_basic::animation::{VelocityDrag, VelocityDragConfig, DragMode};

let mut drag = VelocityDrag::new(VelocityDragConfig::new().sensitivity(1.5));

// On mouse down:
drag.begin(current_value, mouse_y, use_velocity_mode);

// On mouse drag:
let delta = drag.update(mouse_y, value_range);
value += delta;

// On mouse up:
drag.end();

Implementations§

Source§

impl VelocityDrag

Source

pub const fn new(config: VelocityDragConfig) -> Self

Create a new velocity drag helper with the given configuration

Source

pub fn with_defaults() -> Self

Create with default configuration

Source

pub const fn mode(&self) -> DragMode

Get the current drag mode

Source

pub fn is_dragging(&self) -> bool

Check if a drag is in progress

Source

pub fn is_velocity_mode(&self) -> bool

Check if velocity mode is active

Source

pub fn is_absolute_mode(&self) -> bool

Check if absolute mode is active

Source

pub const fn begin( &mut self, current_value: f64, mouse_pos: f64, use_velocity_mode: bool, )

Begin a drag operation

  • current_value: The current parameter value
  • mouse_pos: Current mouse position (typically Y for vertical, X for horizontal)
  • use_velocity_mode: Whether to use velocity mode (can be toggled by modifier)
Source

pub fn begin_auto( &mut self, current_value: f64, mouse_pos: f64, modifiers: &Modifiers, default_velocity_mode: bool, )

Begin drag, automatically choosing mode based on modifier keys

If default_velocity_mode is true, velocity mode is the default and modifier keys switch to absolute. Otherwise, absolute is default.

Source

pub fn update( &mut self, mouse_pos: f64, value_range: f64, drag_pixels: f64, ) -> f64

Update during drag and return the value delta

  • mouse_pos: Current mouse position
  • value_range: Total range of the parameter (max - min)
  • drag_pixels: Number of pixels for full range in absolute mode

Returns the delta to add to the current value

Source

pub fn update_tracked( &mut self, mouse_pos: f64, value_range: f64, drag_pixels: f64, ) -> f64

Update and track accumulated delta

Same as update() but also tracks the total change for absolute mode

Source

pub const fn end(&mut self)

End the drag operation

Source

pub const fn start_value(&self) -> f64

Get the start value when drag began

Source

pub const fn accumulated_delta(&self) -> f64

Get the total accumulated delta since drag began

Trait Implementations§

Source§

impl Clone for VelocityDrag

Source§

fn clone(&self) -> VelocityDrag

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 Debug for VelocityDrag

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> 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,