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

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!