Bladeren bron

some simple sort works

flabbet 7 maanden geleden
bovenliggende
commit
8f7f3ba2a3
2 gewijzigde bestanden met toevoegingen van 7 en 116 verwijderingen
  1. 7 66
      src/PixiEditor/Views/Nodes/LayoutAligner.cs
  2. 0 50
      src/PixiEditor/Views/Nodes/NodeGraphView.cs

+ 7 - 66
src/PixiEditor/Views/Nodes/LayoutAligner.cs

@@ -29,38 +29,25 @@ internal class LayoutAligner
 
     public void Align()
     {
-        var executionQueue = CalculateExecutionQueue(RootGroup);
-        while (executionQueue.Count > 0)
-        {
-            var group = executionQueue.Dequeue();
-            if (group.Children == null)
-            {
-                AlignNodes(group.Nodes, group.SourceNode);
-            }
-            else
-            {
-                //AlignGroup(group);
-            }
-        }
+        AlignNodes(RootGroup.SourceNode);
     }
 
-    private void AlignNodes(List<INodeHandler> nodes, INodeHandler? sourceNode)
+    private void AlignNodes(INodeHandler sourceNode)
     {
-        if (nodes.Count == 0) return;
+        if (sourceNode == null) return;
         foreach (var node in NodeGraph.AllNodes)
         {
-            boundsMap[node] = new RectD(sourceNode?.PositionBindable ?? VecD.Zero, NodeSizes[node]);
+            boundsMap[node] = new RectD(sourceNode.PositionBindable, NodeSizes[node]);
         }
 
-        nodes[0].TraverseBackwards((node, previousNode, previousConnection) =>
+        sourceNode.TraverseBackwards((node, previousNode, previousConnection) =>
         {
             if (previousNode == null)
             {
                 if (sourceNode == null) return true;
 
                 boundsMap[node] =
-                    new RectD(boundsMap[node].TopLeft - new VecD(boundsMap[node].Size.X + HorizontalSpacing, 0),
-                        boundsMap[node].Size);
+                    new RectD(VecD.Zero, boundsMap[node].Size);
                 node.PositionBindable = boundsMap[node].TopLeft;
                 return true;
             }
@@ -95,7 +82,7 @@ internal class LayoutAligner
             double moveYby = shift + startY + VerticalSpacing * indexOfVertical;
 
             double x = previousBounds.X - previousBounds.Width - HorizontalSpacing;
-            double y = verticalCount == 1 ? 0 : previousBounds.Y + moveYby;
+            double y = verticalCount == 1 ? previousBounds.Y : previousBounds.Y + moveYby;
 
             bounds = new RectD(x, y, bounds.Width, bounds.Height);
 
@@ -105,52 +92,6 @@ internal class LayoutAligner
         });
     }
 
-    private void AlignGroup(LayoutGroup group)
-    {
-        if (group.Children == null)
-        {
-            AlignNodes(group.Nodes, group.SourceNode);
-            return;
-        }
-
-        int childGroupsCount = group.Children.Count;
-        double totalHeightRequired = 0;
-
-        for (int i = 0; i < childGroupsCount; i++)
-        {
-            RectD bounds = GetBounds(group.Nodes);
-            totalHeightRequired += bounds.Height;
-        }
-        
-        double startY = 0;
-
-        for (int i = 0; i < group.Children.Count; i++)
-        {
-            var childGroup = group.Children[i];
-
-            RectD alignTo = new RectD(VecD.Zero, new VecD(0, 0));
-            if (childGroup.SourceNode != null)
-            {
-                alignTo = new RectD(boundsMap[childGroup.SourceNode].Pos, NodeSizes[childGroup.SourceNode]);
-            }
-
-            RectD bounds = GetBounds(childGroup.Nodes);
-
-            double shift = -totalHeightRequired / 2f + bounds.Height / 2f;
-            double moveYby = shift + startY + VerticalSpacing * i;
-
-            double x = alignTo.X - alignTo.Width - HorizontalSpacing;
-            double y = alignTo.Y + moveYby;
-
-            foreach (var node in childGroup.Nodes)
-            {
-                node.PositionBindable = new VecD(boundsMap[node].X, boundsMap[node].Y);
-            }
-            
-            startY += bounds.Height;
-        }
-    }
-
     private LayoutGroup SplitToGroups(INodeHandler startNode, INodeHandler sourceNode, LayoutGroup parent = null)
     {
         var group = new LayoutGroup { Nodes = [startNode], Parent = parent, SourceNode = sourceNode };

+ 0 - 50
src/PixiEditor/Views/Nodes/NodeGraphView.cs

@@ -764,55 +764,5 @@ internal class NodeGraphView : Zoombox.Zoombox
         LayoutAligner aligner = new(NodeGraph, boundsMap);
         aligner.SplitToGroups();
         aligner.Align();
-
-        /*const double padding = 100;
-
-        NodeGraph.OutputNode.TraverseBackwards((node, previousNode, previousConnection) =>
-        {
-            if (previousNode == null)
-            {
-                boundsMap[node] = new RectD(VecD.Zero, boundsMap[node].Size);
-                node.PositionBindable = new VecD(0, 0);
-                return true;
-            }
-
-            RectD previousBounds = boundsMap[previousNode];
-            RectD bounds = boundsMap[node];
-
-            int verticalCount = previousNode.Inputs.Count(x => x.ConnectedOutput != null);
-            double totalHeightRequired = 0;
-            double startY = 0;
-
-            int indexOfVertical = 0;
-            bool found = false;
-            foreach (var input in previousNode.Inputs)
-            {
-                if (input.ConnectedOutput == null) continue;
-
-                if (input != previousConnection && !found)
-                {
-                    indexOfVertical++;
-                }
-                else if (!found)
-                {
-                    startY = totalHeightRequired;
-                    found = true;
-                }
-
-                totalHeightRequired += boundsMap[input.ConnectedOutput.Node].Height;
-            }
-
-            double shift = -totalHeightRequired / 2f + bounds.Height / 2f;
-            double moveYby = shift + startY + padding * indexOfVertical;
-
-            double x = previousBounds.X - previousBounds.Width - padding;
-            double y = verticalCount == 1 ? 0 : previousBounds.Y + moveYby;
-
-            bounds = new RectD(x, y, bounds.Width, bounds.Height);
-
-            node.PositionBindable = bounds.TopLeft;
-            boundsMap[node] = bounds;
-            return true;
-        });*/
     }
 }