pub struct DndContext<T: Clone + 'static> { /* private fields */ }Expand description
Handle to the shared drag state. Cheap to copy: it contains only Dioxus store and signal keys.
Implementations§
Source§impl<T: Clone + 'static> DndContext<T>
impl<T: Clone + 'static> DndContext<T>
Sourcepub fn from_parts(
state: Store<DragState<T>>,
announcement: Signal<String>,
) -> Self
pub fn from_parts( state: Store<DragState<T>>, announcement: Signal<String>, ) -> Self
Wrap existing state. Prefer crate::core::hooks::use_dnd_provider.
Sourcepub fn start(
&mut self,
payload: T,
source: Option<ZoneId>,
pointer: Point,
grab: Point,
effect: DropEffect,
mode: DragMode,
)
pub fn start( &mut self, payload: T, source: Option<ZoneId>, pointer: Point, grab: Point, effect: DropEffect, mode: DragMode, )
Begin a drag. Notifies all fields (state transition).
Sourcepub fn start_with_id(&mut self, id: DragId, start: DragStart<T>)
pub fn start_with_id(&mut self, id: DragId, start: DragStart<T>)
Begin a drag with a stable source identity.
Sourcepub fn set_pointer_kind(&mut self, kind: PointerKind)
pub fn set_pointer_kind(&mut self, kind: PointerKind)
Record which pointer device drives the current drag (see
DragState::pointer_kind). Draggable sets this right after
pickup from the initiating event’s pointerType; call it from
custom pointer sources so host-side glue (cursor pollers, raw
input bridges) can tell captured pointers from blind ones. Built-in
sources install this in their initial snapshot; custom sources that
use start or start_with_id can refine the default afterwards.
Sourcepub fn request_refocus(&mut self, payload: T)
pub fn request_refocus(&mut self, payload: T)
Record that payload just landed via a keyboard drop and its new
element should take focus when it mounts (see
DragState::refocus). Draggable calls this on its own keyboard
drops; call it from custom keyboard sources to get the same focus
continuity.
Sourcepub fn claim_refocus(&mut self, payload: &T) -> boolwhere
T: PartialEq,
pub fn claim_refocus(&mut self, payload: &T) -> boolwhere
T: PartialEq,
Claim a pending focus restoration if it matches payload; returns
whether the caller should focus itself. First matching claimant
wins - the request is consumed.
Sourcepub fn set_source_rect(&mut self, rect: Option<Rect>)
pub fn set_source_rect(&mut self, rect: Option<Rect>)
Record the dragged element’s client rect (see
DragState::source_rect). Draggable measures and sets this right
after pickup; call it from custom drag sources so size-matched ghosts
(DragOverlay { match_source: true }) can dress themselves.
Sourcepub fn update_pointer(&mut self, pointer: Point)
pub fn update_pointer(&mut self, pointer: Point)
Update the tracked pointer position (drives DragOverlay). Granular:
only pointer subscribers rerun.
Sourcepub fn enter(&mut self, zone: ZoneId)
pub fn enter(&mut self, zone: ZoneId)
Mark zone as hovered. Granular: only over subscribers rerun.
Sourcepub fn leave(&mut self, zone: ZoneId)
pub fn leave(&mut self, zone: ZoneId)
Clear hover, but only if zone is still the hovered one (avoids
enter/leave races between adjacent zones).
Sourcepub fn take(&mut self) -> Option<(T, Option<ZoneId>)>
pub fn take(&mut self) -> Option<(T, Option<ZoneId>)>
Consume the payload on a successful drop. Returns (payload, source).
After this, dragging() is false.
Sourcepub fn take_settling(&mut self, to: Rect) -> Option<(T, Option<ZoneId>)>
pub fn take_settling(&mut self, to: Rect) -> Option<(T, Option<ZoneId>)>
Consume the payload on a successful drop, like Self::take, but
enter the settling phase instead of resetting: the returned clone
goes to the drop handler while the stored payload stays readable and
settle records the destination rect, so a settle-enabled
crate::core::components::DragOverlay can glide the ghost home.
After this, dragging() is false and over() is cleared; call
Self::finish_settle (the overlay does) to reset fully.
Custom sources in a joined crate::core::world::DndWorld must call
crate::core::world::DndWorld::claim_settle first: world overlays
only present and finish a settle for the elected window.
Sourcepub fn retarget_settle(&mut self, to: Rect)
pub fn retarget_settle(&mut self, to: Rect)
Re-aim an in-flight settle at a better rect - typically the landed
element’s own, measured after the drop re-rendered the model
(SettleSlot does this for you). The overlay’s glide retargets
smoothly, mid-flight included. A no-op unless currently settling.
Sourcepub fn finish_settle(&mut self)
pub fn finish_settle(&mut self)
End the settling phase and reset all state. A no-op unless currently
settling, so a late transitionend can never clobber a new drag.
Sourcepub fn cancel_with_reason(&mut self, reason: CancelReason)
pub fn cancel_with_reason(&mut self, reason: CancelReason)
Abort the drag with an explicit reason for monitor consumers.
Sourcepub fn dragging(&self) -> bool
pub fn dragging(&self) -> bool
Is a drag currently in flight? False while a completed drop is still
settling, even though Self::payload remains readable.
Sourcepub fn settling(&self) -> Option<Rect>
pub fn settling(&self) -> Option<Rect>
Destination rect of a drop currently settling (see
Self::take_settling), if any.
Sourcepub fn has_explicit_drag_id(&self) -> bool
pub fn has_explicit_drag_id(&self) -> bool
Whether the active source deliberately supplied its stable id.
Sourcepub fn drag_session_id(&self) -> Option<DragSessionId>
pub fn drag_session_id(&self) -> Option<DragSessionId>
Fresh identity of the active tracked pointer gesture.
Sourcepub fn source_rect(&self) -> Option<Rect>
pub fn source_rect(&self) -> Option<Rect>
Client rect of the dragged element measured at pickup, if available.
Sourcepub fn effect(&self) -> DropEffect
pub fn effect(&self) -> DropEffect
Effect the drag was started with.
Sourcepub fn pointer_kind(&self) -> PointerKind
pub fn pointer_kind(&self) -> PointerKind
Which pointer device drives the current drag (meaningful for
DragMode::Pointer drags; Mouse otherwise and by default).
Sourcepub fn snapshot(&self) -> Option<DragSnapshot<T>>
pub fn snapshot(&self) -> Option<DragSnapshot<T>>
Complete monitor snapshot of the active drag.
Sourcepub fn announce(&mut self, msg: impl Into<String>)
pub fn announce(&mut self, msg: impl Into<String>)
Push a screen-reader announcement (rendered by
crate::a11y::LiveRegion). Called automatically by the built-in
keyboard interaction; call it yourself for custom flows.
Sourcepub fn announcement(&self) -> String
pub fn announcement(&self) -> String
The current announcement text.
Trait Implementations§
Source§impl<T: Clone + 'static> Clone for DndContext<T>
impl<T: Clone + 'static> Clone for DndContext<T>
impl<T: Clone + 'static> Copy for DndContext<T>
Auto Trait Implementations§
impl<T> !RefUnwindSafe for DndContext<T>
impl<T> !Send for DndContext<T>
impl<T> !Sync for DndContext<T>
impl<T> !UnwindSafe for DndContext<T>
impl<T> Freeze for DndContext<T>
impl<T> Unpin for DndContext<T>
impl<T> UnsafeUnpin for DndContext<T>
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,
impl<T> DependencyElement for T
Source§impl<T> InitializeFromFunction<T> for T
impl<T> InitializeFromFunction<T> for T
Source§fn initialize_from_function(f: fn() -> T) -> T
fn initialize_from_function(f: fn() -> T) -> T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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