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

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 ’
’ in the text, not the width I provide

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

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);