pub struct Target {
pub types: Vec<String>,
/* private fields */
}Expand description
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
impl Target
Sourcepub fn new<S>(types: impl IntoIterator<Item = S>) -> Target
pub fn new<S>(types: impl IntoIterator<Item = S>) -> Target
A target for offers that carry any of types. It accepts nothing until
Target::on_drop gives it a receiver.
Sourcepub fn accept(self, policy: impl Fn(&Location) -> Operation + 'static) -> Target
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.
Sourcepub fn on_enter(self, f: impl Fn(&Location) + 'static) -> Target
pub fn on_enter(self, f: impl Fn(&Location) + 'static) -> Target
Run when a drag the target would accept comes over it.
Sourcepub fn on_leave(self, f: impl Fn() + 'static) -> Target
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.
Sourcepub fn on_drop(self, f: impl Fn(Drop) -> bool + 'static) -> Target
pub fn on_drop(self, f: impl Fn(Drop) -> bool + 'static) -> Target
Take the dropped items. Return whether they were accepted.
Sourcepub fn guarded(self, guard: Rc<dyn Fn(&mut dyn FnMut())>) -> Target
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.
Sourcepub fn is_hovering(&self) -> bool
pub fn is_hovering(&self) -> bool
Whether a drag is over the target right now.
Sourcepub fn proposal(&self, location: &Location) -> Operation
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.
Trait Implementations§
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> 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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