Skip to content

Commit

Permalink
Fix Adaptive Enum Field Width
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonMa0012 committed Dec 27, 2023
1 parent 0109c81 commit 96b79b5
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Editor/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions Editor/ShaderDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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))
{
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down

0 comments on commit 96b79b5

Please sign in to comment.