From 26e5bf451e9c07ac0847e6282268bf8bd94731cf Mon Sep 17 00:00:00 2001 From: Emre Dogan <48212096+EmreDogann@users.noreply.github.com> Date: Sun, 8 Oct 2023 23:22:25 +0100 Subject: [PATCH] Fixed resizing jittering due to node padding. --- Scripts/Editor/NodeEditor.cs | 5 +++++ Scripts/Editor/NodeEditorGUI.cs | 4 +--- Scripts/Editor/NodeEditorResources.cs | 6 +++--- Scripts/Editor/NodeGroupEditor.cs | 18 +++++++++++++----- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/Scripts/Editor/NodeEditor.cs b/Scripts/Editor/NodeEditor.cs index 7976904..e3f8db2 100644 --- a/Scripts/Editor/NodeEditor.cs +++ b/Scripts/Editor/NodeEditor.cs @@ -196,6 +196,11 @@ namespace XNodeEditor return NodeEditorResources.styles.nodeBody; } + public virtual RectOffset GetBodyPadding() + { + return NodeEditorResources.styles.nodeBodyPadding.padding; + } + public virtual GUIStyle GetHeaderLabelStyle() { return NodeEditorResources.styles.nodeHeaderLabel; diff --git a/Scripts/Editor/NodeEditorGUI.cs b/Scripts/Editor/NodeEditorGUI.cs index 169ed38..0f690d3 100755 --- a/Scripts/Editor/NodeEditorGUI.cs +++ b/Scripts/Editor/NodeEditorGUI.cs @@ -723,13 +723,11 @@ namespace XNodeEditor GUI.color = nodeEditor.GetBodyColor(); GUIStyle bodyStyle = new GUIStyle(nodeEditor.GetBodyStyle()); + bodyStyle.padding = nodeEditor.GetBodyPadding(); GUILayout.BeginVertical(bodyStyle); GUI.color = guiColor; - GUIStyle bodyPaddingStyle = NodeEditorResources.styles.nodePadding; - GUILayout.BeginVertical(bodyPaddingStyle); nodeEditor.OnBodyGUI(); - GUILayout.EndVertical(); GUILayout.EndVertical(); diff --git a/Scripts/Editor/NodeEditorResources.cs b/Scripts/Editor/NodeEditorResources.cs index 5f8ed33..ec2d9ca 100644 --- a/Scripts/Editor/NodeEditorResources.cs +++ b/Scripts/Editor/NodeEditorResources.cs @@ -40,7 +40,7 @@ namespace XNodeEditor nodeHeader, nodePorts, nodeBody, - nodePadding, + nodeBodyPadding, tooltip, nodeHighlight; @@ -74,8 +74,8 @@ namespace XNodeEditor nodeHeaderLabelRename.normal.textColor = Color.white; nodeHeaderLabelRename.margin = new RectOffset(24, 24, 8, 2); - nodePadding = new GUIStyle(); - nodePadding.padding = new RectOffset(16, 16, 3, 16); + nodeBodyPadding = new GUIStyle(); + nodeBodyPadding.padding = new RectOffset(16, 16, 3, 16); nodeHeader = new GUIStyle(); nodeHeader.normal.background = NodeEditorResources.nodeHeader; diff --git a/Scripts/Editor/NodeGroupEditor.cs b/Scripts/Editor/NodeGroupEditor.cs index 7c3816d..fcaacf0 100644 --- a/Scripts/Editor/NodeGroupEditor.cs +++ b/Scripts/Editor/NodeGroupEditor.cs @@ -51,10 +51,12 @@ namespace XNodeEditor.NodeGroups { NodeEditorWindow.current.wantsMouseMove = true; Event e = Event.current; + + bool sizeAvailable = NodeEditorWindow.current.nodeSizes.TryGetValue(target, out _size); switch (e.type) { case EventType.MouseMove: - if (NodeEditorWindow.current.nodeSizes.TryGetValue(target, out _size)) + if (sizeAvailable) { bool initHovering = _isResizeHovering; // Mouse position checking is in node local space @@ -83,7 +85,8 @@ namespace XNodeEditor.NodeGroups e.mousePosition.x + _draggingOffset.x + (mouseRectMargin + mouseRectPadding)); // magic numbers - otherwise resizing will jump vertically. group.height = (int)Mathf.Max(100, - e.mousePosition.y + _draggingOffset.y - (31 + (30 - mouseRectMargin))); + e.mousePosition.y + _draggingOffset.y - + (headerStyle.fixedHeight - mouseRectMargin - mouseRectPadding)); _currentHeight = group.height; NodeEditorWindow.current.Repaint(); } @@ -104,7 +107,7 @@ namespace XNodeEditor.NodeGroups e.mousePosition)); } - if (NodeEditorWindow.current.nodeSizes.TryGetValue(target, out _size)) + if (sizeAvailable) { // Mouse position checking is in node local space Rect lowerRight = new Rect(_size.x - (mouseRectMargin + mouseRectPadding), @@ -186,7 +189,7 @@ namespace XNodeEditor.NodeGroups } // Add scale cursors - if (NodeEditorWindow.current.nodeSizes.TryGetValue(target, out _size)) + if (sizeAvailable) { Rect lowerRight = new Rect(target.position, new Vector2(mouseRectMargin, mouseRectMargin)); lowerRight.y += _size.y - (mouseRectMargin + mouseRectPadding); @@ -200,7 +203,7 @@ namespace XNodeEditor.NodeGroups GUILayout.Space(_currentHeight); - if (NodeEditorWindow.current.nodeSizes.TryGetValue(target, out _size)) + if (sizeAvailable) { Color initColor = GUI.color; GUI.color = _isResizeHovering @@ -236,6 +239,11 @@ namespace XNodeEditor.NodeGroups return headerLabelStyle; } + public override RectOffset GetBodyPadding() + { + return new RectOffset(); + } + public static void AddMouseRect(Rect rect, MouseCursor mouseCursor) { EditorGUIUtility.AddCursorRect(rect, mouseCursor);