I’m not even sure if it is possible to do this.
I’m creating a GUILayout.Window that contains a single GUILayout.Label.
I’m trying to get the window to wrap around the label, so to speak.
Here is my code:
using UnityEngine;
using System.Collections;
public class Fail : MonoBehaviour
{
Rect R;
void Awake( )
{
// as per http://forum.unity3d.com/threads/59048-GUI-Window-problems
// start by positioning window offscreen, size = (1,1)
// the first repaint event will adjust this rectangle
R = new Rect( Screen.width+1, Screen.height+1, 1, 1 );
}
bool first = true;
void OnGUI( )
{
Rect R_out = GUILayout.Window(
1
, R
, WindowFunc
, "Test Window"
, GUILayout.ExpandWidth( true )
);
Debug.Log(
Event.current.type.ToString( )
+ ", " + R.ToString( )
+ ", " + R_out.ToString( )
);
if( first ( Event.current.type == EventType.Repaint ) ) {
R.x = 100;
R.y = 50;
R.width = R_out.width;
R.height = R_out.height;
first = false;
}
}
void WindowFunc( int id )
{
GUILayout.Label( "Foo 1 2 3 4 5 6 7" );
}
}
And here is the output:
It should be drawing the label on a single line, rather than splitting it over several lines.
Of course, that code looks conceptually wrong. Conceptually it would make sense for EventType.Layout to calculate the rectangle, instead of EventType.Repaint. But changing it makes no difference.
Also GUILayout.Label( “Foo 1 2 3 4 5 6 7”, GUILayout.ExpandWidth( true ) ); makes no difference.
Can anyone get this to work?
π
EDIT:
If I do this:
R.width = 150; // R_out.width;
R.height = 80; // R_out.height;
… it DOES work.