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
impl VelocityDrag
Sourcepub const fn new(config: VelocityDragConfig) -> Self
pub const fn new(config: VelocityDragConfig) -> Self
Create a new velocity drag helper with the given configuration
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
Create with default configuration
Sourcepub fn is_dragging(&self) -> bool
pub fn is_dragging(&self) -> bool
Check if a drag is in progress
Sourcepub fn is_velocity_mode(&self) -> bool
pub fn is_velocity_mode(&self) -> bool
Check if velocity mode is active
Sourcepub fn is_absolute_mode(&self) -> bool
pub fn is_absolute_mode(&self) -> bool
Check if absolute mode is active
Sourcepub const fn begin(
&mut self,
current_value: f64,
mouse_pos: f64,
use_velocity_mode: bool,
)
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 valuemouse_pos: Current mouse position (typically Y for vertical, X for horizontal)use_velocity_mode: Whether to use velocity mode (can be toggled by modifier)
Sourcepub fn begin_auto(
&mut self,
current_value: f64,
mouse_pos: f64,
modifiers: &Modifiers,
default_velocity_mode: bool,
)
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.
Sourcepub fn update(
&mut self,
mouse_pos: f64,
value_range: f64,
drag_pixels: f64,
) -> f64
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 positionvalue_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
Sourcepub fn update_tracked(
&mut self,
mouse_pos: f64,
value_range: f64,
drag_pixels: f64,
) -> f64
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
Sourcepub const fn start_value(&self) -> f64
pub const fn start_value(&self) -> f64
Get the start value when drag began
Sourcepub const fn accumulated_delta(&self) -> f64
pub const fn accumulated_delta(&self) -> f64
Get the total accumulated delta since drag began
Trait Implementations§
Source§impl Clone for VelocityDrag
impl Clone for VelocityDrag
Source§fn clone(&self) -> VelocityDrag
fn clone(&self) -> VelocityDrag
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more