- Home /
GUIStyle.CalcHeight return value too small
Hi guys, I am trying to draw a Box with the some wrap text
string test = "some wrapped text\n other text";
float dynamicSize = skin.box.CalcHeight(new GUIContent(test), 200);
GUI.Box(new Rect(Event.current.mousePosition.x + 10, Event.current.mousePosition.y,200,dynamicSize), test, skin.GetStyle("ToolTip"))
Looks like it calculates the height according to how many '\n' in the text, not the width I provide
I think I'm blind, but where is the text in your screenshot?
The screenshot seems to be wrong. Still impossible to find a box with "some wrapped text\n other text"
Answer by Bunny83 · Aug 09, 2018 at 11:41 AM
Uhm you used a completely different GUIStyle when calculating your size:
float dynamicSize = skin.box.CalcHeight(new GUIContent(test), 200);
You used the default "box" GUIStyle from that skin whereas when you draw your GUI.Box you use your custom style. You should do something like this:
GUI.skin = skin; // make your skin active
GUIStyle style = "ToolTip";
string test = "some wrapped text\n other text";
float dynamicSize = style.CalcHeight(new GUIContent(test), 200);
Vector2 pos = Event.current.mousePosition;
GUI.Box(new Rect(pos.x + 10, pos.y, 200, dynamicSize), test, style);
Your answer
Follow this Question
Related Questions
Null exception when drawing a rectangle 1 Answer
JS changing gui box color 1 Answer
Rotating a Rect by the GUI.matrix? 0 Answers
New GUI - Text not rendering in front of geometry if using a Mask 1 Answer
How to GUI texture image change? 1 Answer