Skip to content

Commit ad181a3

Browse files
committed
feat: optimize the width of the PlayableGraph popup window
1 parent e12f08a commit ad181a3

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

Editor/Scripts/Element/SearchablePopupField.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,23 @@ public override void OnGUI(Rect rect)
190190

191191
public override Vector2 GetWindowSize()
192192
{
193+
GUIContent tempLabelContent = new GUIContent();
194+
float maxWidth = 0;
195+
foreach (T item in _popup.GetChoices())
196+
{
197+
string label = item?.GetHashCode() == _popup.value?.GetHashCode()
198+
? _popup.formatSelectedValueCallback?.Invoke(item) ?? item?.ToString() ?? string.Empty
199+
: _popup.formatListItemCallback?.Invoke(item) ?? item?.ToString() ?? string.Empty;
200+
tempLabelContent.text = label;
201+
float width = EditorStyles.toolbarPopup.CalcSize(tempLabelContent).x;
202+
if (width > maxWidth)
203+
maxWidth = width;
204+
}
205+
193206
Vector2 size = new Vector2
194207
{
195-
x = Mathf.Max(300, _popup.GetVisualInput().resolvedStyle.width),
196-
y = Mathf.Min(400, _list.elementHeight * _list.count + 36),
208+
x = Mathf.Max(300, _popup.GetVisualInput().resolvedStyle.width, maxWidth),
209+
y = Mathf.Min(400, Mathf.Max(_list.elementHeight * _list.count + 36, 48)),
197210
};
198211

199212
return size;

0 commit comments

Comments
 (0)