I’ve added the following manipulators to the GraphView:
this.AddManipulator(new ContentZoomer());
this.AddManipulator(new SelectionDragger());
this.AddManipulator(new ContentDragger());
this.AddManipulator(new RectangleSelector());
Then I’ve added a manipulator to add a Contextual Menu to add a node, like so:
this.AddManipulator(CreateContextualMenu("Title"));
private ContextualMenuManipulator CreateContextualMenu(string contextualMenuText)
{
return new ContextualMenuManipulator(menuEvent =>
menuEvent.menu.AppendAction(contextualMenuText, actionEvent =>
AddElement(CreateNode(actionEvent.eventInfo.mousePosition)), DropdownMenuAction.AlwaysEnabled));
}
The CreateNode method receives the mouse position and inserts the node at the correct place, until I drag the graph view (due to the content dragger) and try to create a new node.
I’ve inserted a log to see the position and it seems that the actionEvent.eventInfo.mousePosition only goes up to the current window size, and therefore instead of adding on the current position it creates in the closest to the window size.
The contextual menu is where I’ve clicked to add a node, and the node on the left is where it was added.
Is there a way to fix this?