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
拖动用的鼠标键
modifiers: Modifiers此刻按住的修饰键
Implementations§
Source§impl DragEvent
impl DragEvent
Sourcepub fn stop_propagation(&self)
pub fn stop_propagation(&self)
停止传播:冒泡阶段外面的元素、捕获阶段里面的元素不再收到这次 Start;这个元素上剩下的处理器照样调用。
停止了又没有元素拿到手势时,这个手势不开始(收到过 Start 的元素收到 Cancel)
Sourcepub fn is_propagation_stopped(&self) -> bool
pub fn is_propagation_stopped(&self) -> bool
已经有处理器停止了传播
Sourcepub fn phase(&self) -> PropagationPhase
pub fn phase(&self) -> PropagationPhase
事件传到了哪一段。Start 按捕获 → 目标 → 冒泡走;之后的 Move、End、Cancel 只交给拿到手势的元素,
是它拿到时的那一段(在捕获阶段抢到的是捕获阶段)
Sourcepub fn claim_gesture(&self)
pub fn claim_gesture(&self)
这个手势我要(只在 Start 时有效):这个元素拿到手势,传播停止,之后的 Move、End 只交给它;
收到过 Start 的别的元素收到 Cancel。父元素在捕获阶段(on_*_capture)调用就是抢在里面的元素之前拿走;
子元素在目标阶段调用是明说要它(不调用也是它的,见 Self::decline_gesture)
Sourcepub fn decline_gesture(&self)
pub fn decline_gesture(&self)
这个手势我不要(只在 Start 时有效):目标和冒泡阶段第一个有处理器的元素默认拿到手势,
调用了这个就接着往外传,交给外面的元素(比如横着拖的卡片把竖着的拖动让给外面的视口)。
之后收到 Cancel
Trait Implementations§
impl StructuralPartialEq for DragEvent
Auto Trait Implementations§
impl !Freeze for DragEvent
impl !RefUnwindSafe for DragEvent
impl !Sync for DragEvent
impl Forget for DragEvent
impl Send for DragEvent
impl Unpin for DragEvent
impl UnsafeUnpin for DragEvent
impl UnwindSafe for DragEvent
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.