Skip to main content

DropTarget

Struct DropTarget 

Source
pub struct DropTarget {
    pub types: Vec<String>,
    /* private fields */
}
Expand description

A drop destination (docs/drag-and-drop.md): what Decorate::drop_target takes. A drop destination: the types it takes, its acceptance policy, and what runs as a drag enters, leaves and drops (docs/drag-and-drop.md “Accepting drops”).

ⓘ
DropTarget::new(["text/uri-list"])
    .on_enter(move |_| hovering.set(true))
    .on_leave(move || hovering.set(false))
    .on_drop(move |drop| { files.set(drop.file_paths()); true })

The policy (Target::accept) is consulted during hover AND again at drop; without one a target takes a copy of any offer that carries one of its types. Every on_enter is followed by exactly one on_leave: when the drag moves off the target, when the session is cancelled, or right after the drop is delivered, so a highlight needs the pair and nothing else. on_drop returns whether the owned data was accepted. Do not delete a source based on asynchronous work started there: external transfers currently advertise Copy only.

A backend holds the target it was given and calls Target::proposal as the drag moves, Target::deliver at the drop and Target::leave when the session leaves the view or is cancelled; the enter and leave callbacks are derived from those three calls.

Fields§

§types: Vec<String>

The MIME types the target registers for with the platform.

Implementations§

Source§

impl Target

Source

pub fn new<S>(types: impl IntoIterator<Item = S>) -> Target
where S: Into<String>,

A target for offers that carry any of types. It accepts nothing until Target::on_drop gives it a receiver.

Source

pub fn files() -> Target

A target for file references (text/uri-list).

Source

pub fn accept(self, policy: impl Fn(&Location) -> Operation + 'static) -> Target

Decide what a drag at location would do: called during hover and again at the drop. Operation::None refuses this location. Without a policy the target proposes Operation::Copy for an offer that carries one of its types.

Source

pub fn on_enter(self, f: impl Fn(&Location) + 'static) -> Target

Run when a drag the target would accept comes over it.

Source

pub fn on_leave(self, f: impl Fn() + 'static) -> Target

Run when the hover ends: the drag left, the session was cancelled, or the drop was delivered. Paired with Target::on_enter.

Source

pub fn on_drop(self, f: impl Fn(Drop) -> bool + 'static) -> Target

Take the dropped items. Return whether they were accepted.

Source

pub fn guarded(self, guard: Rc<dyn Fn(&mut dyn FnMut())>) -> Target

This target with every callback run through guard, sharing the hover state: how the pieces layer scopes the callbacks to the piece that declared them. guard is handed each callback as a thunk and decides whether, and in which scope, to run it.

Source

pub fn is_hovering(&self) -> bool

Whether a drag is over the target right now.

Source

pub fn proposal(&self, location: &Location) -> Operation

What a drag at location would do, for the platform’s hover feedback. Marks the hover: the first accepting proposal of a session runs on_enter, and a proposal that turns to Operation::None runs on_leave.

Source

pub fn leave(&self)

The drag left the target or the session was cancelled. A backend calls it from the platform’s drag-exit and drag-end callbacks; it is idempotent, and it runs on_leave only when a hover was under way.

Source

pub fn deliver(&self, location: Location, offer: Offer) -> bool

The drop: consult the policy once more, hand the items to on_drop when it accepts, then end the hover. Returns whether the data was taken.

Trait Implementations§

Source§

impl Clone for Target

Source§

fn clone(&self) -> Target

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

Auto Trait Implementations§

§

impl !RefUnwindSafe for Target

§

impl !Send for Target

§

impl !Sync for Target

§

impl !UnwindSafe for Target

§

impl Forget for Target

§

impl Freeze for Target

§

impl Move for Target

§

impl Unpin for Target

§

impl UnsafeUnpin for Target

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> 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, 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoReactive<T, StaticMark> for T
where T: Clone + 'static,

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.