-
Notifications
You must be signed in to change notification settings - Fork 128
DragPane
DragPane
(source) is a wrapper around a WidgetGroup
that allows its children to be dragged. Actors dragged into the pane will be added to its actors (in the correct place, unless the widget uses some unusual paddings), unless a DragPaneListener
does not accept it. DragPane was added in VisUI 0.9.3.
DragPane
children are not draggable by default: not unless Draggable
listener is set with setDraggable
method. This method will automatically attach - or clear, if null - draggable listener to its children, adding the actual dragging functionality. DragPane
itself is just a container of actors that allows to add children by dropping.
##Sample
// Creating a drag pane using an internal GridGroup:
DragPane dragPane = new DragPane(new GridGroup());
// Creating dragging listener:
Draggable draggable = new Draggable();
// Children cannot be dragged out of the pane:
draggable.setKeepWithinParent(true);
// Other widgets will not receive mouse events during dragging:
draggable.setBlockInput(true);
// Original child actor is invisible during dragging; only dragged actor mimic is rendered:
draggable.setInvisibleWhenDragged(true);
// All dragPane children will have the listener attached:
dragPane.setDraggable(draggable);
// This listener filters actors dropped on the pane. Only actors that were originally pane's children are accepted:
dragPane.setListener(new DragPane.DragPaneListener.AcceptOwnChildren());
##DragPaneListener
If you need to filter dropped actors, implement DragPaneListener
and use DragPane#setListener
method. Some common implementations are already provided:
-
AcceptOwnChildren
: accepts actors that are already on the pane; this allows to move pane's actors around, but will not accept new, foreign actors. -
LimitChildren
: takes amax
amount of children that cannot be exceeded. Once children array size is equal to (or greater than)max
, new children are rejected.
##Draggable
You're not forced to work with DragPane
. Draggable
can be attached to any actor, even to these not in a DragPane
. If you need custom dragging functionality, you can implement your own DragListener
and set it with Draggable#setListener
.
Note that default listener implementation handles DragPane
functionality; if you set a custom listener without extending the DragPane$DefaultDragListener
, actors with this Draggable
will no longer be added to DragPane
s. This actually might be desired, as you can drop DragPane
altogether and use your custom containers of dragged actors.
Also, Draggable
contains a few static, modifiable fields that allow you to change default settings. If you want to globally change initial DragListener
or general look settings, modify static fields - they are used while constructing new Draggable
objects.
See README for VisUI introduction.