mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-20 01:06:01 +08:00
Fixed resizing jittering due to node padding.
This commit is contained in:
parent
c58648d663
commit
26e5bf451e
@ -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;
|
||||
|
||||
@ -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();
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user