Skip to main content

DragValue

Struct DragValue 

Source
pub struct DragValue {
    pub location: (f64, f64),
    pub start_location: (f64, f64),
    pub velocity: (f64, f64),
    pub time: f64,
}
Expand description

A DragGesture.Value, read out of the struct SwiftUI hands the handler.

on_drag_gesture used to throw this away — the handler was () -> () and the value went into invoke_value_action, which ignores its argument. A drag handler that cannot see where the drag went is not much of a drag handler: it can tell you that something was dragged and nothing else.

The fields come from the struct’s own layout rather than from accessors, because SwiftUI exports exactly one — translation — and none of the others:

  +0   time           Date            (seconds from the 2001 epoch)
  +8   location       CGPoint
  +24  startLocation  CGPoint
  +40  _velocity      _Velocity<CGSize>
  +56  platform       (empty)

That layout is read from the metadata at run time rather than trusted: a field added in front of location in a later SwiftUI would otherwise turn every drag into silent nonsense. If the shape is not the five fields above, the reader hands back zeroes rather than reading somewhere it should not.

Fields§

§location: (f64, f64)

Where the drag is now, in the gesture’s coordinate space.

§start_location: (f64, f64)

Where it began.

§velocity: (f64, f64)

How fast it was moving, in points per second.

_Velocity<CGSize> wraps a single CGSize and nothing else — checked by following the field record’s symbolic reference to the descriptor, which reports one stored field — so the two doubles at the field’s own offset are the velocity, with no wrapper to step over.

§time: f64

Seconds since Apple’s reference date (1 January 2001), which is what a Date stores. Useful for comparing two values, not as a wall clock.

Implementations§

Source§

impl DragValue

Source

pub fn translation(&self) -> (f64, f64)

location - startLocation, which is what Swift’s translation computes. Cross-checked against SwiftUI’s own getter in the tests.

Trait Implementations§

Source§

impl Clone for DragValue

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for DragValue

Source§

impl Debug for DragValue

Source§

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

Formats the value using the given formatter. Read more
Source§

impl GestureData for DragValue

Source§

unsafe fn read(at: *const u8) -> Self

Read the value SwiftUI passed by address. Read more
Source§

impl PartialEq for DragValue

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for DragValue

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.