1
0
mirror of https://github.com/Siccity/xNode.git synced 2026-02-04 14:24:54 +08:00

Fixed group resizing code to not jitter anymore.

Can now adjust color of group node resize icon.
Changed header label rendering to always be vertically centered.
Changed group node style.
Changed rename text field style.
This commit is contained in:
Emre Dogan 2023-10-08 20:08:19 +01:00
parent ada6d85c51
commit c58648d663
12 changed files with 103 additions and 42 deletions

View File

@ -31,7 +31,7 @@ namespace XNodeEditor
public virtual void OnHeaderGUI()
{
GUILayout.Label(target.name, NodeEditorResources.styles.nodeHeaderLabel, GUILayout.Height(30));
GUILayout.Label(target.name, NodeEditorResources.styles.nodeHeaderLabel);
}
/// <summary> Draws standard field editors for all public fields </summary>

View File

@ -918,7 +918,8 @@ namespace XNodeEditor
width = 200;
}
Rect windowRect = new Rect(nodePos, new Vector2(width / zoom, 30 / zoom));
Rect windowRect = new Rect(nodePos, new Vector2(width / zoom, NodeEditor.GetEditor(node, current)
.GetHeaderStyle().fixedHeight / zoom));
return windowRect.Contains(mousePos);
}

View File

@ -688,12 +688,12 @@ namespace XNodeEditor
if (selected)
{
GUIStyle style = new GUIStyle(nodeEditor.GetBodyStyle());
GUIStyle styleBody = new GUIStyle(nodeEditor.GetBodyStyle());
GUIStyle highlightStyle = new GUIStyle(nodeEditor.GetBodyHighlightStyle());
highlightStyle.padding = style.padding;
style.padding = new RectOffset();
highlightStyle.padding = styleBody.padding;
styleBody.padding = new RectOffset();
GUI.color = nodeEditor.GetTint();
GUILayout.BeginVertical(style);
GUILayout.BeginVertical(styleBody);
GUI.color = NodeEditorPreferences.GetSettings().highlightColor;
GUILayout.BeginVertical(new GUIStyle(highlightStyle));
}
@ -706,22 +706,21 @@ namespace XNodeEditor
EditorGUI.BeginChangeCheck();
//Draw node contents
GUI.color = nodeEditor.GetHeaderColor();
GUIStyle styleHeader = new GUIStyle(nodeEditor.GetHeaderStyle());
GUILayout.BeginVertical(styleHeader);
GUI.color = guiColor;
if (currentActivity == NodeActivity.Renaming && Selection.activeObject == node)
{
RenameTextField.current.DrawRenameTextField();
}
else
{
GUI.color = nodeEditor.GetHeaderColor();
GUIStyle style = new GUIStyle(nodeEditor.GetHeaderStyle());
GUILayout.BeginVertical(style);
GUI.color = guiColor;
nodeEditor.OnHeaderGUI();
GUILayout.EndVertical();
}
GUILayout.EndVertical();
GUI.color = nodeEditor.GetBodyColor();
GUIStyle bodyStyle = new GUIStyle(nodeEditor.GetBodyStyle());
GUILayout.BeginVertical(bodyStyle);

View File

@ -71,6 +71,8 @@ namespace XNodeEditor
public Color32 bgPortsColor = new Color32(65, 67, 70, 255);
public Color32 bgBodyColor = new Color32(65, 67, 70, 255);
public Color32 highlightColor = new Color32(255, 255, 255, 255);
public Color32 resizeIconColor = new Color32(255, 255, 255, 26);
public Color32 resizeIconHoverColor = new Color32(255, 255, 255, 100);
public bool gridSnap = true;
public bool autoSave = true;
public bool openOnCreate = true;
@ -276,6 +278,9 @@ namespace XNodeEditor
settings.bgHeaderColor = EditorGUILayout.ColorField("Header Background", settings.bgHeaderColor);
settings.bgPortsColor = EditorGUILayout.ColorField("Ports Background", settings.bgPortsColor);
settings.bgBodyColor = EditorGUILayout.ColorField("Body Background", settings.bgBodyColor);
settings.resizeIconColor = EditorGUILayout.ColorField("Resize Icon Color", settings.resizeIconColor);
settings.resizeIconHoverColor =
EditorGUILayout.ColorField("Resize Icon Hover Color", settings.resizeIconHoverColor);
settings.highlightColor = EditorGUILayout.ColorField("Selection", settings.highlightColor);
EditorGUILayout.Space();
settings.noodlePath = (NoodlePath)EditorGUILayout.EnumPopup("Noodle path", settings.noodlePath);

