Dear GUI friends, I was surprised to find that:
void OnGUI()
{
ww = GUILayout.Window(0, ww, Facts, "Title:");
}
private void Facts(int windowID)
{
GUILayout.BeginVertical();
GUILayout.Label( "label words here");
GUILayout.Label( "label words here");
... versus ...
GUILayout.Button("button words here");
GUILayout.Button("button words here");
GUILayout.EndVertical();
GUI.DragWindow();
}
in the example, It will “know” how wide the button is going to be, and it will make the window wide enough so that the text on the button does not break. However, with GUILayout.Label, it DOES break the words, i.e. it does not automatically set the width wide enough.
How to fix?
(I appreciate that you could add, say GUILayout.Width(250) but I want it to work automatically exactly as it does with buttons. Also, note that ExpandWidth(true) is irrelevant to this issue, it relates to resizing floating windows.)