- Home /
EditorGUILayout size not calculated automatically?
I'm using GUILayout.Window where EditorGUILayout element size doesn't get automatically calculated the way GUILayout elements do, example EditorGUILayout.EnumPopup(myEnum);
How can I make it resize? Thanks
Comment
Best Answer
Answer by numberkruncher · Oct 20, 2014 at 01:20 AM
Yes, it seems that the editor GUI controls do not behave in the same way.
Here is a custom implementation of EditorGUILayout.EnumPopup
which does expand the window:
using System;
using UnityEngine;
using UnityEditor;
public static class CustomEditorGUI {
private static GUIContent s_TempContent = new GUIContent();
public static Enum EnumPopup(Enum selected, params GUILayoutOption[] options) {
s_TempContent.text = ObjectNames.NicifyVariableName(selected.ToString());
var position = GUILayoutUtility.GetRect(s_TempContent, EditorStyles.popup);
return EditorGUI.EnumPopup(position, selected);
}
}
Usage example:
using UnityEngine;
using UnityEditor;
public class ExampleEditorWindow : EditorWindow {
[MenuItem("Window/Example")]
private static void ShowWindow() {
GetWindow<ExampleEditorWindow>();
}
private Rect _windowPosition = new Rect(10, 10, 50, 50);
private SomeEnum _selectedValue = SomeEnum.ThisIsAReallyLongString;
private void OnGUI() {
BeginWindows();
_windowPosition = GUILayout.Window(1, _windowPosition, DrawWindow, "My Window");
if (GUI.Button(new Rect(Screen.width - 200, 5, 190, 42), "Reset"))
_windowPosition = new Rect(10, 10, 50, 50);
EndWindows();
}
private void DrawWindow(int windowID) {
_selectedValue = (SomeEnum)CustomEditorGUI.EnumPopup(_selectedValue);
}
}
I hope that this helps!
Your answer
![](https://koobas.hobune.stream/wayback/20220613165453im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
GUILayout.Button image 0 Answers
[SOLVED]GUIStyle Word Wrap Check 1 Answer
Custom style for EditorGUILayout.Popup 0 Answers
TextArea tab width 0 Answers
How can I fix EditorGUILayout.TextArea not having word wrap? 1 Answer