View File

@ -64,14 +64,15 @@ namespace XNodeEditor
nodeHeaderLabel = new GUIStyle();
nodeHeaderLabel.alignment = TextAnchor.MiddleCenter;
nodeHeaderLabel.fontStyle = FontStyle.Bold;
nodeHeaderLabel.stretchHeight = true;
nodeHeaderLabel.normal.textColor = Color.white;
nodeHeaderLabelRename = new GUIStyle(GUI.skin.textField);
nodeHeaderLabelRename.alignment = TextAnchor.MiddleCenter;
nodeHeaderLabelRename.fontStyle = FontStyle.Bold;
nodeHeaderLabelRename.stretchHeight = true;
nodeHeaderLabelRename.normal.textColor = Color.white;
nodeHeaderLabelRename.fixedHeight = 18;
nodeHeaderLabelRename.margin = new RectOffset(5, 5, 10, 8);
nodeHeaderLabelRename.margin = new RectOffset(24, 24, 8, 2);
nodePadding = new GUIStyle();
nodePadding.padding = new RectOffset(16, 16, 3, 16);
@ -79,8 +80,8 @@ namespace XNodeEditor
nodeHeader = new GUIStyle();
nodeHeader.normal.background = NodeEditorResources.nodeHeader;
nodeHeader.border = new RectOffset(32, 32, 16, 0);
// nodeHeader.fixedHeight = 27;
nodeHeader.padding = new RectOffset(0, 0, 1, 0);
nodeHeader.fixedHeight = 28;
nodeHeader.padding = new RectOffset(0, 0, 6, 0);
// nodeHeader.padding = new RectOffset(16, 16, 3, 16);
nodePorts = new GUIStyle();

View File

