Skip to content

Commit 532526d

Browse files
authored
Use cached GUILayout.ExpandWidth wherever possible (#77)
1 parent 3921096 commit 532526d

File tree

12 files changed

+84
-85
lines changed

12 files changed

+84
-85
lines changed

RuntimeUnityEditor.Bepin5/LogViewer/LogViewerEntry.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ public bool DrawEntry()
5252
{
5353
GUI.color = GetColor();
5454
var clicked = GUILayout.Button(_timeString, GUI.skin.label, GUILayout.MinWidth(35));
55-
GUILayout.Label("[", GUILayout.ExpandWidth(false));
55+
GUILayout.Label("[", IMGUIUtils.LayoutOptionsExpandWidthFalse);
5656
clicked |= GUILayout.Button(_logLevelString, GUI.skin.label, GUILayout.MinWidth(45));
57-
GUILayout.Label(":", GUILayout.ExpandWidth(false));
57+
GUILayout.Label(":", IMGUIUtils.LayoutOptionsExpandWidthFalse);
5858
clicked |= GUILayout.Button(_sourceNameString, GUI.skin.label, GUILayout.MinWidth(100));
59-
GUILayout.Label("]", GUILayout.ExpandWidth(false));
59+
GUILayout.Label("]", IMGUIUtils.LayoutOptionsExpandWidthFalse);
6060
GUI.color = Color.white;
61-
clicked |= GUILayout.Button(_dataString, GUI.skin.label, GUILayout.ExpandWidth(true));
61+
clicked |= GUILayout.Button(_dataString, GUI.skin.label, IMGUIUtils.LayoutOptionsExpandWidthTrue);
6262
return clicked;
6363
}
6464

RuntimeUnityEditor.Bepin5/LogViewer/LogViewerWindow.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,19 +143,19 @@ protected override void DrawContents()
143143
{
144144
GUILayout.BeginHorizontal();
145145
{
146-
GUILayout.BeginHorizontal(GUI.skin.box, GUILayout.ExpandWidth(true));
146+
GUILayout.BeginHorizontal(GUI.skin.box, IMGUIUtils.LayoutOptionsExpandWidthTrue);
147147
{
148148
GUI.changed = false;
149149
var searchString = SearchString;
150150
var isEmpty = string.IsNullOrEmpty(searchString) && GUI.GetNameOfFocusedControl() != "sbox";
151151
if (isEmpty) GUI.color = Color.gray;
152152
GUI.SetNextControlName("sbox");
153-
var newString = GUILayout.TextField(isEmpty ? "Search log text and stack traces..." : searchString, GUILayout.ExpandWidth(true));
153+
var newString = GUILayout.TextField(isEmpty ? "Search log text and stack traces..." : searchString, IMGUIUtils.LayoutOptionsExpandWidthTrue);
154154
if (GUI.changed) SearchString = newString;
155155
GUI.color = Color.white;
156156
}
157157
GUILayout.EndHorizontal();
158-
GUILayout.BeginHorizontal(GUI.skin.box, GUILayout.ExpandWidth(false));
158+
GUILayout.BeginHorizontal(GUI.skin.box, IMGUIUtils.LayoutOptionsExpandWidthFalse);
159159
{
160160
if (!Capture) GUI.color = Color.red;
161161
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()
240240
}
241241
}
242242

243-
if (entry.Sender != null && GUILayout.Button("Inspect", GUILayout.ExpandWidth(false)))
243+
if (entry.Sender != null && GUILayout.Button("Inspect", IMGUIUtils.LayoutOptionsExpandWidthFalse))
244244
Inspector.Instance.Push(new InstanceStackEntry(entry, entry.LogEventArgs.Source.SourceName + " -> Log entry"), true);
245245

246246
DnSpyHelper.DrawDnSpyButtonIfAvailable(entry.Method, new GUIContent("^", $"In dnSpy, attempt to navigate to the method that produced this log message:\n\n{entry.Method.GetFancyDescription()}"));

RuntimeUnityEditor.UMM/RuntimeUnityEditorSettings.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.IO;
44
using System.Xml;
55
using System.Xml.Serialization;
6+
using RuntimeUnityEditor.Core.Utils;
67
using UnityEngine;
78
using UnityModManagerNet;
89
#pragma warning disable CS0618
@@ -120,7 +121,7 @@ public void Draw(UnityModManager.ModEntry entry)
120121
}
121122
else if (setting is Setting<UnityEngine.KeyCode> keycodeSetting)
122123
{
123-
GUILayout.Label(settingName, GUILayout.ExpandWidth(false));
124+
GUILayout.Label(settingName, IMGUIUtils.LayoutOptionsExpandWidthFalse);
124125

125126
var value = new KeyBinding() { keyCode = keycodeSetting.Value };
126127
if (UnityModManager.UI.DrawKeybinding(ref value, settingName)) keycodeSetting.Value = value.keyCode;
@@ -129,9 +130,9 @@ public void Draw(UnityModManager.ModEntry entry)
129130
else if (setting is Setting<string> stringSetting)
130131
{
131132
GUILayout.BeginVertical();
132-
GUILayout.Label(settingName, GUILayout.ExpandWidth(false));
133+
GUILayout.Label(settingName, IMGUIUtils.LayoutOptionsExpandWidthFalse);
133134

134-
var value = GUILayout.TextField(stringSetting.Value, GUILayout.ExpandWidth(true));
135+
var value = GUILayout.TextField(stringSetting.Value, IMGUIUtils.LayoutOptionsExpandWidthTrue);
135136
if (value != stringSetting.Value) stringSetting.Value = value;
136137
GUILayout.EndVertical();
137138
}

RuntimeUnityEditor/Features/ContextMenu.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ public void Show(object obj, MemberInfo objMemberInfo, Vector2 clickPoint)
213213
/// </summary>
214214
public void DrawContextButton(object obj, MemberInfo objMemberInfo)
215215
{
216-
if (obj != null && GUILayout.Button("...", GUILayout.ExpandWidth(false)))
216+
if (obj != null && GUILayout.Button("...", IMGUIUtils.LayoutOptionsExpandWidthFalse))
217217
Show(obj, objMemberInfo);
218218
}
219219

RuntimeUnityEditor/Utils/Abstractions/DnSpyHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ void IFeature.OnEditorShownChanged(bool visible) { }
181181
private static readonly GUIContent _guiContent = new GUIContent("^", "Navigate to this member in dnSpy");
182182
internal static void DrawDnSpyButtonIfAvailable(MemberInfo mi, GUIContent customButtonContent = null)
183183
{
184-
if (IsAvailable && GUILayout.Button(customButtonContent ?? _guiContent, GUILayout.ExpandWidth(false)))
184+
if (IsAvailable && GUILayout.Button(customButtonContent ?? _guiContent, IMGUIUtils.LayoutOptionsExpandWidthFalse))
185185
OpenInDnSpy(mi);
186186
}
187187
}

RuntimeUnityEditor/Windows/ChangeHistory/ChangeHistoryWindow.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ protected override void DrawContents()
8787
GUI.color = Color.white;
8888
}
8989

