How does GUIStyle.CalcSize() work?

I want to know how big a GUI.Box should be in order to perfectly contain a given text, while keeping in mind the content offset, padding, etc. Is there an easy way? I’ve tried with GUIStyle.CalcSize(new GUIContent(text)) but I get very weird values, so I don’t know if this is the purpose of this function. Is there any other? I could get this working with something to get the pixel width and height of a given text given the current Font, if that’s easier.

What is the result you want to achieve? Maybe using GUILayout would be easier, unless you have some specific requirements.
If I’m not mistaken, GUILayout.Window will resize itself based on what you put in it.

That is the purpose of that function. Note that if you have a wordwrapping style, the whole process gets a lot more complex (where do you introduce wordwraps?), but thats the one used by GUILayout behind the scenes.

It’s a question related to this post. I want to know the size of the bubble before creating it, keeping in mind the text that will be inside.

In that case, try using GUILayout - it will let you do all this easily - inside a scrollview, etc…

As nicholas pointed out, wordWrap was causing me problems, now it all works fine. Thnaks!