GUIStyle.CalcSize appears to break when your style specifies padding

I have a GUIStyle derived from

I set a few properties on that style such as the alignment and fontsize, then I iterate through fonts sizes until I find the largest font that will fit my rect.

This works great, right up until the point I put padding around the label, then CalcSize goes beserk returning back heights that are orders of magnitude larger than the actual height.

l_oLabelStyle.alignment = TextAnchor.MiddleCenter;
l_oLabelStyle.fontSize = 36;

The above has no problems with CalcSize.

l_oLabelStyle.padding = new RectOffset( 30, 30, 30, 30 );

The line above causes everything to go haywire. The CalcSize seems to be returning back a reasonable width in this case, but the height is astronomically large.

Without touching the padding, I get back a reasonable height of 47.

With padding I get 3936 for the height…

Other caveats are that I am using setting GUI.matrix elsewhere to scale my GUI code to the runtime resolution. The scale is roughly 0.5 on X and Y.

Anybody run into this before?

Seems like I misunderstood the relationship between CalcSize and CalcHeight. It seems like you should either use CalcSize or both together, but in reality, you simply use CalcHeight unless you can’t word wrap.

Issues resolved now. I was confused because of the odd difference in data types they return.