- Home /
GUI labels and buttons overlapping | how can I fix this?
So I am using a list of GUILayout labels and buttons. If I don't use an area it works perfect, the labels and buttons are displayed below each other (in the top left corner, but I want them to be in the middle of the screen) but when I use an area they all use the same position and just overlap each other. If anyone could help me (please don't make it too hard, I am still a noob in programming :) ), I would really appreciate it.
void OnGUI(){
Event e = Event.current;
if (inputManager != null) {
for (int i = 0; i < inputManager.Count; i++) {
GUILayout.BeginArea(new Rect(posX, posY, sizeX, sizeY));
GUILayout.BeginHorizontal ();
GUILayout.Label (inputManager [i].keyName, labelStyle);
if (GUILayout.Button (inputManager [i].key, keyStyle)) {
key = i;
change = true;
}
GUILayout.EndHorizontal();
GUILayout.EndArea ();
}
}
This is part of the code I use for customizable controls.
Answer by saschandroid · Apr 07, 2016 at 01:38 PM
I don't use the legacy gui, but I guess you have to put Area and Horizontal outside the for-loop:
GUILayout.BeginArea(new Rect(posX, posY, sizeX, sizeY));
GUILayout.BeginHorizontal ();
for (int i = 0; i < inputManager.Count; i++)
{
GUILayout.Label (inputManager [i].keyName, labelStyle);
if (GUILayout.Button (inputManager [i].key, keyStyle))
{
key = i;
change = true;
}
}
GUILayout.EndHorizontal();
GUILayout.EndArea ();
Thanks, this works ... I feel so stupid now for not thinking about that myself :P But do you know how I can get them under each other but with the boxes next to the label? Because if I use BeginHorizontal everything will be next to each other on a Horizontal line (obviously) and if I use Vertical everything will be under each other (again obvious) but I want my boxes next to the labels. Anyways much thanks for the suggestion it helped a lot :D
Like this?
GUILayout.BeginArea(new Rect(posX, posY, sizeX, sizeY));
GUILayout.BeginHorizontal ();
for (int i = 0; i < input$$anonymous$$anager.Count; i++)
{
GUILayout.BeginVertical();
GUILayout.Label (input$$anonymous$$anager [i].keyName, labelStyle);
if (GUILayout.Button (input$$anonymous$$anager [i].key, keyStyle))
{
key = i;
change = true;
}
GUILayout.EndVertical();
}
GUILayout.EndHorizontal();
GUILayout.EndArea ();
This will put the buttons below the labels ins$$anonymous$$d of next to it but just switch horizontal and vertical and it's exactly what I need :D Thank you very much!
Answer by CaJerry87 · Dec 20, 2016 at 07:46 AM
Look athe the images and itll help you with your Custom Inspector Layout http://answers.unity3d.com/answers/1288008/view.html
Your answer
Follow this Question
Related Questions
Fade out GUILayout Area? 1 Answer
Additional parameters for GUILayout.Label 1 Answer
GUI.label overlapping text 1 Answer
How do I fix my GUILayout.Button 2 Answers
GUILayout Icon + Text 3 Answers