Skip to main content

DragEvent

Struct DragEvent 

Source
pub struct DragEvent {
    pub phase: GesturePhase,
    pub position: [f32; 2],
    pub window_position: [f32; 2],
    pub start_position: [f32; 2],
    pub delta: [f32; 2],
    pub translation: [f32; 2],
    pub velocity: [f32; 2],
    pub button: MouseButton,
    pub modifiers: Modifiers,
    /* private fields */
}
Expand description

拖动事件,见 crate::Element::on_drag。位移、速度都是窗口坐标(逻辑像素),不受元素自己缩放的影响。

Start 沿按下处的路径走捕获 → 目标 → 冒泡,决定谁拿到这个拖动(DragEvent::claim_gesture、 DragEvent::decline_gesture);之后只交给拿到的元素

Fields§

§phase: GesturePhase

进行到哪一步

§position: [f32; 2]

元素自己的坐标

§window_position: [f32; 2]

窗口坐标;拖出窗口后可以是负数或超过窗口大小

§start_position: [f32; 2]

按下的位置,窗口坐标

§delta: [f32; 2]

和上一个事件之间的位移。Start 的位移是从按下到现在(包括越过阈值的那一小段),所以各次位移加起来就是总位移

§translation: [f32; 2]

从按下到现在的总位移

§velocity: [f32; 2]

最近约 0.1 秒的平均速度,逻辑像素每秒;松手前停了一会儿时 End 的速度是 0

§button: MouseButton

拖动用的鼠标键

§modifiers: Modifiers

此刻按住的修饰键

Implementations§

Source§

impl DragEvent

Source

pub fn stop_propagation(&self)

停止传播:冒泡阶段外面的元素、捕获阶段里面的元素不再收到这次 Start;这个元素上剩下的处理器照样调用。 停止了又没有元素拿到手势时,这个手势不开始(收到过 Start 的元素收到 Cancel)

Source

pub fn is_propagation_stopped(&self) -> bool

已经有处理器停止了传播

Source

pub fn phase(&self) -> PropagationPhase

事件传到了哪一段。Start 按捕获 → 目标 → 冒泡走;之后的 Move、End、Cancel 只交给拿到手势的元素, 是它拿到时的那一段(在捕获阶段抢到的是捕获阶段)

Source

pub fn claim_gesture(&self)

这个手势我要(只在 Start 时有效):这个元素拿到手势,传播停止,之后的 Move、End 只交给它; 收到过 Start 的别的元素收到 Cancel。父元素在捕获阶段(on_*_capture)调用就是抢在里面的元素之前拿走; 子元素在目标阶段调用是明说要它(不调用也是它的,见 Self::decline_gesture)

Source

pub fn decline_gesture(&self)

这个手势我不要(只在 Start 时有效):目标和冒泡阶段第一个有处理器的元素默认拿到手势, 调用了这个就接着往外传,交给外面的元素(比如横着拖的卡片把竖着的拖动让给外面的视口)。 之后收到 Cancel

Trait Implementations§

Source§

impl Clone for DragEvent

Source§

fn clone(&self) -> DragEvent

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

Source§

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

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

impl PartialEq for DragEvent

Source§

fn eq(&self, other: &DragEvent) -> 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 DragEvent

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more