@ -16,6 +16,7 @@ namespace XNodeEditor.NodeGroups
_corner != null ? _corner : _corner = Resources.Load<Texture2D>("xnode_corner");
private static Texture2D _corner;
private bool _isResizing;
private bool _isResizeHovering;
private Vector2 _size;
private float _currentHeight;
private Vector2 _draggingOffset;
@ -26,17 +27,24 @@ namespace XNodeEditor.NodeGroups
private const int mouseRectMargin = 30;
private GUIStyle headerStyle;
private GUIStyle headerLabelStyle;
public override void OnCreate()
{
_currentHeight = group.height;
headerStyle = new GUIStyle(NodeEditorResources.styles.nodeHeaderLabel);
headerStyle.fontSize = 18;
headerLabelStyle = new GUIStyle(NodeEditorResources.styles.nodeHeaderLabel);
headerLabelStyle.fontSize = 24;
headerStyle = new GUIStyle(NodeEditorResources.styles.nodeHeader);
headerStyle.fixedHeight += 18;
}
public override void OnHeaderGUI()
{
GUILayout.Label(target.name, headerStyle, GUILayout.Height(30));
Color initColor = GUI.contentColor;
GUI.contentColor = new Color(0.6f, 0.6f, 0.6f, 1.0f);
GUILayout.Label(target.name, headerLabelStyle);
GUI.contentColor = initColor;
}
public override void OnBodyGUI()
@ -45,11 +53,37 @@ namespace XNodeEditor.NodeGroups
Event e = Event.current;
switch (e.type)
{
case EventType.MouseMove:
if (NodeEditorWindow.current.nodeSizes.TryGetValue(target, out _size))
{
bool initHovering = _isResizeHovering;
// Mouse position checking is in node local space
Rect lowerRight = new Rect(_size.x - (mouseRectMargin + mouseRectPadding),
_size.y - (mouseRectMargin + mouseRectPadding), mouseRectMargin, mouseRectMargin);
if (lowerRight.Contains(e.mousePosition))
{
_isResizeHovering = true;
}
else
{
_isResizeHovering = false;
}
if (initHovering != _isResizeHovering)
{
NodeEditorWindow.current.Repaint();
}
}
break;
case EventType.MouseDrag:
if (_isResizing)
{
group.width = Mathf.Max(200, (int)e.mousePosition.x + (int)_draggingOffset.x + 16);
group.height = Mathf.Max(100, (int)e.mousePosition.y + (int)_draggingOffset.y - 34);
group.width = (int)Mathf.Max(200,
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)));
_currentHeight = group.height;
NodeEditorWindow.current.Repaint();
}
@ -78,8 +112,7 @@ namespace XNodeEditor.NodeGroups
if (lowerRight.Contains(e.mousePosition))
{
_isResizing = true;
_draggingOffset = _size - e.mousePosition - new Vector2(GetBodyStyle().padding.right,
GetBodyStyle().padding.bottom);
_draggingOffset = lowerRight.position - e.mousePosition;
}
}
@ -166,17 +199,23 @@ namespace XNodeEditor.NodeGroups
}
GUILayout.Space(_currentHeight);
GUI.DrawTexture(new Rect(group.width - 34, group.height + 16, 24, 24), corner);
}
public override void OnRenameActive()
{
_currentHeight += 30 - NodeEditorResources.styles.nodeHeaderLabelRename.fixedHeight -
NodeEditorResources.styles.nodeHeaderLabelRename.margin.top +
NodeEditorResources.styles.nodeHeaderLabelRename.margin.bottom / 2;
if (NodeEditorWindow.current.nodeSizes.TryGetValue(target, out _size))
{
Color initColor = GUI.color;
GUI.color = _isResizeHovering
? NodeEditorPreferences.GetSettings().resizeIconHoverColor
: NodeEditorPreferences.GetSettings().resizeIconColor;
GUI.DrawTexture(
new Rect(_size.x - (mouseRectMargin + mouseRectPadding),
_size.y - (mouseRectMargin + mouseRectPadding),
24,
24),
corner);
GUI.color = initColor;
}
}
public override void OnRenameDeactive()
{
_currentHeight = group.height;
@ -187,11 +226,16 @@ namespace XNodeEditor.NodeGroups
return group.width;
}
public override GUIStyle GetHeaderLabelStyle()
public override GUIStyle GetHeaderStyle()
{
return headerStyle;
}
public override GUIStyle GetHeaderLabelStyle()
{
return headerLabelStyle;
}
public static void AddMouseRect(Rect rect, MouseCursor mouseCursor)
{
EditorGUIUtility.AddCursorRect(rect, mouseCursor);

View File

@ -38,6 +38,10 @@ namespace XNodeEditor
GUIStyle stylesNodeHeaderRename = NodeEditorResources.styles.nodeHeaderLabelRename;
stylesNodeHeaderRename.fontSize =
NodeEditor.GetEditor((Node)target, NodeEditorWindow.current).GetHeaderLabelStyle().fontSize;
stylesNodeHeaderRename.fixedHeight = NodeEditor.GetEditor((Node)target, NodeEditorWindow.current)
.GetHeaderLabelStyle().fixedHeight;
stylesNodeHeaderRename.padding = NodeEditor.GetEditor((Node)target, NodeEditorWindow.current)
.GetHeaderLabelStyle().padding;
input = GUILayout.TextField(input, stylesNodeHeaderRename);
EditorGUI.FocusTextInControl(inputControlName);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 5.3 KiB

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 0babe8a4377248fcacd576e5da1a27e5
guid: d129eb4a5ff1c8a40a23ef0e54de1fa9
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
@ -63,16 +63,16 @@ TextureImporter:
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 1
applyGammaDecoding: 0
swizzle: 50462976
cookieLightType: 2
cookieLightType: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
@ -85,7 +85,7 @@ TextureImporter:
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 0
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
@ -98,7 +98,7 @@ TextureImporter:
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 0
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
@ -111,7 +111,7 @@ TextureImporter:
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 0
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0

Binary file not shown.

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: fe6a85593b08b0e41bef27ac9562c228
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -2,8 +2,8 @@
namespace XNode
{
[NodeColorHeader(0.2f, 0.2f, 0.2f, 0.5f)]
[NodeColorBody(0.25f, 0.25f, 0.25f, 0.35f)]
[NodeColorHeader(0.1f, 0.1f, 0.1f, 0.35f)]
[NodeColorBody(0.1f, 0.1f, 0.1f, 0.35f)]
[CreateNodeMenu("Group")]
public class NodeGroup : Node
{