mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-20 09:16: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;
|
return NodeEditorResources.styles.nodeBody;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual RectOffset GetBodyPadding()
|
||||||
|
{
|
||||||
|
return NodeEditorResources.styles.nodeBodyPadding.padding;
|
||||||
|
}
|
||||||
|
|
||||||
public virtual GUIStyle GetHeaderLabelStyle()
|
public virtual GUIStyle GetHeaderLabelStyle()
|
||||||
{
|
{
|
||||||
return NodeEditorResources.styles.nodeHeaderLabel;
|
return NodeEditorResources.styles.nodeHeaderLabel;
|
||||||
|
|||||||
@ -723,13 +723,11 @@ namespace XNodeEditor
|
|||||||
|
|
||||||
GUI.color = nodeEditor.GetBodyColor();
|
GUI.color = nodeEditor.GetBodyColor();
|
||||||
GUIStyle bodyStyle = new GUIStyle(nodeEditor.GetBodyStyle());
|
GUIStyle bodyStyle = new GUIStyle(nodeEditor.GetBodyStyle());
|
||||||
|
bodyStyle.padding = nodeEditor.GetBodyPadding();
|
||||||
GUILayout.BeginVertical(bodyStyle);
|
GUILayout.BeginVertical(bodyStyle);
|
||||||
|
|
||||||
GUI.color = guiColor;
|
GUI.color = guiColor;
|
||||||
GUIStyle bodyPaddingStyle = NodeEditorResources.styles.nodePadding;
|
|
||||||
GUILayout.BeginVertical(bodyPaddingStyle);
|
|
||||||
nodeEditor.OnBodyGUI();
|
nodeEditor.OnBodyGUI();
|
||||||
GUILayout.EndVertical();
|
|
||||||
|
|
||||||
GUILayout.EndVertical();
|
GUILayout.EndVertical();
|
||||||
|
|
||||||
|
|||||||
@ -40,7 +40,7 @@ namespace XNodeEditor
|
|||||||
nodeHeader,
|
nodeHeader,
|
||||||
nodePorts,
|
nodePorts,
|
||||||
nodeBody,
|
nodeBody,
|
||||||
nodePadding,
|
nodeBodyPadding,
|
||||||
tooltip,
|
tooltip,
|
||||||
nodeHighlight;
|
nodeHighlight;
|
||||||
|
|
||||||
@ -74,8 +74,8 @@ namespace XNodeEditor
|
|||||||
nodeHeaderLabelRename.normal.textColor = Color.white;
|
nodeHeaderLabelRename.normal.textColor = Color.white;
|
||||||
nodeHeaderLabelRename.margin = new RectOffset(24, 24, 8, 2);
|
nodeHeaderLabelRename.margin = new RectOffset(24, 24, 8, 2);
|
||||||
|
|
||||||
nodePadding = new GUIStyle();
|
nodeBodyPadding = new GUIStyle();
|
||||||
nodePadding.padding = new RectOffset(16, 16, 3, 16);
|
nodeBodyPadding.padding = new RectOffset(16, 16, 3, 16);
|
||||||
|
|
||||||
nodeHeader = new GUIStyle();
|
nodeHeader = new GUIStyle();
|
||||||
nodeHeader.normal.background = NodeEditorResources.nodeHeader;
|
nodeHeader.normal.background = NodeEditorResources.nodeHeader;
|
||||||
|
|||||||
@ -51,10 +51,12 @@ namespace XNodeEditor.NodeGroups
|
|||||||
{
|
{
|
||||||
NodeEditorWindow.current.wantsMouseMove = true;
|
NodeEditorWindow.current.wantsMouseMove = true;
|
||||||
Event e = Event.current;
|
Event e = Event.current;
|
||||||
|
|
||||||
|
bool sizeAvailable = NodeEditorWindow.current.nodeSizes.TryGetValue(target, out _size);
|
||||||
switch (e.type)
|
switch (e.type)
|
||||||
{
|
{
|
||||||
case EventType.MouseMove:
|
case EventType.MouseMove:
|
||||||
if (NodeEditorWindow.current.nodeSizes.TryGetValue(target, out _size))
|
if (sizeAvailable)
|
||||||
{
|
{
|
||||||
bool initHovering = _isResizeHovering;
|
bool initHovering = _isResizeHovering;
|
||||||
// Mouse position checking is in node local space
|
// Mouse position checking is in node local space
|
||||||
@ -83,7 +85,8 @@ namespace XNodeEditor.NodeGroups
|
|||||||
e.mousePosition.x + _draggingOffset.x + (mouseRectMargin + mouseRectPadding));
|
e.mousePosition.x + _draggingOffset.x + (mouseRectMargin + mouseRectPadding));
|
||||||
// magic numbers - otherwise resizing will jump vertically.
|
// magic numbers - otherwise resizing will jump vertically.
|
||||||
group.height = (int)Mathf.Max(100,
|
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;
|
_currentHeight = group.height;
|
||||||
NodeEditorWindow.current.Repaint();
|
NodeEditorWindow.current.Repaint();
|
||||||
}
|
}
|
||||||
@ -104,7 +107,7 @@ namespace XNodeEditor.NodeGroups
|
|||||||
e.mousePosition));
|
e.mousePosition));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NodeEditorWindow.current.nodeSizes.TryGetValue(target, out _size))
|
if (sizeAvailable)
|
||||||
{
|
{
|
||||||
// Mouse position checking is in node local space
|
// Mouse position checking is in node local space
|
||||||
Rect lowerRight = new Rect(_size.x - (mouseRectMargin + mouseRectPadding),
|
Rect lowerRight = new Rect(_size.x - (mouseRectMargin + mouseRectPadding),
|
||||||
@ -186,7 +189,7 @@ namespace XNodeEditor.NodeGroups
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add scale cursors
|
// Add scale cursors
|
||||||
if (NodeEditorWindow.current.nodeSizes.TryGetValue(target, out _size))
|
if (sizeAvailable)
|
||||||
{
|
{
|
||||||
Rect lowerRight = new Rect(target.position, new Vector2(mouseRectMargin, mouseRectMargin));
|
Rect lowerRight = new Rect(target.position, new Vector2(mouseRectMargin, mouseRectMargin));
|
||||||
lowerRight.y += _size.y - (mouseRectMargin + mouseRectPadding);
|
lowerRight.y += _size.y - (mouseRectMargin + mouseRectPadding);
|
||||||
@ -200,7 +203,7 @@ namespace XNodeEditor.NodeGroups
|
|||||||
|
|
||||||
GUILayout.Space(_currentHeight);
|
GUILayout.Space(_currentHeight);
|
||||||
|
|
||||||
if (NodeEditorWindow.current.nodeSizes.TryGetValue(target, out _size))
|
if (sizeAvailable)
|
||||||
{
|
{
|
||||||
Color initColor = GUI.color;
|
Color initColor = GUI.color;
|
||||||
GUI.color = _isResizeHovering
|
GUI.color = _isResizeHovering
|
||||||
@ -236,6 +239,11 @@ namespace XNodeEditor.NodeGroups
|
|||||||
return headerLabelStyle;
|
return headerLabelStyle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override RectOffset GetBodyPadding()
|
||||||
|
{
|
||||||
|
return new RectOffset();
|
||||||
|
}
|
||||||
|
|
||||||
public static void AddMouseRect(Rect rect, MouseCursor mouseCursor)
|
public static void AddMouseRect(Rect rect, MouseCursor mouseCursor)
|
||||||
{
|
{
|
||||||
EditorGUIUtility.AddCursorRect(rect, mouseCursor);
|
EditorGUIUtility.AddCursorRect(rect, mouseCursor);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user