- Home /
GUIStyle.CalcHeight return value too short.
I'm trying to use GUIStyle.CalcHeight with my own GUIStyle, for some multi-line wordwrapped labels. Normally the number comes out too short and the last line, or the bottom of a single line of text gets clipped. If I add a background texture then it seems like most of the time the height returned works fine. I don't want to just overflow the text, beause then it might overlap the next label down.
It also doesn't seem to properly account for the font style being set to bold.
Is there a way to get accurate height?
Try adding a background texture with one pixel and zero alpha.
At the moment I'm just multiplying the result by 1.2 and using that. Seems to work.
CalcHeight should work, although it did take some fiddling until I used it correctly. Can you show the code you're using with it?
Are you adding the border values for the style to the height returned by CalcHeight? I seem to remember having to do that at one time.
Unity4.3 still has issues with CalcHeight - I had to use preprocessor directive depending on UNITY_EDITOR or standalone, subtracting 1 from CalcHeight for editor (not sure why i have to, but it works) - very important given this value is used to calculate a scrollview.Height and scrollPosition.y as part of a GUI selection method. Possibly this arbitrary -1 changes depending on fontsize - that works for fontsize 9 anyway
e.g.
#if UNITY_EDITOR
Debug.Log("Unity Editor");
rowHeight=(int)popupNormal.CalcHeight(new GUIContent(""),10)-1;
#else
Debug.Log("Unity Standalone");
rowHeight=(int)popupNormal.CalcHeight(new GUIContent(""),10);
Your answer
Follow this Question
Related Questions
GUIStyle textures pixelated, but appears smooth for GUISkin 1 Answer
Add an image/texture to a custom editorwindow 0 Answers
Changing OnGUI Texture to be behind another (GUI Rendered off of same script, different instance) 2 Answers
Understanding GUISkin/GUIStyle BackgroundImage and Border 2 Answers
GUI Style Issue-- Texture not changing 2 Answers