Drop
Enables receiving per drag and drop.
modifier Drop
import { Frame, Rectangle, Overlay, Drop, Text } from ui
export component Main {
text: String = "Waiting..."
Rectangle(color: Color(0xFF80C0D0), radius: 4) with {
Frame(height: 128)
Overlay {
Text(self.text)
}
Drop(
of: ["text/plain"],
perform: fun (event, action) {
self.text = "\{action}: \{event.data(format: "text/plain")}"
return true
},
)
}
}
export var main = Main()
Constructors
(can_accept:enter:update:exit:perform)
can_accept: (DropEvent) -> (Bool)
Called when a drag enters or moves within the drop area to determine whether or not it is acceptable.
See DropEvent.
enter: (DropEvent) -> ()
Called when a drag enters the drop area.
This parameter is optional and can be omitted if you do not need to perform any action when a drag enters the drop area.
See DropEvent.
update: (DropEvent) -> (DropAction?)
Called when a drag moves within the drop area, allowing you to update the action that will be performed on drop.
If the function returns nil
then the proposed action is used.
This parameter is optional and can be omitted if you do not need to update the action.
See DropEvent.
exit: () -> ()
Called when a drag exits the drop area.
This parameter is optional and can be omitted if you do not need to perform any action when a drag exits the drop area.
perform: (DropEvent, DropAction) -> (Bool)
Called when a valid drop occured.
The DropAction
parameter indicates the action that was performed by the target, e.g. DropAction.copy
, DropAction.link
or DropAction.move
.
See DropEvent, DropAction.
(of:enter:update:exit:perform)
of: [String] = []
A list of MIME types that this drop area accepts.
enter: (DropEvent) -> ()
Called when a drag enters the drop area.
This parameter is optional and can be omitted if you do not need to perform any action when a drag enters the drop area.
See DropEvent.
update: (DropEvent) -> (DropAction?)
Called when a drag moves within the drop area, allowing you to update the action that will be performed on drop.
If the function returns nil
then the proposed action is used.
This parameter is optional and can be omitted if you do not need to update the action.
See DropEvent.
exit: () -> ()
Called when a drag exits the drop area.
This parameter is optional and can be omitted if you do not need to perform any action when a drag exits the drop area.
perform: (DropEvent, DropAction) -> (Bool)
Called when a valid drop occured.
The DropAction
parameter indicates the action that was performed by the target, e.g. DropAction.copy
, DropAction.link
or DropAction.move
.
See DropEvent.
See DropAction.
Layout Behavior
None.
DropEvent
class DropEvent
Methods
has_format(_ mime_type: String) -> (Bool)
Returns whether data for the given MIME type was attached to this event.
data(format: String) -> (String)
Retrieves the data for the given MIME type.
If data for the requested MIME type is not available, an internal exception is thrown.
See this article for more information on MIME types.
supports_action(_ action: DropAction) -> (Bool)
Returns whether the drag operation supports the given action.
See DropAction.
Properties
position: Point
The position of the pointer in the component's coordinate system when the drop occurred.
frame: Rect
The component's bounding box during the event.
DropAction
The action that can be performed on a drop.
enum DropAction {
copy,
move,
link,
cancel
}
copy
The target should copy the data.
move
The target should move the data.
link
The target should create a link to the data.
cancel
The target should cancel the drag operation.