Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by paprocjo · Nov 28, 2012 at 09:30 PM · c#guilayoutguistylegui.labelwordwrap

[SOLVED]GUIStyle Word Wrap Check

Hey everyone!

I have custom GUIStyle set up to use wordwrap and I was wondering if there is anyway to check to see if a Label gets wrapped so it will move the next label below it out of the way.

I want to maintain good spacing between the lines that get displayed. Am I going about this the wrong way?

Here is an example of my issue: alt text

Here is my code if that helps at all!

         GUI.Label(new Rect(Screen.width/1.9f, hieght, 400, 30),question1, Question);
 
         GUI.Label(new Rect(Screen.width / 1.9f, hieght + 50, 500, 50), answer1, Answer);
 
         GUI.Label(new Rect(Screen.width / 1.9f, hieght + 150, 500, 50), question2, Question);
 
         GUI.Label(new Rect(Screen.width / 1.9f, hieght + 200, 500, 50), answer2, Answer);
 
         GUI.Label(new Rect(Screen.width / 1.9f, hieght + 300, 500, 50), question3, Question);
 
         GUI.Label(new Rect(Screen.width / 1.9f, hieght + 350, 500, 50), answer3, Answer);
 

Thanks for looking!

EDIT: Final Code

 void OnGUI()
     {
         GUI.skin = Skin;
         GUIStyle Question = Skin.customStyles[0];
         GUIStyle Answer = Skin.customStyles[1];
         
 
         if (isOn == true)
         {
 
             string question1 = getQuestion1();
             string question2 = getQuestion2();
             string question3 = getQuestion3();
             string answer1 = getAnswer1();
             string answer2 = getAnswer2();
             string answer3 = getAnswer3();
             hieght = (Screen.height / 4);
             GUILayout.BeginArea(new Rect(Screen.width / 1.9f, hieght, 400, 1000));
             //GUI.BeginGroup(new Rect(Screen.width/1.9f, hieght, 100, 100));
             GUILayout.Label(question1, Question);
             GUILayout.Space(10);
             GUILayout.Label(answer1, Answer);
             GUILayout.Space(30);
             GUILayout.Label(question2, Question);
             GUILayout.Space(10);
             GUILayout.Label(answer2, Answer);
             GUILayout.Space(30);
             GUILayout.Label(question3, Question);
             GUILayout.Space(10);
             GUILayout.Label(answer3, Answer);
             GUILayout.EndArea();
             //GUI.EndGroup();
         }

help.jpg (68.8 kB)
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Loius · Nov 28, 2012 at 10:21 PM 2
Share

The GUILayout class will space itself automatically based on settings you apply to it. I don't know of a way to detect word wrapping though.

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Mortoc · Nov 28, 2012 at 10:28 PM

You can use the GUIStyle.CalcHeight function for this: http://docs.unity3d.com/Documentation/ScriptReference/GUIStyle.CalcHeight.html

I'm assuming that the variable 'Answer' is your GUIStyle and 'answer1' is your string. You can figure out the different sizes of the typed in text something like this:

 float oneLineHeight = Answer.CalcHeight(new GUIContent(""), 500);
 float answerHeight = Answer.CalcHeight(new GUIContent(answer1), 500);
Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Nov 28, 2012 at 11:34 PM 2
Share

Yes this does work, however i like GUILayout much more ;) It automatically sizes every element but you can override most things if you want. See the last 8 functions of GUILayout

avatar image Mortoc · Nov 28, 2012 at 11:44 PM 1
Share

Agreed, especially for a simple GUI layout. I generally use GUI for pixel perfect things like HUDs. GUILayout works better for simple layouts like this. I'd go with GUILayout if I were you paprocjo.

avatar image paprocjo · Nov 29, 2012 at 03:38 PM 0
Share

Ok! I am looking into GUILayout as we speak! I will report back later! Thanks for pointing me in the right direction!

avatar image paprocjo · Nov 29, 2012 at 05:03 PM 0
Share

GUILayout did the trick perfectly!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

13 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

ArgumentException: Getting control 1's position... 0 Answers

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

GUILayout.Label - WordWrap and FontSize issue. 2 Answers

Can you use GUIStyle with GUILayout? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges