1
0
mirror of https://github.com/Siccity/xNode.git synced 2025-12-20 09:16:01 +08:00

Fixed renaming on group node jittering due to different header heights.

Added new virtual callback 'OnRenameActive()'. Called when rename is first activated.
This commit is contained in:
Emre Dogan 2023-10-06 03:21:55 +01:00
parent 6e579667b2
commit 47396c06f4
3 changed files with 28 additions and 3 deletions

View File

@ -210,6 +210,9 @@ namespace XNodeEditor
AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(target));
}
/// <summary> Called when entering into rename mode for this node. </summary>
public virtual void OnRenameActive() {}
/// <summary> Called after this node's name has changed. </summary>
public virtual void OnRename() {}

View File

@ -13,6 +13,12 @@ namespace XNodeEditor.NodeGroups
private NodeGroup _group;
private bool _isDragging;
private Vector2 _size;
private float _currentHeight;
public override void OnCreate()
{
_currentHeight = group.height;
}
public override void OnHeaderGUI()
{
@ -29,6 +35,7 @@ namespace XNodeEditor.NodeGroups
{
group.width = Mathf.Max(200, (int)e.mousePosition.x + 16);
group.height = Mathf.Max(100, (int)e.mousePosition.y - 34);
_currentHeight = group.height;
NodeEditorWindow.current.Repaint();
}
@ -132,8 +139,20 @@ namespace XNodeEditor.NodeGroups
break;
}
// Control height of node
GUILayout.Space(group.height);
GUILayout.Space(_currentHeight);
}
public override void OnRenameActive()
{
_currentHeight += 30 - NodeEditorResources.styles.nodeHeaderRename.fixedHeight -
NodeEditorResources.styles.nodeHeaderRename.margin.top +
NodeEditorResources.styles.nodeHeaderRename.margin.bottom / 2;
}
public override void OnRename()
{
_currentHeight = group.height;
}
public override int GetWidth()

View File

@ -38,12 +38,15 @@ namespace XNodeEditor
input = GUILayout.TextField(input, NodeEditorResources.styles.nodeHeaderRename);
EditorGUI.FocusTextInControl(inputControlName);
// Fixes textfield not being fully selected on multiple consecutive rename activates.
if (firstFrame)
{
// Fixes textfield not being fully selected on multiple consecutive rename activates.
TextEditor textEditor =
(TextEditor)GUIUtility.GetStateObject(typeof(TextEditor), GUIUtility.keyboardControl);
textEditor.SelectAll();
NodeEditor.GetEditor((Node)target, NodeEditorWindow.current).OnRenameActive();
firstFrame = false;
}