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 Sam Bauwens · Jul 09, 2013 at 01:11 PM · guifontlabel

GUI.Label top margin problem (without layout)

I'm trying to make my layout framework, and I'm faced with a problem when trying to align a label to the top left corner of the screen:

When I put the label at position 0, 0 there is a margin between the top of the text and the top of the screen, meaning that the top of the text doesn't "touch" the top of the screen, whereas the left side of the text does touch it.

So one solution would be to place the label at a negative Y position (-5 for instance) to correct that margin, but the problem is that the margin depends not only on the font but also and more importantly on the text of the label. That leads me to what I think is the cause of the problem, which is that there are characters like "|" which are higher that other, and so unity I think calculates the maximum possible height of any string and uses that to calculate where to position the text.

Here is some code to reproduce the problem, I tried it on an empty project, with no custom skin. When I launch it, I expect the text "Hi!" to "touch" the top of the screen, but it doesn't, theres a top margin of about 5 pixels.

``` using UnityEngine; using System.Collections;

public class GUILayoutTest : MonoBehaviour {

 void OnGUI()
 {
     GUI.Label(new Rect(0, 0, 100, 20), new GUIContent("Hi!"));
 }

} ```

Of course the point isn't really to put 0 margin, but to be able to control the margin.

Comment
Add comment · Show 8
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 swyrazik · Jul 09, 2013 at 01:52 PM 0
Share

do you make use of your own GUIStyle or not? If not then you could use one to specify the margins and many other properties.

avatar image Sam Bauwens · Jul 09, 2013 at 01:55 PM 0
Share

Yes I use GUIStyle, but margins and most of the layout properties are used only by GUILayout, and I don't use GUILayout, because I've heard of the performance issues...

avatar image TonyLi · Jul 09, 2013 at 02:52 PM 0
Share

Have you tested GUILayout? The extra CPU overhead probably won't be noticeable.

avatar image Sam Bauwens · Jul 09, 2013 at 03:54 PM 0
Share

The margin problem is the same with gui layout actually.

avatar image tw1st3d · Jul 09, 2013 at 05:39 PM 0
Share

Could you please post your code, so we can properly see what you're doing?

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

18 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

OS Error with fonts? 1 Answer

Problem Trying To Get GUI.Label Centred 2 Answers

Possible to change GUI.Label fontsize without using GUIStyle? 1 Answer

How to set the font size in GUI.Label 2 Answers

Changing a GUILabel text SIZE 3 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