1
0
mirror of https://github.com/Siccity/xNode.git synced 2025-12-21 01:36:03 +08:00

Fix for [Space] attribute (#90)

* Fix for [Space] attribute.
Code is a bit messy.

* Exchanged EditorGUILayout.Space() to GUILayout.Space() that takes a parameter height, for custom space distances.

* Changed where implementation is added to not messy up the rest of the code.
This commit is contained in:
Simon Rodriguez 2018-12-18 10:00:10 +01:00 committed by Thor Brigsted
parent 6268bab37a
commit fe2b7a9684

View File

@ -43,6 +43,10 @@ namespace XNodeEditor {
else { else {
Rect rect = new Rect(); Rect rect = new Rect();
float spacePadding = 0;
SpaceAttribute spaceAttribute;
if(NodeEditorUtilities.GetAttrib(port.node.GetType(), property.name, out spaceAttribute)) spacePadding = spaceAttribute.height;
// If property is an input, display a regular property field and put a port handle on the left side // If property is an input, display a regular property field and put a port handle on the left side
if (port.direction == XNode.NodePort.IO.Input) { if (port.direction == XNode.NodePort.IO.Input) {
// Get data from [Input] attribute // Get data from [Input] attribute
@ -54,6 +58,15 @@ namespace XNodeEditor {
showBacking = inputAttribute.backingValue; showBacking = inputAttribute.backingValue;
} }
//Call GUILayout.Space if Space attribute is set and we are NOT drawing a PropertyField
bool useLayoutSpace = instancePortList
|| showBacking == XNode.Node.ShowBackingValue.Never
|| (showBacking == XNode.Node.ShowBackingValue.Unconnected && port.IsConnected);
if (spacePadding > 0 && useLayoutSpace) {
GUILayout.Space(spacePadding);
spacePadding = 0;
}
if (instancePortList) { if (instancePortList) {
Type type = GetType(property); Type type = GetType(property);
XNode.Node.ConnectionType connectionType = inputAttribute != null ? inputAttribute.connectionType : XNode.Node.ConnectionType.Multiple; XNode.Node.ConnectionType connectionType = inputAttribute != null ? inputAttribute.connectionType : XNode.Node.ConnectionType.Multiple;
@ -78,7 +91,7 @@ namespace XNodeEditor {
} }
rect = GUILayoutUtility.GetLastRect(); rect = GUILayoutUtility.GetLastRect();
rect.position = rect.position - new Vector2(16, 0); rect.position = rect.position - new Vector2(16, -spacePadding);
// 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 == XNode.NodePort.IO.Output) { } else if (port.direction == XNode.NodePort.IO.Output) {
// Get data from [Output] attribute // Get data from [Output] attribute
@ -90,6 +103,16 @@ namespace XNodeEditor {
showBacking = outputAttribute.backingValue; showBacking = outputAttribute.backingValue;
} }
//Call GUILayout.Space if Space attribute is set and we are NOT drawing a PropertyField
bool useLayoutSpace = instancePortList
|| showBacking == XNode.Node.ShowBackingValue.Never
|| (showBacking == XNode.Node.ShowBackingValue.Unconnected && port.IsConnected);
if (spacePadding > 0 && useLayoutSpace)
{
GUILayout.Space(spacePadding);
spacePadding = 0;
}
if (instancePortList) { if (instancePortList) {
Type type = GetType(property); Type type = GetType(property);
XNode.Node.ConnectionType connectionType = outputAttribute != null ? outputAttribute.connectionType : XNode.Node.ConnectionType.Multiple; XNode.Node.ConnectionType connectionType = outputAttribute != null ? outputAttribute.connectionType : XNode.Node.ConnectionType.Multiple;
@ -114,7 +137,7 @@ namespace XNodeEditor {
} }
rect = GUILayoutUtility.GetLastRect(); rect = GUILayoutUtility.GetLastRect();
rect.position = rect.position + new Vector2(rect.width, 0); rect.position = rect.position + new Vector2(rect.width, spacePadding);
} }
rect.size = new Vector2(16, 16); rect.size = new Vector2(16, 16);