Trouble with implementing tooltip with GUILayout

My goal here is to use GUILayout to render a label that has a background that automatically resizes itself to fit its contents (the text). This the only way that I know of to make sure the background texture is as long as the text.

This label will serve as a tooltip that follows the mouse cursor. There's two main problems here:

  1. There is no way (that I can see) to provide a position for GUILayout.Label without specifying its dimensions. I've tried GUILayout.BeginArea() but it forces the label to be the same size as the area and does not dynamically size.
  2. Even when I don't use an Area, I still can't get the label's width to automatically adjust based on the amount of text it has.

Here is some code. This function is called after all of my widgets have been drawn. Some widgets specify a tooltip, some don't.

void DrawTooltip()
{
    float width = 300;
    float height = 50;

    Vector2 pos = UIManager.MousePosition;
    pos.x -= Rect.x;
    pos.y = pos.y - height - Rect.y;

    GUIStyle style = UIManager.Instance.TooltipStyle;
    style.alignment = TextAnchor.LowerLeft;

    GUILayout.BeginArea( new Rect( pos.x, pos.y, width, height ) );
    {
        GUILayout.BeginHorizontal();
        {
            GUILayout.Label( GUI.tooltip, style );
            GUILayout.FlexibleSpace();
        }
        GUILayout.EndHorizontal();
    }
    GUILayout.EndArea();
}

Anyone know how I can get this working properly?

UPDATE

I figured out why this isn't working. Apparently GUI.tooltip is an empty string when OnGUI is called for Layout only (Check Event.current.type for the "Layout" event). However, on the repaint event, it is the valid tooltip. Because the string (GUI.tooltip) is empty during layout, the widgets cannot size to their content properly.

What you've got seems pretty close, but you might also need to add some flexible space to the vertical, e.g.

GUILayout.BeginArea( new Rect( pos.x, pos.y, width, height ) );
{
  GUILayout.BeginVertical();
  {
    GUILayout.BeginHorizontal();
    {
      GUILayout.Label( GUI.tooltip, style );
      GUILayout.FlexibleSpace();
    }
    GUILayout.EndHorizontal();
    GUILayout.FlexibleSpace();
  }
  GUILayout.EndVertical();
}
GUILayout.EndArea();

If the width of the label still does not adjust, make sure your style has "fixedWidth" set to 0 (i.e. no fixed width, allow adjustment).