From 3fabeddc0af487c225ad3f219d4d8587fdc53fd3 Mon Sep 17 00:00:00 2001 From: ManlyMarco <39247311+ManlyMarco@users.noreply.github.com> Date: Tue, 4 Jun 2024 22:37:15 +0200 Subject: [PATCH] Use cached GUILayout.ExpandWidth wherever possible --- .../LogViewer/LogViewerEntry.cs | 8 +-- .../LogViewer/LogViewerWindow.cs | 8 +-- .../RuntimeUnityEditorSettings.cs | 7 +- RuntimeUnityEditor/Features/ContextMenu.cs | 2 +- .../Utils/Abstractions/DnSpyHelper.cs | 2 +- .../ChangeHistory/ChangeHistoryWindow.cs | 6 +- .../Windows/Clipboard/ClipboardWindow.cs | 8 +-- .../Windows/Inspector/Inspector.cs | 20 +++--- .../Windows/Inspector/VariableFieldDrawer.cs | 68 +++++++++---------- .../Windows/Profiler/ProfilerWindow.cs | 18 +++-- RuntimeUnityEditor/Windows/REPL/REPLWindow.cs | 14 ++-- RuntimeUnityEditor/Windows/Taskbar.cs | 8 +-- 12 files changed, 84 insertions(+), 85 deletions(-) diff --git a/RuntimeUnityEditor.Bepin5/LogViewer/LogViewerEntry.cs b/RuntimeUnityEditor.Bepin5/LogViewer/LogViewerEntry.cs index b91bfcd..643f59e 100644 --- a/RuntimeUnityEditor.Bepin5/LogViewer/LogViewerEntry.cs +++ b/RuntimeUnityEditor.Bepin5/LogViewer/LogViewerEntry.cs @@ -52,13 +52,13 @@ public bool DrawEntry() { GUI.color = GetColor(); var clicked = GUILayout.Button(_timeString, GUI.skin.label, GUILayout.MinWidth(35)); - GUILayout.Label("[", GUILayout.ExpandWidth(false)); + GUILayout.Label("[", IMGUIUtils.LayoutOptionsExpandWidthFalse); clicked |= GUILayout.Button(_logLevelString, GUI.skin.label, GUILayout.MinWidth(45)); - GUILayout.Label(":", GUILayout.ExpandWidth(false)); + GUILayout.Label(":", IMGUIUtils.LayoutOptionsExpandWidthFalse); clicked |= GUILayout.Button(_sourceNameString, GUI.skin.label, GUILayout.MinWidth(100)); - GUILayout.Label("]", GUILayout.ExpandWidth(false)); + GUILayout.Label("]", IMGUIUtils.LayoutOptionsExpandWidthFalse); GUI.color = Color.white; - clicked |= GUILayout.Button(_dataString, GUI.skin.label, GUILayout.ExpandWidth(true)); + clicked |= GUILayout.Button(_dataString, GUI.skin.label, IMGUIUtils.LayoutOptionsExpandWidthTrue); return clicked; } diff --git a/RuntimeUnityEditor.Bepin5/LogViewer/LogViewerWindow.cs b/RuntimeUnityEditor.Bepin5/LogViewer/LogViewerWindow.cs index a8f39e7..1440178 100644 --- a/RuntimeUnityEditor.Bepin5/LogViewer/LogViewerWindow.cs +++ b/RuntimeUnityEditor.Bepin5/LogViewer/LogViewerWindow.cs @@ -143,19 +143,19 @@ protected override void DrawContents() { GUILayout.BeginHorizontal(); { - GUILayout.BeginHorizontal(GUI.skin.box, GUILayout.ExpandWidth(true)); + GUILayout.BeginHorizontal(GUI.skin.box, IMGUIUtils.LayoutOptionsExpandWidthTrue); { GUI.changed = false; var searchString = SearchString; var isEmpty = string.IsNullOrEmpty(searchString) && GUI.GetNameOfFocusedControl() != "sbox"; if (isEmpty) GUI.color = Color.gray; GUI.SetNextControlName("sbox"); - var newString = GUILayout.TextField(isEmpty ? "Search log text and stack traces..." : searchString, GUILayout.ExpandWidth(true)); + var newString = GUILayout.TextField(isEmpty ? "Search log text and stack traces..." : searchString, IMGUIUtils.LayoutOptionsExpandWidthTrue); if (GUI.changed) SearchString = newString; GUI.color = Color.white; } GUILayout.EndHorizontal(); - GUILayout.BeginHorizontal(GUI.skin.box, GUILayout.ExpandWidth(false)); + GUILayout.BeginHorizontal(GUI.skin.box, IMGUIUtils.LayoutOptionsExpandWidthFalse); { if (!Capture) GUI.color = Color.red; Capture = GUILayout.Toggle(Capture, new GUIContent("Enable log capture", "Note: This can hurt performance, especially if there is log spam.")); @@ -240,7 +240,7 @@ protected override void DrawContents() } } - if (entry.Sender != null && GUILayout.Button("Inspect", GUILayout.ExpandWidth(false))) + if (entry.Sender != null && GUILayout.Button("Inspect", IMGUIUtils.LayoutOptionsExpandWidthFalse)) Inspector.Instance.Push(new InstanceStackEntry(entry, entry.LogEventArgs.Source.SourceName + " -> Log entry"), true); DnSpyHelper.DrawDnSpyButtonIfAvailable(entry.Method, new GUIContent("^", $"In dnSpy, attempt to navigate to the method that produced this log message:\n\n{entry.Method.GetFancyDescription()}")); diff --git a/RuntimeUnityEditor.UMM/RuntimeUnityEditorSettings.cs b/RuntimeUnityEditor.UMM/RuntimeUnityEditorSettings.cs index f88b029..b2b7ae8 100644 --- a/RuntimeUnityEditor.UMM/RuntimeUnityEditorSettings.cs +++ b/RuntimeUnityEditor.UMM/RuntimeUnityEditorSettings.cs @@ -3,6 +3,7 @@ using System.IO; using System.Xml; using System.Xml.Serialization; +using RuntimeUnityEditor.Core.Utils; using UnityEngine; using UnityModManagerNet; #pragma warning disable CS0618 @@ -120,7 +121,7 @@ public void Draw(UnityModManager.ModEntry entry) } else if (setting is Setting keycodeSetting) { - GUILayout.Label(settingName, GUILayout.ExpandWidth(false)); + GUILayout.Label(settingName, IMGUIUtils.LayoutOptionsExpandWidthFalse); var value = new KeyBinding() { keyCode = keycodeSetting.Value }; if (UnityModManager.UI.DrawKeybinding(ref value, settingName)) keycodeSetting.Value = value.keyCode; @@ -129,9 +130,9 @@ public void Draw(UnityModManager.ModEntry entry) else if (setting is Setting stringSetting) { GUILayout.BeginVertical(); - GUILayout.Label(settingName, GUILayout.ExpandWidth(false)); + GUILayout.Label(settingName, IMGUIUtils.LayoutOptionsExpandWidthFalse); - var value = GUILayout.TextField(stringSetting.Value, GUILayout.ExpandWidth(true)); + var value = GUILayout.TextField(stringSetting.Value, IMGUIUtils.LayoutOptionsExpandWidthTrue); if (value != stringSetting.Value) stringSetting.Value = value; GUILayout.EndVertical(); } diff --git a/RuntimeUnityEditor/Features/ContextMenu.cs b/RuntimeUnityEditor/Features/ContextMenu.cs index f1f0975..fda795f 100644 --- a/RuntimeUnityEditor/Features/ContextMenu.cs +++ b/RuntimeUnityEditor/Features/ContextMenu.cs @@ -213,7 +213,7 @@ public void Show(object obj, MemberInfo objMemberInfo, Vector2 clickPoint) /// public void DrawContextButton(object obj, MemberInfo objMemberInfo) { - if (obj != null && GUILayout.Button("...", GUILayout.ExpandWidth(false))) + if (obj != null && GUILayout.Button("...", IMGUIUtils.LayoutOptionsExpandWidthFalse)) Show(obj, objMemberInfo); } diff --git a/RuntimeUnityEditor/Utils/Abstractions/DnSpyHelper.cs b/RuntimeUnityEditor/Utils/Abstractions/DnSpyHelper.cs index 57ae22c..96ede73 100644 --- a/RuntimeUnityEditor/Utils/Abstractions/DnSpyHelper.cs +++ b/RuntimeUnityEditor/Utils/Abstractions/DnSpyHelper.cs @@ -181,7 +181,7 @@ void IFeature.OnEditorShownChanged(bool visible) { } private static readonly GUIContent _guiContent = new GUIContent("^", "Navigate to this member in dnSpy"); internal static void DrawDnSpyButtonIfAvailable(MemberInfo mi, GUIContent customButtonContent = null) { - if (IsAvailable && GUILayout.Button(customButtonContent ?? _guiContent, GUILayout.ExpandWidth(false))) + if (IsAvailable && GUILayout.Button(customButtonContent ?? _guiContent, IMGUIUtils.LayoutOptionsExpandWidthFalse)) OpenInDnSpy(mi); } } diff --git a/RuntimeUnityEditor/Windows/ChangeHistory/ChangeHistoryWindow.cs b/RuntimeUnityEditor/Windows/ChangeHistory/ChangeHistoryWindow.cs index 33d20bb..94d59a5 100644 --- a/RuntimeUnityEditor/Windows/ChangeHistory/ChangeHistoryWindow.cs +++ b/RuntimeUnityEditor/Windows/ChangeHistory/ChangeHistoryWindow.cs @@ -87,9 +87,9 @@ protected override void DrawContents() GUI.color = Color.white; } - GUILayout.TextField(change.GetDisplayString(), GUI.skin.label, GUILayout.ExpandWidth(true)); + GUILayout.TextField(change.GetDisplayString(), GUI.skin.label, IMGUIUtils.LayoutOptionsExpandWidthTrue); - if (change.CanUndo && GUILayout.Button(_undoContent, GUILayout.ExpandWidth(false))) + if (change.CanUndo && GUILayout.Button(_undoContent, IMGUIUtils.LayoutOptionsExpandWidthFalse)) { try { @@ -101,7 +101,7 @@ protected override void DrawContents() } } - if (!change.Target.IsNullOrDestroyed() && GUILayout.Button(_inspectContent, GUILayout.ExpandWidth(false))) + if (!change.Target.IsNullOrDestroyed() && GUILayout.Button(_inspectContent, IMGUIUtils.LayoutOptionsExpandWidthFalse)) Inspector.Inspector.Instance.Push(new InstanceStackEntry(change.Target, change.GetDisplayString()), true); } GUILayout.EndHorizontal(); diff --git a/RuntimeUnityEditor/Windows/Clipboard/ClipboardWindow.cs b/RuntimeUnityEditor/Windows/Clipboard/ClipboardWindow.cs index 2961461..1dc6668 100644 --- a/RuntimeUnityEditor/Windows/Clipboard/ClipboardWindow.cs +++ b/RuntimeUnityEditor/Windows/Clipboard/ClipboardWindow.cs @@ -40,7 +40,7 @@ protected override void DrawContents() GUILayout.FlexibleSpace(); GUILayout.Label("You can copy objects to clipboard by clicking the 'C' button in inspector, or by running the 'copy(object)' command in REPL. Structs are copied by value, classes by reference.\n\n" + "Clipboard contents can be used in REPL by running the 'paste(index)' command, or in inspector when invoking a method.\n\n" + - "Press 'X' to remove item from clipboard, right click on it to open a menu with more options.", GUILayout.ExpandWidth(true)); + "Press 'X' to remove item from clipboard, right click on it to open a menu with more options.", IMGUIUtils.LayoutOptionsExpandWidthTrue); GUILayout.FlexibleSpace(); } GUILayout.EndVertical(); @@ -57,7 +57,7 @@ protected override void DrawContents() { GUILayout.Label("Index", GUILayout.Width(widthIndex), GUILayout.ExpandWidth(false)); GUILayout.Label("Type", GUILayout.Width(widthName), GUILayout.ExpandWidth(false)); - GUILayout.Label("Value", GUILayout.ExpandWidth(true)); + GUILayout.Label("Value", IMGUIUtils.LayoutOptionsExpandWidthTrue); } GUILayout.EndHorizontal(); @@ -78,7 +78,7 @@ protected override void DrawContents() var prevEnabled = GUI.enabled; GUI.enabled = type != null && typeof(IConvertible).IsAssignableFrom(type); GUI.changed = false; - var newVal = GUILayout.TextField(ToStringConverter.ObjectToString(content), GUILayout.ExpandWidth(true)); + var newVal = GUILayout.TextField(ToStringConverter.ObjectToString(content), IMGUIUtils.LayoutOptionsExpandWidthTrue); if (GUI.changed && type != null) { try @@ -93,7 +93,7 @@ protected override void DrawContents() GUI.enabled = prevEnabled; - if (GUILayout.Button("X", GUILayout.ExpandWidth(false))) + if (GUILayout.Button("X", IMGUIUtils.LayoutOptionsExpandWidthFalse)) Contents.RemoveAt(index); } GUILayout.EndHorizontal(); diff --git a/RuntimeUnityEditor/Windows/Inspector/Inspector.cs b/RuntimeUnityEditor/Windows/Inspector/Inspector.cs index f2ae50e..06d1d88 100644 --- a/RuntimeUnityEditor/Windows/Inspector/Inspector.cs +++ b/RuntimeUnityEditor/Windows/Inspector/Inspector.cs @@ -185,12 +185,12 @@ protected override void DrawContents() { GUILayout.BeginHorizontal(); { - GUILayout.BeginHorizontal(GUI.skin.box, GUILayout.ExpandWidth(true)); + GUILayout.BeginHorizontal(GUI.skin.box, IMGUIUtils.LayoutOptionsExpandWidthTrue); { - GUILayout.Label("Filter:", GUILayout.ExpandWidth(false)); + GUILayout.Label("Filter:", IMGUIUtils.LayoutOptionsExpandWidthFalse); GUI.SetNextControlName(SearchBoxName); - SearchString = GUILayout.TextField(SearchString, GUILayout.ExpandWidth(true)); + SearchString = GUILayout.TextField(SearchString, IMGUIUtils.LayoutOptionsExpandWidthTrue); if (_focusSearchBox) { @@ -206,7 +206,7 @@ protected override void DrawContents() _showDeclaredOnly = GUILayout.Toggle(_showDeclaredOnly, "Only declared"); /* todo - GUILayout.Label("Find:", GUILayout.ExpandWidth(false)); + GUILayout.Label("Find:", IMGUIUtils.LayoutOptionsExpandWidthFalse); foreach (var obj in new[] { new KeyValuePair(EditorUtilities.GetInstanceClassScanner().OrderBy(x => x.Name()), "Instances"), @@ -217,7 +217,7 @@ protected override void DrawContents() }) { if (obj.Key == null) continue; - if (GUILayout.Button(obj.Value, GUILayout.ExpandWidth(false))) + if (GUILayout.Button(obj.Value, IMGUIUtils.LayoutOptionsExpandWidthFalse)) Push(new InstanceStackEntry(obj.Key, obj.Value), true); }*/ } @@ -257,7 +257,7 @@ protected override void DrawContents() if (currentTab == tab) GUI.backgroundColor = Color.cyan; - if (GUILayout.Button($"Tab {index + 1}: {LimitStringLengthForPreview(tab?.CurrentStackItem?.Name, 18)}", GUILayout.ExpandWidth(false))) + if (GUILayout.Button($"Tab {index + 1}: {LimitStringLengthForPreview(tab?.CurrentStackItem?.Name, 18)}", IMGUIUtils.LayoutOptionsExpandWidthFalse)) { // todo custom context menu for the tab bar? IMGUIUtils.IsMouseRightClick() if (IMGUIUtils.IsMouseWheelClick()) @@ -293,7 +293,7 @@ protected override void DrawContents() if (stackEntry == currentTab.CurrentStackItem) GUI.backgroundColor = Color.cyan; - if (GUILayout.Button(LimitStringLengthForPreview(stackEntry.Name, 90), GUILayout.ExpandWidth(false))) + if (GUILayout.Button(LimitStringLengthForPreview(stackEntry.Name, 90), IMGUIUtils.LayoutOptionsExpandWidthFalse)) { if (IMGUIUtils.IsMouseRightClick()) stackEntry.ShowContextMenu(); @@ -305,7 +305,7 @@ protected override void DrawContents() } if (i + 1 < stackEntries.Length) - GUILayout.Label(">", GUILayout.ExpandWidth(false)); + GUILayout.Label(">", IMGUIUtils.LayoutOptionsExpandWidthFalse); GUI.backgroundColor = defaultGuiColor; } @@ -322,7 +322,7 @@ protected override void DrawContents() GUILayout.Space(2); GUILayout.Label("Member name", GUI.skin.box, _inspectorNameWidth); GUILayout.Space(1); - GUILayout.Label("Value", GUI.skin.box, GUILayout.ExpandWidth(true)); + GUILayout.Label("Value", GUI.skin.box, IMGUIUtils.LayoutOptionsExpandWidthTrue); } GUILayout.EndHorizontal(); @@ -451,7 +451,7 @@ private void DrawSingleContentEntry(ICacheEntry entry) catch (Exception ex) { RuntimeUnityEditorCore.Logger.Log(LogLevel.Error, $"[{Title}] Failed to draw setting {entry?.Name()} - {ex.Message}"); - GUILayout.TextArea(ex.Message, GUI.skin.label, GUILayout.ExpandWidth(true)); + GUILayout.TextArea(ex.Message, GUI.skin.label, IMGUIUtils.LayoutOptionsExpandWidthTrue); } } GUILayout.EndHorizontal(); diff --git a/RuntimeUnityEditor/Windows/Inspector/VariableFieldDrawer.cs b/RuntimeUnityEditor/Windows/Inspector/VariableFieldDrawer.cs index b35e163..dff0ada 100644 --- a/RuntimeUnityEditor/Windows/Inspector/VariableFieldDrawer.cs +++ b/RuntimeUnityEditor/Windows/Inspector/VariableFieldDrawer.cs @@ -79,7 +79,7 @@ public static void DrawSettingValue(ICacheEntry setting, object value) } else if (canSetValue && ToStringConverter.CanEditValue(setting, value)) { - DrawGenericEditableValue(setting, value, GUILayout.ExpandWidth(true)); + DrawGenericEditableValue(setting, value, IMGUIUtils.LayoutOptionsExpandWidthTrue); } else { @@ -92,7 +92,7 @@ public static void DrawSettingValue(ICacheEntry setting, object value) private static void DrawUnknownField(object value) { - GUILayout.TextArea(ToStringConverter.ObjectToString(value), GUI.skin.label, GUILayout.ExpandWidth(true)); + GUILayout.TextArea(ToStringConverter.ObjectToString(value), GUI.skin.label, IMGUIUtils.LayoutOptionsExpandWidthTrue); } public static void ClearCache() @@ -118,7 +118,7 @@ public static bool DrawCurrentDropdown() private static void DrawBoolField(ICacheEntry setting, object o) { var boolVal = (bool)setting.GetValue(); - var result = GUILayout.Toggle(boolVal, boolVal ? "True" : "False", GUILayout.ExpandWidth(true)); + var result = GUILayout.Toggle(boolVal, boolVal ? "True" : "False", IMGUIUtils.LayoutOptionsExpandWidthTrue); if (result != boolVal) setting.SetValue(result); } @@ -129,7 +129,7 @@ private static void DrawFlagsField(ICacheEntry setting, IList enumValues, object var allValues = enumValues.Cast().Select(x => new { name = x.ToString(), val = Convert.ToInt64(x) }).ToArray(); // Vertically stack Horizontal groups of the options to deal with the options taking more width than is available in the window - GUILayout.BeginVertical(GUILayout.ExpandWidth(true)); + GUILayout.BeginVertical(IMGUIUtils.LayoutOptionsExpandWidthTrue); { for (var index = 0; index < allValues.Length;) { @@ -173,7 +173,7 @@ private static void DrawFlagsField(ICacheEntry setting, IList enumValues, object private static void DrawComboboxField(ICacheEntry setting, IList list, object value) { var buttonText = new GUIContent(value.ToString()); - var dispRect = GUILayoutUtility.GetRect(buttonText, GUI.skin.button, GUILayout.ExpandWidth(true)); + var dispRect = GUILayoutUtility.GetRect(buttonText, GUI.skin.button, IMGUIUtils.LayoutOptionsExpandWidthTrue); if (!_comboBoxCache.TryGetValue(setting, out var box)) { @@ -264,8 +264,8 @@ private static void DrawQuaternion(ICacheEntry obj, object value) private static float DrawSingleVectorSlider(float setting, string label) { - GUILayout.Label(label, GUILayout.ExpandWidth(false)); - float.TryParse(GUILayout.TextField(setting.ToString("F4", CultureInfo.InvariantCulture), GUILayout.ExpandWidth(true)), NumberStyles.Any, CultureInfo.InvariantCulture, out var x); + GUILayout.Label(label, IMGUIUtils.LayoutOptionsExpandWidthFalse); + float.TryParse(GUILayout.TextField(setting.ToString("F4", CultureInfo.InvariantCulture), IMGUIUtils.LayoutOptionsExpandWidthTrue), NumberStyles.Any, CultureInfo.InvariantCulture, out var x); return x; } @@ -280,14 +280,14 @@ private static void DrawColor(ICacheEntry obj, object value) _colorCache[obj] = cacheEntry; } - GUILayout.Label("R", GUILayout.ExpandWidth(false)); - setting.r = GUILayout.HorizontalSlider(setting.r, 0f, 1f, GUILayout.ExpandWidth(true)); - GUILayout.Label("G", GUILayout.ExpandWidth(false)); - setting.g = GUILayout.HorizontalSlider(setting.g, 0f, 1f, GUILayout.ExpandWidth(true)); - GUILayout.Label("B", GUILayout.ExpandWidth(false)); - setting.b = GUILayout.HorizontalSlider(setting.b, 0f, 1f, GUILayout.ExpandWidth(true)); - GUILayout.Label("A", GUILayout.ExpandWidth(false)); - setting.a = GUILayout.HorizontalSlider(setting.a, 0f, 1f, GUILayout.ExpandWidth(true)); + GUILayout.Label("R", IMGUIUtils.LayoutOptionsExpandWidthFalse); + setting.r = GUILayout.HorizontalSlider(setting.r, 0f, 1f, IMGUIUtils.LayoutOptionsExpandWidthTrue); + GUILayout.Label("G", IMGUIUtils.LayoutOptionsExpandWidthFalse); + setting.g = GUILayout.HorizontalSlider(setting.g, 0f, 1f, IMGUIUtils.LayoutOptionsExpandWidthTrue); + GUILayout.Label("B", IMGUIUtils.LayoutOptionsExpandWidthFalse); + setting.b = GUILayout.HorizontalSlider(setting.b, 0f, 1f, IMGUIUtils.LayoutOptionsExpandWidthTrue); + GUILayout.Label("A", IMGUIUtils.LayoutOptionsExpandWidthFalse); + setting.a = GUILayout.HorizontalSlider(setting.a, 0f, 1f, IMGUIUtils.LayoutOptionsExpandWidthTrue); GUILayout.Space(4); @@ -319,7 +319,7 @@ private static void DrawColor(ICacheEntry obj, object value) cacheEntry.Last = setting; } - GUILayout.Label(cacheEntry.Tex, GUILayout.ExpandWidth(false)); + GUILayout.Label(cacheEntry.Tex, IMGUIUtils.LayoutOptionsExpandWidthFalse); } private sealed class ColorCacheEntry @@ -340,7 +340,7 @@ private static void DrawAnyTexture(object obj) GUILayout.FlexibleSpace(); - if (ObjectView.ObjectViewWindow.Initialized && GUILayout.Button("View", GUILayout.ExpandWidth(false))) + if (ObjectView.ObjectViewWindow.Initialized && GUILayout.Button("View", IMGUIUtils.LayoutOptionsExpandWidthFalse)) ObjectView.ObjectViewWindow.Instance.SetShownObject(tex, tex.name); } @@ -374,7 +374,7 @@ private static void DrawSprite(Sprite spr, string objectName) GUILayout.FlexibleSpace(); - if (ObjectView.ObjectViewWindow.Initialized && GUILayout.Button("View", GUILayout.ExpandWidth(false))) + if (ObjectView.ObjectViewWindow.Initialized && GUILayout.Button("View", IMGUIUtils.LayoutOptionsExpandWidthFalse)) ObjectView.ObjectViewWindow.Instance.SetShownObject(spr.GetVisibleTexture(), objectName); } @@ -402,32 +402,32 @@ private static void DrawImage(ICacheEntry obj, object value) private static void DrawMethodInvokeField(MethodCacheEntry method) { - if (GUILayout.Button(_buttonInvokeContent, GUILayout.ExpandWidth(false))) + if (GUILayout.Button(_buttonInvokeContent, IMGUIUtils.LayoutOptionsExpandWidthFalse)) ShowInvokeWindow(method.MethodInfo, method.Instance); - GUILayout.Label(method.ParameterString, GUILayout.ExpandWidth(true)); + GUILayout.Label(method.ParameterString, IMGUIUtils.LayoutOptionsExpandWidthTrue); } private static void DrawEventInvokeField(EventCacheEntry @event) { var eventInfo = @event.EventInfo; - GUILayout.Label("Invoke event method: ", GUILayout.ExpandWidth(false)); - if (GUILayout.Button("Add", GUILayout.ExpandWidth(false))) + GUILayout.Label("Invoke event method: ", IMGUIUtils.LayoutOptionsExpandWidthFalse); + if (GUILayout.Button("Add", IMGUIUtils.LayoutOptionsExpandWidthFalse)) ShowInvokeWindow(eventInfo.GetAddMethod(true), @event.Instance); - if (GUILayout.Button("Remove", GUILayout.ExpandWidth(false))) + if (GUILayout.Button("Remove", IMGUIUtils.LayoutOptionsExpandWidthFalse)) ShowInvokeWindow(eventInfo.GetRemoveMethod(true), @event.Instance); // Raise method is always null in C# assemblies, but exists if assembly was compiled from VB.NET, F# or C++/CLI var raiseMethod = eventInfo.GetRaiseMethod(true); - if (raiseMethod != null && GUILayout.Button("Raise", GUILayout.ExpandWidth(false))) + if (raiseMethod != null && GUILayout.Button("Raise", IMGUIUtils.LayoutOptionsExpandWidthFalse)) ShowInvokeWindow(raiseMethod, @event.Instance); var backingDelegate = (Delegate)@event.GetValue(); if (backingDelegate != null) { GUILayout.Space(10); - //if (GUILayout.Button("Raise", GUILayout.ExpandWidth(false))) + //if (GUILayout.Button("Raise", IMGUIUtils.LayoutOptionsExpandWidthFalse)) // ShowInvokeWindow(backingDelegate.DynamicInvoke(), @event.Instance); var invocationList = backingDelegate.GetInvocationList(); @@ -437,7 +437,7 @@ private static void DrawEventInvokeField(EventCacheEntry @event) GUILayout.FlexibleSpace(); - //GUILayout.Label(method.ParameterString, GUILayout.ExpandWidth(true)); + //GUILayout.Label(method.ParameterString, IMGUIUtils.LayoutOptionsExpandWidthTrue); } public static void ShowInvokeWindow(MethodInfo method, object instance, Type[] genericArguments = null, ParameterInfo[] parameters = null) @@ -467,7 +467,7 @@ private static void DrawDelegateField(ICacheEntry cacheEntry) if (v == null) { - GUILayout.Label("NULL / Empty", GUILayout.ExpandWidth(true)); + GUILayout.Label("NULL / Empty", IMGUIUtils.LayoutOptionsExpandWidthTrue); return; } @@ -479,7 +479,7 @@ private static void DrawDelegateField(ICacheEntry cacheEntry) var invocationList = v.GetInvocationList(); //todo v.Method is null, work on delegate directly - if (GUILayout.Button(_buttonInvokeContent, GUILayout.ExpandWidth(false))) + if (GUILayout.Button(_buttonInvokeContent, IMGUIUtils.LayoutOptionsExpandWidthFalse)) { if (invokeM != null) ShowInvokeWindow(invokeM, v); @@ -487,10 +487,10 @@ private static void DrawDelegateField(ICacheEntry cacheEntry) ShowInvokeWindow(dynInvokeM, v, null, v.Method.GetParameters()); } - if (GUILayout.Button(invocationList.Length + " delegate(s)", GUILayout.ExpandWidth(false))) + if (GUILayout.Button(invocationList.Length + " delegate(s)", IMGUIUtils.LayoutOptionsExpandWidthFalse)) Inspector.Instance.Push(new InstanceStackEntry(invocationList, cacheEntry.Name() + " Invocation List", cacheEntry), false); - GUILayout.Label(MethodCacheEntry.GetParameterPreviewString(invokeM), GUILayout.ExpandWidth(true)); + GUILayout.Label(MethodCacheEntry.GetParameterPreviewString(invokeM), IMGUIUtils.LayoutOptionsExpandWidthTrue); } public static void DrawInvokeWindow() @@ -531,7 +531,7 @@ private static void DrawInvokeWindowFunc(int id) GUILayout.BeginHorizontal(); GUILayout.Label("#" + index, GUILayout.Width(indexColWidth)); GUILayout.Label(genericArg.FullDescription(), GUILayout.Width((_currentlyInvokingRect.width - indexColWidth) / 2.3f)); - _currentlyInvokingArgsValues[index] = GUILayout.TextField(_currentlyInvokingArgsValues[index], GUILayout.ExpandWidth(true)); + _currentlyInvokingArgsValues[index] = GUILayout.TextField(_currentlyInvokingArgsValues[index], IMGUIUtils.LayoutOptionsExpandWidthTrue); GUILayout.EndHorizontal(); } } @@ -547,7 +547,7 @@ private static void DrawInvokeWindowFunc(int id) GUILayout.BeginHorizontal(); GUILayout.Label("#" + index, GUILayout.Width(indexColWidth)); GUILayout.Label(parameter.ParameterType.FullDescription() + " " + parameter.Name, GUILayout.Width((_currentlyInvokingRect.width - indexColWidth) / 2.3f)); - _currentlyInvokingParamsValues[index] = GUILayout.TextField(_currentlyInvokingParamsValues[index], GUILayout.ExpandWidth(true)); + _currentlyInvokingParamsValues[index] = GUILayout.TextField(_currentlyInvokingParamsValues[index], IMGUIUtils.LayoutOptionsExpandWidthTrue); GUILayout.EndHorizontal(); } } @@ -559,8 +559,8 @@ private static void DrawInvokeWindowFunc(int id) GUILayout.BeginHorizontal(GUI.skin.box); { - GUILayout.Label("Invoke result: ", GUILayout.ExpandWidth(false)); - GUILayout.TextArea(_currentlyInvokingException != null ? _currentlyInvokingException.GetType().Name + " - " + _currentlyInvokingException.Message : _currentlyInvokingResult == null ? "None / NULL" : _currentlyInvokingResult.ToString(), GUI.skin.label, GUILayout.ExpandWidth(true)); + GUILayout.Label("Invoke result: ", IMGUIUtils.LayoutOptionsExpandWidthFalse); + GUILayout.TextArea(_currentlyInvokingException != null ? _currentlyInvokingException.GetType().Name + " - " + _currentlyInvokingException.Message : _currentlyInvokingResult == null ? "None / NULL" : _currentlyInvokingResult.ToString(), GUI.skin.label, IMGUIUtils.LayoutOptionsExpandWidthTrue); } GUILayout.EndHorizontal(); diff --git a/RuntimeUnityEditor/Windows/Profiler/ProfilerWindow.cs b/RuntimeUnityEditor/Windows/Profiler/ProfilerWindow.cs index 76f14d8..662497d 100644 --- a/RuntimeUnityEditor/Windows/Profiler/ProfilerWindow.cs +++ b/RuntimeUnityEditor/Windows/Profiler/ProfilerWindow.cs @@ -26,8 +26,6 @@ public sealed class ProfilerWindow : Window private static readonly GUILayoutOption[] _cRanW2 = { GUILayout.MinWidth(RanW), GUILayout.MaxWidth(RanW) }; private static readonly GUILayoutOption[] _cTicksW = { GUILayout.MinWidth(50), GUILayout.MaxWidth(50) }; private static readonly GUILayoutOption[] _cInsW = { GUILayout.MinWidth(50), GUILayout.MaxWidth(50) }; - private static readonly GUILayoutOption[] _expandW = { GUILayout.ExpandWidth(true) }; - private static readonly GUILayoutOption[] _expandWno = { GUILayout.ExpandWidth(false) }; private static readonly GUIContent _cColOrder = new GUIContent("#", "Relative order of execution in a frame. Methods are called one by one on the main unity thread in this order.\n\nMethods that did not run during this frame are also included, so this number does not equal how many methods were called on this frame."); private static readonly GUIContent _cColRan = new GUIContent("Ran", "Left toggle indicates if this method was executed in this frame (all Harmony patches were called, and the original method was called if not disabled by a Harmony patch).\n\nRight toggle indicates if the original method was executed (original method being skipped is usually caused by a false postfix in a Harmony patch)"); private static readonly GUIContent _cColTime = new GUIContent("Time", "Time spent executing this method (all Harmony patches included).\n\nBy default it's shown in ticks (smallest measurable unit of time). Resolution of ticks depends on Stopwatch.Frequency, but usually 10000 = 1ms.\n\nHigh values will drop FPS. If the value is much higher on some frames it can be felt as the game stuttering.\n\nIn methods running on every frame this should be as low as possible."); @@ -95,21 +93,21 @@ protected override void DrawContents() GUILayout.BeginHorizontal(); { - GUILayout.BeginHorizontal(GUI.skin.box, _expandW); + GUILayout.BeginHorizontal(GUI.skin.box, IMGUIUtils.LayoutOptionsExpandWidthTrue); { - GUILayout.Label("Search: ", _expandWno); - _searchText = GUILayout.TextField(_searchText, _expandW); - if (GUILayout.Button("Clear", _expandWno)) _searchText = ""; + GUILayout.Label("Search: ", IMGUIUtils.LayoutOptionsExpandWidthFalse); + _searchText = GUILayout.TextField(_searchText, IMGUIUtils.LayoutOptionsExpandWidthTrue); + if (GUILayout.Button("Clear", IMGUIUtils.LayoutOptionsExpandWidthFalse)) _searchText = ""; _searchHighlightMode = GUILayout.Toggle(_searchHighlightMode, "Highlight mode"); _searchCaseSensitive = GUILayout.Toggle(_searchCaseSensitive, "Case sensitive"); } GUILayout.EndHorizontal(); - GUILayout.BeginHorizontal(GUI.skin.box, _expandWno); + GUILayout.BeginHorizontal(GUI.skin.box, IMGUIUtils.LayoutOptionsExpandWidthFalse); { GUILayout.Label("Order: "); GUI.changed = false; - _ordering = GUILayout.SelectionGrid(_ordering, _orderingStrings, 4, _expandWno); + _ordering = GUILayout.SelectionGrid(_ordering, _orderingStrings, 4, IMGUIUtils.LayoutOptionsExpandWidthFalse); if (GUI.changed) _needResort = true; } GUILayout.EndHorizontal(); @@ -135,7 +133,7 @@ protected override void DrawContents() GUILayout.Label(_cColMem, _cGcW); if( _aggregation ) GUILayout.Label(_cColIns, _cInsW); - GUILayout.Label(_cColName, _expandW); + GUILayout.Label(_cColName, IMGUIUtils.LayoutOptionsExpandWidthTrue); } GUILayout.EndHorizontal(); @@ -201,7 +199,7 @@ protected override void DrawContents() } GUI.color = dispNameColor; - GUILayout.Label(pd.DisplayName, _expandW); //fullname + GUILayout.Label(pd.DisplayName, IMGUIUtils.LayoutOptionsExpandWidthTrue); //fullname GUI.color = origColor; GUILayout.FlexibleSpace(); diff --git a/RuntimeUnityEditor/Windows/REPL/REPLWindow.cs b/RuntimeUnityEditor/Windows/REPL/REPLWindow.cs index b4547f0..5b2a893 100644 --- a/RuntimeUnityEditor/Windows/REPL/REPLWindow.cs +++ b/RuntimeUnityEditor/Windows/REPL/REPLWindow.cs @@ -193,7 +193,7 @@ protected override void DrawContents() _completionsListingStyle.normal.textColor = Color.white; foreach (var snipplet in _savedSnipplets) { - if (GUILayout.Button(snipplet, GUI.skin.box, GUILayout.ExpandWidth(true))) + if (GUILayout.Button(snipplet, GUI.skin.box, IMGUIUtils.LayoutOptionsExpandWidthTrue)) { _inputField = snipplet; _snippletsShown = false; @@ -201,7 +201,7 @@ protected override void DrawContents() } } - if (GUILayout.Button(">> Edit snipplet list in external editor <<", GUI.skin.box, GUILayout.ExpandWidth(true))) + if (GUILayout.Button(">> Edit snipplet list in external editor <<", GUI.skin.box, IMGUIUtils.LayoutOptionsExpandWidthTrue)) { AppendLogLine("Opening snipplet file at " + _snippletFilename); @@ -218,7 +218,7 @@ protected override void DrawContents() foreach (var suggestion in _suggestions) { _completionsListingStyle.normal.textColor = suggestion.GetTextColor(); - if (GUILayout.Button(suggestion.Full, _completionsListingStyle, GUILayout.ExpandWidth(true))) + if (GUILayout.Button(suggestion.Full, _completionsListingStyle, IMGUIUtils.LayoutOptionsExpandWidthTrue)) { AcceptSuggestion(suggestion.Addition); break; @@ -252,10 +252,10 @@ protected override void DrawContents() _refocusCursorIndex = -1; } - if (GUILayout.Button("Run", GUILayout.ExpandWidth(false))) + if (GUILayout.Button("Run", IMGUIUtils.LayoutOptionsExpandWidthFalse)) AcceptInput(); - if (GUILayout.Button(_snippletsShown ? "Cancel" : (_inputField.Length == 0 ? "Load" : "Save"), GUILayout.ExpandWidth(false))) + if (GUILayout.Button(_snippletsShown ? "Cancel" : (_inputField.Length == 0 ? "Load" : "Save"), IMGUIUtils.LayoutOptionsExpandWidthFalse)) { if (_snippletsShown) { @@ -285,7 +285,7 @@ protected override void DrawContents() } } - if (GUILayout.Button("Autostart", GUILayout.ExpandWidth(false))) + if (GUILayout.Button("Autostart", IMGUIUtils.LayoutOptionsExpandWidthFalse)) { AppendLogLine("Opening autostart file at " + _autostartFilename); @@ -298,7 +298,7 @@ protected override void DrawContents() ScrollToBottom(); } - if (GUILayout.Button("History", GUILayout.ExpandWidth(false))) + if (GUILayout.Button("History", IMGUIUtils.LayoutOptionsExpandWidthFalse)) { AppendLogLine(""); AppendLogLine("# History of executed commands:"); diff --git a/RuntimeUnityEditor/Windows/Taskbar.cs b/RuntimeUnityEditor/Windows/Taskbar.cs index d3081c8..47b0c90 100644 --- a/RuntimeUnityEditor/Windows/Taskbar.cs +++ b/RuntimeUnityEditor/Windows/Taskbar.cs @@ -98,11 +98,11 @@ private void DrawTaskbar(int id) GUILayout.Label("|"); - GUILayout.Label("Time", GUILayout.ExpandWidth(false)); + GUILayout.Label("Time", IMGUIUtils.LayoutOptionsExpandWidthFalse); - if (GUILayout.Button(">", GUILayout.ExpandWidth(false))) + if (GUILayout.Button(">", IMGUIUtils.LayoutOptionsExpandWidthFalse)) Time.timeScale = 1; - if (GUILayout.Button("||", GUILayout.ExpandWidth(false))) + if (GUILayout.Button("||", IMGUIUtils.LayoutOptionsExpandWidthFalse)) Time.timeScale = 0; if (float.TryParse(GUILayout.TextField(Time.timeScale.ToString("F2", CultureInfo.InvariantCulture), GUILayout.Width(38)), NumberStyles.Any, CultureInfo.InvariantCulture, out var newVal)) @@ -114,7 +114,7 @@ private void DrawTaskbar(int id) GUILayout.Label("|"); - if (GUILayout.Button("Log", GUILayout.ExpandWidth(false))) + if (GUILayout.Button("Log", IMGUIUtils.LayoutOptionsExpandWidthFalse)) UnityFeatureHelper.OpenLog(); AssetBundleManagerHelper.DrawButtonIfAvailable();