90-
GUILayout.TextField(change.GetDisplayString(), GUI.skin.label, GUILayout.ExpandWidth(true));
90+
GUILayout.TextField(change.GetDisplayString(), GUI.skin.label, IMGUIUtils.LayoutOptionsExpandWidthTrue);
9191

92-
if (change.CanUndo && GUILayout.Button(_undoContent, GUILayout.ExpandWidth(false)))
92+
if (change.CanUndo && GUILayout.Button(_undoContent, IMGUIUtils.LayoutOptionsExpandWidthFalse))
9393
{
9494
try
9595
{
@@ -101,7 +101,7 @@ protected override void DrawContents()
101101
}
102102
}
103103

104-
if (!change.Target.IsNullOrDestroyed() && GUILayout.Button(_inspectContent, GUILayout.ExpandWidth(false)))
104+
if (!change.Target.IsNullOrDestroyed() && GUILayout.Button(_inspectContent, IMGUIUtils.LayoutOptionsExpandWidthFalse))
105105
Inspector.Inspector.Instance.Push(new InstanceStackEntry(change.Target, change.GetDisplayString()), true);
106106
}
107107
GUILayout.EndHorizontal();

RuntimeUnityEditor/Windows/Clipboard/ClipboardWindow.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ protected override void DrawContents()
4040
GUILayout.FlexibleSpace();
4141
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" +
4242
"Clipboard contents can be used in REPL by running the 'paste(index)' command, or in inspector when invoking a method.\n\n" +
43-
"Press 'X' to remove item from clipboard, right click on it to open a menu with more options.", GUILayout.ExpandWidth(true));
43+
"Press 'X' to remove item from clipboard, right click on it to open a menu with more options.", IMGUIUtils.LayoutOptionsExpandWidthTrue);
4444
GUILayout.FlexibleSpace();
4545
}
4646
GUILayout.EndVertical();
@@ -57,7 +57,7 @@ protected override void DrawContents()
5757
{
5858
GUILayout.Label("Index", GUILayout.Width(widthIndex), GUILayout.ExpandWidth(false));
5959
GUILayout.Label("Type", GUILayout.Width(widthName), GUILayout.ExpandWidth(false));
60-
GUILayout.Label("Value", GUILayout.ExpandWidth(true));
60+
GUILayout.Label("Value", IMGUIUtils.LayoutOptionsExpandWidthTrue);
6161
}
6262
GUILayout.EndHorizontal();
6363

