Skip to main content

DndManager

Struct DndManager 

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

应用内拖放管理器。

Rc<RefCell<_>> 共享:source widget 持有一份用于 begin,app 持有一份用于 update/finish/cancel。单线程、不读墙钟。

Implementations§

Source§

impl DndManager

Source

pub fn new() -> Self

Source

pub fn session(&self) -> Option<DragSession>

Source

pub fn is_active(&self) -> bool

Source

pub fn begin( &self, source: ElementId, payload: DragPayload, position: Point, ) -> bool

开启会话。已有活跃会话时拒绝新会话(单指针应用内 DnD 的兜底), 返回 false 表示未开启;终态会话可直接被下一次 begin 覆盖。

Source

pub fn update( &self, tree: &mut ElementTree, position: Point, ) -> Option<ElementId>

指针移动时由 app 调用:用 tree 命中目标,沿祖先链找最近的 DropTarget。

返回当前 hover 的 target(若有),供 app 决定光标形态/重绘。

Source

pub fn finish(&self, tree: &mut ElementTree, position: Point) -> bool

抬起时由 app 调用:命中目标并尝试 drop。返回是否消费成功。

Source

pub fn cancel(&self)

显式取消(窗口失焦 / Escape / PointerCancel)。

Source

pub fn cancel_with_tree(&self, tree: &mut ElementTree)

带 tree 的取消:会通知当前 hover 目标 drag_leave。

Source

pub fn keyboard_pickup( &self, tree: &ElementTree, source: ElementId, payload: DragPayload, ) -> bool

键盘等价「拾取」:为指定 source 开会话,位置为 source 的 element 原点。

app 把 KeyDown(Enter/Space) 翻译为本调用;与鼠标 Pan 走同一个会话结构, 因此后续命中/drop/replay 完全一致。

Source

pub fn keyboard_move( &self, tree: &mut ElementTree, dx: f32, dy: f32, ) -> Option<ElementId>

键盘等价「移动」:按 logical 像素步进更新指针位置并重新命中目标。

Source

pub fn keyboard_drop(&self, tree: &mut ElementTree) -> bool

键盘等价「放下」:在当前位置完成 drop。

Source

pub fn clear(&self)

清空会话(树重建 / 窗口关闭时调用)。

Trait Implementations§

Source§

impl Clone for DndManager

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

Source§

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

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

impl Default for DndManager

Source§

fn default() -> Self

Returns the “default value” for a type. 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 = !

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.