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
0
Question by judy3turn · Aug 17, 2012 at 10:12 PM · guilayout

GUILayout.Space() doesn't work with floats?

I think this must be a bug. It's the kind of thing that makes me pull my hair out. In the example below, whoRect and tmpRect are both returned from GUILayoutUtility.GetLastRect(). My goal is to align text to columns based on the width of the column header such that text + space = width. I had planned on doing this by calling GUILayout.Space() but it doesn't work with the results for GetLastRect() for some extremely odd and strange reason I cannot for the life of me fathom.

             // simplest test (this works)
             float x = 78f;
             float y = 23f;
             int diff = (int)(x - y); 
             GUILayout.Space(diff);
 
             // this doesn't
             x = whoRect.width;
             y = tmpRect.width;
             print("x " + x + " y " + y);  // 78 and 23
             diff = (int)(x - y);  // note: also tried with diff as a float
             print(diff); // 55
             GUILayout.Space(diff);

So when I use the difference from the two Rects I don't get any space. The value prints out identically in the two calls to GUILayout.Space() so why does the first work and the latter not?

goes off and bangs head against wall some more

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 judy3turn · Aug 18, 2012 at 10:09 PM 0
Share

I find it hard to believe it could be sequencing when the print(value) call is immediately prior to the Space(value) call and prints out the correct value. And yes, I switched from floats to ints to get rid of any floating point value weirdness. Now, I am a C++ programmer so I do make some C# assumptions that aren't always valid. But I thought Rect saved = LastRect() would COPY the last rect request into the saved value. Sequencing at that point should be irrelevant so I'm guessing something weird is going on behind the scenes and I don't have the source to look at. Here is the gist of the code I was using.

 doGUI()
 { 
     window = GUI.Window(1, window, drawWin, "myWindow");
 }
 
 drawWin()
 {
     GUILayout.BeginVertical();
     GUILayout.BeginHorizontal();
     GUILayout.Button("column1", "myButton");
     Rect saved1 = GUILayoutUtility.GetLastRect();
     GUILayout.Button("column2", "myButton");
     Rect saved2 = GUILayoutUtility.GetLastRect();
     <... more of same...>
     GUILayout.EndHorizontal();
     GUILayout.BeginHorizontal();
     GUILayout.Label("some text", "myLabel");
     Rect temp = GUILayoutUtility.GetLastRect();
     float diff = saved1.width - temp.width;
     GUILayout.Space(diff);
     GUILayout.Label("more text", "myLabel");
     temp = GUILayoutUtilility.GetLastRect();
     diff = saved2.width - temp.width;
     GUILayout.Space(diff);
     <... more of the same ...>
    GUILayer.EndHorizontal();
    GUILayer.EndVertical();
 }

So what could be going on in the GUILayout that would mess with these values and make them irrelevant even after they printed out correctly? I'm thinking someone with access to the source code and some assembler skills could figure this out. I don't have the first and am limited in the second, so I'm just passing this along as a bug. If not a bug, but a feature, could you document it please so I know how to do what I want to do?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Paulo-Henrique025 · Aug 18, 2012 at 01:24 AM

Let's take a look at the documentation:

 static function Space (pixels : float) : void

Pixels, the amount of space is measured in pixels and there is no thing as 1.5 pixel. It's easy to miss this kind of stuff.

Comment
Add comment · Show 2 · 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 · Aug 18, 2012 at 03:08 AM 0
Share

That's actually irrelevant. Unity works with floats and all rendering is also done with floats. Of course it get rasterized in the end, but that should be obvious. He actually cast it already to "int" so he has whole numbers.

avatar image Paulo-Henrique025 · Aug 18, 2012 at 03:54 AM 0
Share

Thanks for the correction!

avatar image
0

Answer by Bunny83 · Aug 18, 2012 at 02:26 AM

I'm pretty sure that's more sequential problem. Where and when do you use GetLastRect? GetLastRect only returns in the Repaint event a meaningful value.during the layout step it's garbage since the size of each rect can only determined at the end of the layout step.

So within the same OnGUI you can't use a rect value within the layouting phase. We don't know the rest of your script so we can't say what you actually want to do...

Comment
Add comment · 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

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

10 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

Related Questions

GUI layering 0 Answers

Grid layout lags after thousand inserts. 0 Answers

Centering a GUI label with varying text length 1 Answer

How do I set the order of elements in Canvas (Screen Space - Camera)? 0 Answers

Get height of a group of GUILayout controls 1 Answer


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