- Home /
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.
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.
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...
Have you tested GUILayout? The extra CPU overhead probably won't be noticeable.
The margin problem is the same with gui layout actually.
Could you please post your code, so we can properly see what you're doing?
Your answer
Follow this Question
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