Problem (bug ?) with GUILayout.Window and GUILayout.BeginArea

If I use this:

using UnityEngine;
using System.Collections;

public class GUIcode : MonoBehaviour {
    public Rect windowRect = new Rect(20, 20, 500, 500);
    void OnGUI()
    {
        windowRect = GUILayout.Window(0, windowRect, DoMyWindow, "My Window");
    }
    void DoMyWindow(int windowID)
    {
        GUI.DragWindow(new Rect(0, 0, 10000, 20));

        GUILayout.Label("This is a label");
        GUILayout.Label("Another label");
        GUILayout.HorizontalSlider(500, 0, 1000);

     }
}

I get a nice Window.

But if I add GUILayout.BeginArea (and End) functions, the window shrinks to a dot:

using UnityEngine;
using System.Collections;

public class GUIcode : MonoBehaviour {
    public Rect windowRect = new Rect(20, 20, 500, 500);
    void OnGUI()
    {
        windowRect = GUILayout.Window(0, windowRect, DoMyWindow, "My Window");
    }
    void DoMyWindow(int windowID)
    {
        GUI.DragWindow(new Rect(0, 0, 10000, 20));

        GUILayout.BeginArea(new Rect(10,10,200,200));
        GUILayout.Label("This is a label");
        GUILayout.Label("Another label");
        GUILayout.HorizontalSlider(500, 0, 1000);
        GUILayout.EndArea();
     }
}

Is this a bug or am I doing something wrong?

The answer by Bunny83 in this thread should shed some light on the problem.

Basically (from what I understand), when you call BeginArea it starts a new layout group that the Window knows nothing about, and therefore thinks it contains no content.

You could try using GUILayoutUtility.GetRect to “carve out” the space for your area.
Something like this:

using UnityEngine;
using System.Collections;

public class GUIcode : MonoBehaviour 
{
	public Rect windowRect = new Rect(20, 20, 500, 500);

	private Rect areaRect = new Rect(10,10,200,200);

	void OnGUI()
	{
		windowRect = GUILayout.Window(0, windowRect, DoMyWindow, "My Window");
	}

	void DoMyWindow(int windowID)
	{
		GUI.DragWindow(new Rect(0, 0, 10000, 20));

		GUILayoutUtility.GetRect(areaRect.width, areaRect.height);
		GUILayout.BeginArea(areaRect);
		GUILayout.Label("This is a label");
		GUILayout.Label("Another label");
		GUILayout.HorizontalSlider(500, 0, 1000);		
		GUILayout.EndArea();
	}
}