GUILayout.Label not full width? ie, words break

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.)

#By default the attribute word wrap of the skin style is false for the button and true for the label.

.
In this case the label will be as large as the parent and wrap if necessary but the GUILayout.Window again will be as large as the content if no Rect is defined - and so it will collapse to the minimum possible.

You either want to set label to word wrap false or define a size for the window.


[Ed] To create such a style in code:

	GUIStyle nonbreakingLabelStyle;
	nonbreakingLabelStyle = new GUIStyle();
	nonbreakingLabelStyle.wordWrap = false;
	nonbreakingLabelStyle.normal.textColor = Color.white;

Then, just add these to the end of GUILabel …

GUILayout.Label( "many words many words" ,nonbreakingLabelStyle );