mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-21 01:36:03 +08:00
Fixed dynamic node width.
Fixed field widths.
This commit is contained in:
parent
46e32234f3
commit
432ce05bb5
@ -137,7 +137,9 @@ public partial class NodeEditorWindow {
|
|||||||
Vector2 mousePos = Event.current.mousePosition;
|
Vector2 mousePos = Event.current.mousePosition;
|
||||||
//Get node position
|
//Get node position
|
||||||
Vector2 nodePos = GridToWindowPosition(node.position);
|
Vector2 nodePos = GridToWindowPosition(node.position);
|
||||||
Rect windowRect = new Rect(nodePos, new Vector2(200 / zoom, 30 / zoom));
|
float width = 200;
|
||||||
|
if (nodeWidths.ContainsKey(node)) width = nodeWidths[node];
|
||||||
|
Rect windowRect = new Rect(nodePos, new Vector2(width / zoom, 30 / zoom));
|
||||||
return windowRect.Contains(mousePos);
|
return windowRect.Contains(mousePos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -117,7 +117,7 @@ public partial class NodeEditorWindow {
|
|||||||
//If a null node is found, return. This can happen if the nodes associated script is deleted. It is currently not possible in Unity to delete a null asset.
|
//If a null node is found, return. This can happen if the nodes associated script is deleted. It is currently not possible in Unity to delete a null asset.
|
||||||
if (node == null) continue;
|
if (node == null) continue;
|
||||||
|
|
||||||
foreach(NodePort output in node.Outputs) {
|
foreach (NodePort output in node.Outputs) {
|
||||||
//Needs cleanup. Null checks are ugly
|
//Needs cleanup. Null checks are ugly
|
||||||
if (!portConnectionPoints.ContainsKey(output)) continue;
|
if (!portConnectionPoints.ContainsKey(output)) continue;
|
||||||
Vector2 from = _portConnectionPoints[output].center;
|
Vector2 from = _portConnectionPoints[output].center;
|
||||||
@ -136,7 +136,10 @@ public partial class NodeEditorWindow {
|
|||||||
|
|
||||||
private void DrawNodes() {
|
private void DrawNodes() {
|
||||||
Event e = Event.current;
|
Event e = Event.current;
|
||||||
if (e.type == EventType.Repaint) portConnectionPoints.Clear();
|
if (e.type == EventType.Repaint) {
|
||||||
|
portConnectionPoints.Clear();
|
||||||
|
nodeWidths.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
//Selected node is hashed before and after node GUI to detect changes
|
//Selected node is hashed before and after node GUI to detect changes
|
||||||
int nodeHash = 0;
|
int nodeHash = 0;
|
||||||
@ -186,6 +189,8 @@ public partial class NodeEditorWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (e.type == EventType.Repaint) {
|
if (e.type == EventType.Repaint) {
|
||||||
|
nodeWidths.Add(node, nodeEditor.GetWidth());
|
||||||
|
|
||||||
foreach (var kvp in NodeEditor.portPositions) {
|
foreach (var kvp in NodeEditor.portPositions) {
|
||||||
Vector2 portHandlePos = kvp.Value;
|
Vector2 portHandlePos = kvp.Value;
|
||||||
portHandlePos += node.position;
|
portHandlePos += node.position;
|
||||||
@ -204,14 +209,14 @@ public partial class NodeEditorWindow {
|
|||||||
|
|
||||||
//Check if we are hovering any of this nodes ports
|
//Check if we are hovering any of this nodes ports
|
||||||
//Check input ports
|
//Check input ports
|
||||||
foreach(NodePort input in node.Inputs) {
|
foreach (NodePort input in node.Inputs) {
|
||||||
//Check if port rect is available
|
//Check if port rect is available
|
||||||
if (!portConnectionPoints.ContainsKey(input)) continue;
|
if (!portConnectionPoints.ContainsKey(input)) continue;
|
||||||
Rect r = GridToWindowRect(portConnectionPoints[input]);
|
Rect r = GridToWindowRect(portConnectionPoints[input]);
|
||||||
if (r.Contains(mousePos)) hoveredPort = input;
|
if (r.Contains(mousePos)) hoveredPort = input;
|
||||||
}
|
}
|
||||||
//Check all output ports
|
//Check all output ports
|
||||||
foreach(NodePort output in node.Outputs) {
|
foreach (NodePort output in node.Outputs) {
|
||||||
//Check if port rect is available
|
//Check if port rect is available
|
||||||
if (!portConnectionPoints.ContainsKey(output)) continue;
|
if (!portConnectionPoints.ContainsKey(output)) continue;
|
||||||
Rect r = GridToWindowRect(portConnectionPoints[output]);
|
Rect r = GridToWindowRect(portConnectionPoints[output]);
|
||||||
@ -274,7 +279,7 @@ public partial class NodeEditorWindow {
|
|||||||
else {
|
else {
|
||||||
string s = TypeToString(elementType);
|
string s = TypeToString(elementType);
|
||||||
int i = s.IndexOf('[');
|
int i = s.IndexOf('[');
|
||||||
return s.Substring(0,i) + "["+rank+"]" + s.Substring(i);
|
return s.Substring(0, i) + "[" + rank + "]" + s.Substring(i);
|
||||||
}
|
}
|
||||||
} else return hoveredPort.ValueType.ToString();
|
} else return hoveredPort.ValueType.ToString();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,10 +14,8 @@ public static class NodeEditorGUILayout {
|
|||||||
Node node = property.serializedObject.targetObject as Node;
|
Node node = property.serializedObject.targetObject as Node;
|
||||||
NodePort port = node.GetPort(property.name);
|
NodePort port = node.GetPort(property.name);
|
||||||
|
|
||||||
float temp_labelWidth = EditorGUIUtility.labelWidth;
|
|
||||||
|
|
||||||
// If property is not a port, display a regular property field
|
// If property is not a port, display a regular property field
|
||||||
if (port == null) EditorGUILayout.PropertyField(property, includeChildren);
|
if (port == null) EditorGUILayout.PropertyField(property, includeChildren, GUILayout.MinWidth(30));
|
||||||
else {
|
else {
|
||||||
Rect rect = new Rect();
|
Rect rect = new Rect();
|
||||||
|
|
||||||
@ -26,12 +24,12 @@ public static class NodeEditorGUILayout {
|
|||||||
// Display a label if port is connected
|
// Display a label if port is connected
|
||||||
if (port.IsConnected) EditorGUILayout.LabelField(property.displayName);
|
if (port.IsConnected) EditorGUILayout.LabelField(property.displayName);
|
||||||
// Display an editable property field if port is not connected
|
// Display an editable property field if port is not connected
|
||||||
else EditorGUILayout.PropertyField(property, includeChildren);
|
else EditorGUILayout.PropertyField(property, includeChildren, GUILayout.MinWidth(30));
|
||||||
rect = GUILayoutUtility.GetLastRect();
|
rect = GUILayoutUtility.GetLastRect();
|
||||||
rect.position = rect.position - new Vector2(16, 0);
|
rect.position = rect.position - new Vector2(16, 0);
|
||||||
// If property is an output, display a text label and put a port handle on the right side
|
// If property is an output, display a text label and put a port handle on the right side
|
||||||
} else if (port.direction == NodePort.IO.Output) {
|
} else if (port.direction == NodePort.IO.Output) {
|
||||||
EditorGUILayout.LabelField(property.displayName, NodeEditorResources.styles.outputPort);
|
EditorGUILayout.LabelField(property.displayName, NodeEditorResources.styles.outputPort, GUILayout.MinWidth(30));
|
||||||
rect = GUILayoutUtility.GetLastRect();
|
rect = GUILayoutUtility.GetLastRect();
|
||||||
rect.position = rect.position + new Vector2(rect.width, 0);
|
rect.position = rect.position + new Vector2(rect.width, 0);
|
||||||
}
|
}
|
||||||
@ -45,14 +43,11 @@ public static class NodeEditorGUILayout {
|
|||||||
if (NodeEditor.portPositions.ContainsKey(port)) NodeEditor.portPositions[port] = portPos;
|
if (NodeEditor.portPositions.ContainsKey(port)) NodeEditor.portPositions[port] = portPos;
|
||||||
else NodeEditor.portPositions.Add(port, portPos);
|
else NodeEditor.portPositions.Add(port, portPos);
|
||||||
}
|
}
|
||||||
EditorGUIUtility.labelWidth = temp_labelWidth;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void PortField(NodePort port) {
|
public static void PortField(NodePort port) {
|
||||||
if (port == null) return;
|
if (port == null) return;
|
||||||
float temp_labelWidth = EditorGUIUtility.labelWidth;
|
EditorGUILayout.LabelField(port.fieldName.PrettifyCamelCase(), GUILayout.MinWidth(30));
|
||||||
|
|
||||||
EditorGUILayout.LabelField(port.fieldName.PrettifyCamelCase());
|
|
||||||
|
|
||||||
Rect rect = GUILayoutUtility.GetLastRect();
|
Rect rect = GUILayoutUtility.GetLastRect();
|
||||||
if (port.direction == NodePort.IO.Input) rect.position = rect.position - new Vector2(16, 0);
|
if (port.direction == NodePort.IO.Input) rect.position = rect.position - new Vector2(16, 0);
|
||||||
@ -65,7 +60,6 @@ public static class NodeEditorGUILayout {
|
|||||||
Vector2 portPos = rect.center;
|
Vector2 portPos = rect.center;
|
||||||
if (NodeEditor.portPositions.ContainsKey(port)) NodeEditor.portPositions[port] = portPos;
|
if (NodeEditor.portPositions.ContainsKey(port)) NodeEditor.portPositions[port] = portPos;
|
||||||
else NodeEditor.portPositions.Add(port, portPos);
|
else NodeEditor.portPositions.Add(port, portPos);
|
||||||
EditorGUIUtility.labelWidth = temp_labelWidth;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void DrawPortHandle(Rect rect, Type type) {
|
private static void DrawPortHandle(Rect rect, Type type) {
|
||||||
|
|||||||
@ -13,6 +13,8 @@ public partial class NodeEditorWindow : EditorWindow {
|
|||||||
/// <summary> Stores node positions for all nodePorts. </summary>
|
/// <summary> Stores node positions for all nodePorts. </summary>
|
||||||
public Dictionary<NodePort, Rect> portConnectionPoints { get { return _portConnectionPoints; } }
|
public Dictionary<NodePort, Rect> portConnectionPoints { get { return _portConnectionPoints; } }
|
||||||
private Dictionary<NodePort, Rect> _portConnectionPoints = new Dictionary<NodePort, Rect>();
|
private Dictionary<NodePort, Rect> _portConnectionPoints = new Dictionary<NodePort, Rect>();
|
||||||
|
public Dictionary<Node, float> nodeWidths { get { return _nodeWidths; } }
|
||||||
|
private Dictionary<Node, float> _nodeWidths = new Dictionary<Node, float>();
|
||||||
public NodeGraph graph;
|
public NodeGraph graph;
|
||||||
public Vector2 panOffset { get { return _panOffset; } set { _panOffset = value; Repaint(); } }
|
public Vector2 panOffset { get { return _panOffset; } set { _panOffset = value; Repaint(); } }
|
||||||
private Vector2 _panOffset;
|
private Vector2 _panOffset;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user