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:
Here is some code. This function is called after all of my widgets have been drawn. Some widgets specify a tooltip, some don't.
Anyone know how I can get this working properly?
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.
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).
answered May 21 '10 at 04:27 PM