b1 Button { text = "Button 1", position="absolute", x=10, y=10, onStartDrag = start, onDrag = drag, onDropOnTarget = drop};
Three properties make the drag operation possible:
Delegate StartDragFunction(widget Widget in, x int in, y int in) returns (Boolean)
The function receives a reference to the widget and receives the absolute x and y coordinates of the mouse pointer. The function returns a Boolean value that indicates whether to continue the drag operation.
Delegate DragFunction(widget Widget in, dropTarget Widget in, x int in, y int in)
The function receives references to the widget that is being dragged and to the widget (if any) over which the mouse pointer is passing. If the mouse pointer is not passing over a widget, the second argument is null. The function also receives the absolute x and y coordinates of the mouse pointer and has no return value. The function updates the position of the widget (or some other image) in response to the mouse-move event.
Delegate DropOnTargetFunction(widget Widget in, dropTarget Widget in, x int in, y int in)
The function receives references to the widget that is being dropped and to the widget (if any) under the mouse pointer. If no widget is under the mouse pointer, the second argument is null. The function also receives the absolute x and y coordinates of the mouse pointer and has no return value.
import com.ibm.egl.rui.widgets.TextField; handler MyHandler type RUIHandler{initialUI =[myTextField]} myTextField TextField{text = "What a drag!", position = "absolute", x = 110, y = 210, width = 120, onStartDrag = start, onDrag = drag, onDropOnTarget = drop}; dx, dy int; function start(myWidget Widget in, x int in, y int in) returns(boolean) dx = x - myWidget.x; dy = y - myWidget.y; return(true); end function drag(myWidget Widget in, drop Widget in, x int in, y int in) myWidget.x = x - dx; myWidget.y = y - dy; end function drop(widget Widget in, drop Widget in, x int in, y int in) end end
myWidget.x = x; myWidget.y = y;
To see more examples, see "Rich UI Shadow."