|
4 | 4 | using System.Globalization;
|
5 | 5 | using UnityEditor.Experimental;
|
6 | 6 | using UnityEditor.Experimental.GraphView;
|
7 |
| -using UnityEditor.SceneManagement; |
8 | 7 |
|
9 |
| -using UnityEditor.VFX.UIElements; |
10 | 8 | using UnityEngine;
|
11 | 9 | using UnityEngine.VFX;
|
12 | 10 | using UnityEngine.UIElements;
|
@@ -71,51 +69,25 @@ public static void SavePosition(Board board, Rect r)
|
71 | 69 |
|
72 | 70 | public static void ValidatePosition(GraphElement element, VFXView view, Rect defaultPosition)
|
73 | 71 | {
|
74 |
| - Rect viewrect = view.contentRect; |
75 |
| - Rect rect = element.GetPosition(); |
76 |
| - bool changed = false; |
| 72 | + var viewrect = view.contentRect; |
| 73 | + var rect = element.GetPosition(); |
| 74 | + var changed = false; |
77 | 75 |
|
78 |
| - Vector2 maxSizeInView = viewrect.max; |
79 |
| - float newWidth = Mathf.Max(defaultPosition.width, Mathf.Min(rect.width, maxSizeInView.x)); |
80 |
| - float newHeight = Mathf.Max(defaultPosition.height, Mathf.Min(rect.height, maxSizeInView.y)); |
81 |
| - |
82 |
| - if (Mathf.Abs(newWidth - rect.width) > 1) |
83 |
| - { |
84 |
| - rect.width = newWidth; |
85 |
| - changed = true; |
86 |
| - } |
87 |
| - |
88 |
| - if (Mathf.Abs(newHeight - rect.height) > 1) |
| 76 | + if (rect.xMin > viewrect.xMax || rect.xMax > viewrect.xMax) |
89 | 77 | {
|
90 |
| - rect.height = newHeight; |
| 78 | + var width = Math.Max(Math.Min(rect.width, viewrect.width), element.resolvedStyle.minWidth.value); |
| 79 | + rect.xMax = viewrect.xMax; |
| 80 | + rect.xMin = Math.Max(0, rect.xMax - width); |
| 81 | + rect.width = width; |
91 | 82 | changed = true;
|
92 | 83 | }
|
93 | 84 |
|
94 |
| - var xDiff = viewrect.xMax - rect.xMax; |
95 |
| - if (xDiff < 0) |
| 85 | + if (rect.yMin > viewrect.yMax || rect.yMax > viewrect.yMax) |
96 | 86 | {
|
97 |
| - if (rect.x + xDiff >= 0) |
98 |
| - { |
99 |
| - rect.x += xDiff; |
100 |
| - } |
101 |
| - else |
102 |
| - { |
103 |
| - rect.width = Math.Max(defaultPosition.width, rect.width + xDiff); |
104 |
| - } |
105 |
| - changed = true; |
106 |
| - } |
107 |
| - |
108 |
| - var yDiff = viewrect.yMax - rect.yMax; |
109 |
| - if (yDiff < 0) |
110 |
| - { |
111 |
| - if (rect.y + yDiff >= 0) |
112 |
| - { |
113 |
| - rect.y += yDiff; |
114 |
| - } |
115 |
| - else |
116 |
| - { |
117 |
| - rect.height = Math.Max(defaultPosition.height, rect.height + yDiff); |
118 |
| - } |
| 87 | + var height = Math.Max(Math.Min(rect.height, viewrect.height), element.resolvedStyle.minHeight.value); |
| 88 | + rect.yMax = viewrect.yMax; |
| 89 | + rect.yMin = Math.Max(0, rect.yMax - height); |
| 90 | + rect.height = height; |
119 | 91 | changed = true;
|
120 | 92 | }
|
121 | 93 |
|
|
0 commit comments