Grouping
As mentioned in Grouping, nodes can be interactively inserted into a group, moved from one group to another and ungrouped entirely as part of a Moving Items gesture. This process is called node reparenting. Programmatically, this is controlled by an instance of IReparentNodeHandler which is set on GraphEditorInputMode using the reparentNodeHandler property.
You can disable node reparenting completely by setting GraphEditorInputMode.allowReparentNodes to false
.
The IReparentNodeHandler interface defines methods that determine if a gesture should be interpreted as a reparenting gesture, if an item can be reparented, if a certain parent is a valid target for a node that is being reparented, and a method that actually performs the reparenting. Here is a detailed description:
- isReparentGesture(context: IInputModeContext, node: INode): boolean
- Whether the current gesture is a reparent gesture. The current gesture can be determined from the context.
- shouldReparent(context: IInputModeContext, node: INode): boolean
- Whether the parent of the current node can be changed.
- isValidParent(context: IInputModeContext, node: INode, newParent: INode): boolean
- Whether the node’s parent can be changed to
newParent
. - reparent(context: IInputModeContext, node: INode, newParent: INode): void
- Called after the gesture has been finished to perform the actual change of the parent.
Should be implemented to set
newParent
as the new parent of thenode
.
For your convenience, the default implementation of the IReparentNodeHandler interface is ReparentNodeHandler which implements the interface trivially by allowing all nodes to be reparented. You can use this implementation as a base for your own implementation if desired. For the implementation of isReparentGesture it uses a function that accepts key events as reparent gesture where the Shift modifier key is pressed. If you only want to change the gesture of the default behavior, simply set the ReparentNodeHandler.reparentRecognizer of the default reparentNodeHandler to something else.
The source code of the Reparent Handler demo shows how to extend IReparentNodeHandler’s default implementation ReparentNodeHandler to customize node reparenting.