Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How does GUIStyle.CalcSize() work?

Discussion in 'Immediate Mode GUI (IMGUI)' started by manuelflara, Nov 27, 2007.

  1. manuelflara

    manuelflara

    Joined:
    Jan 21, 2007
    Posts:
    87
    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.
     
  2. shaun

    shaun

    Joined:
    Mar 23, 2007
    Posts:
    728
    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.
     
  3. NicholasFrancis

    NicholasFrancis

    Joined:
    Apr 8, 2005
    Posts:
    1,587
    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.
     
  4. manuelflara

    manuelflara

    Joined:
    Jan 21, 2007
    Posts:
    87
    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.
     
  5. NicholasFrancis

    NicholasFrancis

    Joined:
    Apr 8, 2005
    Posts:
    1,587
    In that case, try using GUILayout - it will let you do all this easily - inside a scrollview, etc...
     
  6. manuelflara

    manuelflara

    Joined:
    Jan 21, 2007
    Posts:
    87
    As nicholas pointed out, wordWrap was causing me problems, now it all works fine. Thnaks!