From 96b79b53c58749e660964996e4c9d668d706da7e Mon Sep 17 00:00:00 2001 From: Jason Ma <1312119064@qq.com> Date: Wed, 27 Dec 2023 16:17:16 +0800 Subject: [PATCH] Fix Adaptive Enum Field Width --- Editor/Helper.cs | 4 ++-- Editor/ShaderDrawer.cs | 4 ++-- package.json | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Editor/Helper.cs b/Editor/Helper.cs index 4d84cd0..29fd5a3 100644 --- a/Editor/Helper.cs +++ b/Editor/Helper.cs @@ -125,9 +125,9 @@ public static LWGUI GetLWGUI(MaterialEditor editor) } } - public static void AdaptiveFieldWidth(GUIStyle style, GUIContent content, float extraWidth = 0) + public static void AdaptiveFieldWidth(GUIStyle style, GUIContent content) { - var extraTextWidth = Mathf.Max(0, style.CalcSize(content).x + extraWidth - EditorGUIUtility.fieldWidth); + var extraTextWidth = Mathf.Max(0, style.CalcSize(content).x - (EditorGUIUtility.fieldWidth - RevertableHelper.revertButtonWidth)); EditorGUIUtility.labelWidth -= extraTextWidth; EditorGUIUtility.fieldWidth += extraTextWidth; } diff --git a/Editor/ShaderDrawer.cs b/Editor/ShaderDrawer.cs index d863ab8..4677bea 100644 --- a/Editor/ShaderDrawer.cs +++ b/Editor/ShaderDrawer.cs @@ -535,7 +535,7 @@ public override void DrawProp(Rect position, MaterialProperty prop, GUIContent l return; } - Helper.AdaptiveFieldWidth(EditorStyles.popup, _names[index], EditorStyles.popup.lineHeight); + Helper.AdaptiveFieldWidth(EditorStyles.popup, _names[index]); int newIndex = EditorGUI.Popup(rect, label, index, _names); EditorGUI.showMixedValue = false; if (Helper.EndChangeCheck(lwgui, prop)) @@ -1109,7 +1109,7 @@ public override void DrawProp(Rect position, MaterialProperty prop, GUIContent l } var presetNames = preset.presets.Select(((inPreset) => new GUIContent(inPreset.presetName))).ToArray(); - Helper.AdaptiveFieldWidth(EditorStyles.popup, presetNames[index], EditorStyles.popup.lineHeight); + Helper.AdaptiveFieldWidth(EditorStyles.popup, presetNames[index]); int newIndex = EditorGUI.Popup(rect, label, index, presetNames); if (Helper.EndChangeCheck(lwgui, prop)) { diff --git a/package.json b/package.json index 924fc08..a46e9a3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.jasonma.lwgui", - "version": "1.14.5", + "version": "1.14.6", "displayName": "LWGUI", "description": "A Lightweight, Flexible, Powerful Shader GUI System for Unity.", "keywords": [