pub trait Draggable {
// Required methods
fn drag_type(&self) -> &str;
fn drag_data(&self) -> DragPayload;
// Provided methods
fn drag_preview(&self) -> Option<Box<dyn Widget>> { ... }
fn drag_config(&self) -> DragConfig { ... }
fn on_drag_start(&mut self) { ... }
fn on_drag_end(&mut self, _success: bool) { ... }
}Expand description
Trait for widgets that can be drag sources.
Implement this trait to allow a widget to participate in drag-and-drop operations. The drag manager calls these methods during the drag lifecycle.
§Example
use ftui_widgets::drag::{Draggable, DragPayload, DragConfig};
struct FileItem { path: String }
impl Draggable for FileItem {
fn drag_type(&self) -> &str { "application/file-path" }
fn drag_data(&self) -> DragPayload {
DragPayload::new("application/file-path", self.path.as_bytes().to_vec())
.with_display_text(&self.path)
}
}Required Methods§
Sourcefn drag_type(&self) -> &str
fn drag_type(&self) -> &str
MIME-like type identifier for the dragged data.
Must return a stable string for the lifetime of the drag.
Examples: "text/plain", "widget/list-item", "application/file-path".
Sourcefn drag_data(&self) -> DragPayload
fn drag_data(&self) -> DragPayload
Produce the drag payload.
Called once when the drag starts to capture the data being transferred.
Provided Methods§
Sourcefn drag_preview(&self) -> Option<Box<dyn Widget>>
fn drag_preview(&self) -> Option<Box<dyn Widget>>
Optional custom preview widget shown during the drag.
Return None to use the default text-based preview from
DragPayload::display_text.
Sourcefn drag_config(&self) -> DragConfig
fn drag_config(&self) -> DragConfig
Drag gesture configuration for this widget.
Override to customize threshold, delay, or escape behaviour.
Sourcefn on_drag_start(&mut self)
fn on_drag_start(&mut self)
Called when a drag operation starts from this widget.
Use this to apply visual feedback (e.g., dim the source item).
Sourcefn on_drag_end(&mut self, _success: bool)
fn on_drag_end(&mut self, _success: bool)
Called when the drag operation ends.
success is true if the payload was accepted by a drop target,
false if the drag was cancelled or dropped on an invalid target.