@@ -78,7 +78,7 @@ protected override void DrawContents()
7878
var prevEnabled = GUI.enabled;
7979
GUI.enabled = type != null && typeof(IConvertible).IsAssignableFrom(type);
8080
GUI.changed = false;
81-
var newVal = GUILayout.TextField(ToStringConverter.ObjectToString(content), GUILayout.ExpandWidth(true));
81+
var newVal = GUILayout.TextField(ToStringConverter.ObjectToString(content), IMGUIUtils.LayoutOptionsExpandWidthTrue);
8282
if (GUI.changed && type != null)
8383
{
8484
try
@@ -93,7 +93,7 @@ protected override void DrawContents()
9393

9494
GUI.enabled = prevEnabled;
9595

96-
if (GUILayout.Button("X", GUILayout.ExpandWidth(false)))
96+
if (GUILayout.Button("X", IMGUIUtils.LayoutOptionsExpandWidthFalse))
9797
Contents.RemoveAt(index);
9898
}
9999
GUILayout.EndHorizontal();

RuntimeUnityEditor/Windows/Inspector/Inspector.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,12 @@ protected override void DrawContents()
185185
{
186186
GUILayout.BeginHorizontal();
187187
{
188-
GUILayout.BeginHorizontal(GUI.skin.box, GUILayout.ExpandWidth(true));
188+
GUILayout.BeginHorizontal(GUI.skin.box, IMGUIUtils.LayoutOptionsExpandWidthTrue);
189189
{
190-
GUILayout.Label("Filter:", GUILayout.ExpandWidth(false));
190+
GUILayout.Label("Filter:", IMGUIUtils.LayoutOptionsExpandWidthFalse);
191191

192192
GUI.SetNextControlName(SearchBoxName);
193-
SearchString = GUILayout.TextField(SearchString, GUILayout.ExpandWidth(true));
193+
SearchString = GUILayout.TextField(SearchString, IMGUIUtils.LayoutOptionsExpandWidthTrue);
194194

195195
if (_focusSearchBox)
196196
{
@@ -206,7 +206,7 @@ protected override void DrawContents()
206206
_showDeclaredOnly = GUILayout.Toggle(_showDeclaredOnly, "Only declared");
207207

208208
/* todo
209-
GUILayout.Label("Find:", GUILayout.ExpandWidth(false));
209+
GUILayout.Label("Find:", IMGUIUtils.LayoutOptionsExpandWidthFalse);
210210
foreach (var obj in new[]
211211
{
212212
new KeyValuePair<object, string>(EditorUtilities.GetInstanceClassScanner().OrderBy(x => x.Name()), "Instances"),
@@ -217,7 +217,7 @@ protected override void DrawContents()
217217
})
218218
{
219219
if (obj.Key == null) continue;
220-
if (GUILayout.Button(obj.Value, GUILayout.ExpandWidth(false)))
220+
if (GUILayout.Button(obj.Value, IMGUIUtils.LayoutOptionsExpandWidthFalse))
221221
Push(new InstanceStackEntry(obj.Key, obj.Value), true);
222222
}*/
223223
}
@@ -257,7 +257,7 @@ protected override void DrawContents()
257257
if (currentTab == tab)
258258
GUI.backgroundColor = Color.cyan;
259259

260-
if (GUILayout.Button($"Tab {index + 1}: {LimitStringLengthForPreview(tab?.CurrentStackItem?.Name, 18)}", GUILayout.ExpandWidth(false)))
260+
if (GUILayout.Button($"Tab {index + 1}: {LimitStringLengthForPreview(tab?.CurrentStackItem?.Name, 18)}", IMGUIUtils.LayoutOptionsExpandWidthFalse))
261261
{
262262
// todo custom context menu for the tab bar? IMGUIUtils.IsMouseRightClick()
263263
if (IMGUIUtils.IsMouseWheelClick())
@@ -293,7 +293,7 @@ protected override void DrawContents()
293293
if (stackEntry == currentTab.CurrentStackItem)
294294
GUI.backgroundColor = Color.cyan;
295295

296-
if (GUILayout.Button(LimitStringLengthForPreview(stackEntry.Name, 90), GUILayout.ExpandWidth(false)))
296+
if (GUILayout.Button(LimitStringLengthForPreview(stackEntry.Name, 90), IMGUIUtils.LayoutOptionsExpandWidthFalse))
297297
{
298298
if (IMGUIUtils.IsMouseRightClick())
299299
stackEntry.ShowContextMenu();
@@ -305,7 +305,7 @@ protected override void DrawContents()
305305
}
306306

307307
if (i + 1 < stackEntries.Length)
308-
GUILayout.Label(">", GUILayout.ExpandWidth(false));
308+
GUILayout.Label(">", IMGUIUtils.LayoutOptionsExpandWidthFalse);
309309

310310
GUI.backgroundColor = defaultGuiColor;
311311
}
@@ -322,7 +322,7 @@ protected override void DrawContents()
322322
GUILayout.Space(2);
323323
GUILayout.Label("Member name", GUI.skin.box, _inspectorNameWidth);
324324
GUILayout.Space(1);
325-
GUILayout.Label("Value", GUI.skin.box, GUILayout.ExpandWidth(true));
325+
GUILayout.Label("Value", GUI.skin.box, IMGUIUtils.LayoutOptionsExpandWidthTrue);
326326
}
327327
GUILayout.EndHorizontal();
328328

@@ -451,7 +451,7 @@ private void DrawSingleContentEntry(ICacheEntry entry)
451451
catch (Exception ex)
452452
{
453453
RuntimeUnityEditorCore.Logger.Log(LogLevel.Error, $"[{Title}] Failed to draw setting {entry?.Name()} - {ex.Message}");
454-
GUILayout.TextArea(ex.Message, GUI.skin.label, GUILayout.ExpandWidth(true));
454+
GUILayout.TextArea(ex.Message, GUI.skin.label, IMGUIUtils.LayoutOptionsExpandWidthTrue);
455455
}
456456
}
457457
GUILayout.EndHorizontal();

0 commit comments

Comments
 (0)