/// <summary>
        /// Formats the tree to look nicely.
        /// </summary>
        public static void PositionNodesNicely(BonsaiNode root, Vector2 anchor)
        {
            // Sort parent-child connections so formatter uses latest changes.
            foreach (BonsaiNode node in TreeTraversal.PreOrder(root))
            {
                node.SortChildren();
            }

            var positioning = new FormatPositioning();

            foreach (BonsaiNode node in TreeTraversal.PostOrder(root))
            {
                PositionHorizontal(node, positioning);
            }

            foreach (BonsaiNode node in TreeTraversal.PreOrder(root))
            {
                PositionVertical(node);
            }

            // Move the entire subtree to the anchor.
            Vector2 offset = EditorSingleDrag.StartDrag(root, root.Center);

            EditorSingleDrag.SetSubtreePosition(root, anchor, offset);
        }
        private void StartSingleDrag(BonsaiInputEvent startEvent)
        {
            BonsaiNode node   = startEvent.node;
            Vector2    offset = EditorSingleDrag.StartDrag(node, startEvent.canvasMousePostion);

            MotionAction = (CanvasTransform t) => EditorSingleDrag.Drag(node, BonsaiInput.MousePosition(t), offset);
        }
 public static void Drag(Vector2 dragPosition, IReadOnlyList <DraggingNode> nodes)
 {
     foreach (DraggingNode root in nodes)
     {
         EditorSingleDrag.SetSubtreePosition(root.node, dragPosition, root.offset);
     }
 }