Documentation
¶
Overview ¶
Package dragdrop transfers application values between views in one window. It owns gesture negotiation, target changes and cancellation, with no look: the application supplies each view and its preview, and keeps a menu or another keyboard-accessible way to perform the same operation.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Activation ¶
type Activation uint8
Activation chooses how a source starts a drag, independently of device.
const ( // AfterMove starts after the pointer moves Threshold points. It is the default. AfterMove Activation = iota // AfterLongPress first waits for View.DelayLongPress, or the normal long-press // delay, then for movement. A scroll may take an earlier swipe as usual. AfterLongPress )
type Area ¶
Area connects its Source and Target descendants in one window. It adds no layout container. Nested areas are independent; use one per window. The source keeps its original view while a noninteractive preview follows the pointer above the content. Escape, native cancellation or source disposal ends the drag without dropping.
type Event ¶
Event is a value being dragged over a target. Data is sampled once as the drag starts; it may itself be a slice of the app's selected items.
type Result ¶
Result ends a source's drag. Dropped says a live accepting target received it; Target is that target's view, nil when the drag was cancelled or missed.
type Source ¶
type Source struct {
View core.View
// Data is sampled once when the drag starts. A nil function disables dragging.
// Copy mutable data here when the drag must retain a snapshot.
Data func() any
// Preview supplies a label or picture. Without it View.Label/LabelFunc is used.
Preview func(data any) core.Node
Activation Activation
// Threshold is movement in points, 4 when zero or negative.
Threshold core.Points
OnStart func(data any)
OnEnd func(Result)
}
Source makes View draggable within its Area. View retains its press, keyboard, accessibility and styling props; its Responder is owned by Source and must be unset. Put a button or another existing control in View.Children when it owns the normal action. A movement below Threshold leaves that action intact.
type Target ¶
type Target struct {
View core.View
Accept func(data any) bool
OnEnter, OnMove, OnLeave, OnDrop func(Event)
}
Target receives values on View. Accept may reject a value, allowing an accepting ancestor target to take it. OnEnter/OnLeave let the application draw the target state; no hover or press appearance is added. OnDrop must be set for the target to accept a drop. View.Ref is retained when supplied.