- Home /
GUI focus and draw order mixed
So I have a GUI window with a few text fields.
when the user enters text a suggestion box appears below one of them.
my problem is that I have to draw the box after the other controls so it appears on top of them.
But the controls that are drawn first receive my mouse click instead of the buttons in the box.
I cant use gui.enabled = false for them because they need to be able to be clicked to close the suggestion box.
void MailWindow (int id) {
GUILayout.BeginHorizontal();
GUILayout.BeginVertical(GUILayout.Width(90));
GUILayout.BeginHorizontal();
GUILayout.Label("To:");
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.Label("Subject:");
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
GUILayout.EndVertical();
GUILayout.BeginVertical();
GUI.SetNextControlName("address");
mailTo = GUILayout.TextField(mailTo);
string currentMail = (mailTo.LastIndexOf(',') > -1) ? mailTo.Substring(mailTo.LastIndexOf(',')+1) : mailTo;
mailMatches = new List<string>();
foreach (string mail in previousMails) {
if (mail.IndexOf(currentMail) == 0)
mailMatches.Add (mail);
}
subject = GUILayout.TextField (subject);
GUILayout.EndVertical();
GUILayout.EndHorizontal();
GUILayout.Space(20);
textScroller = GUILayout.BeginScrollView(textScroller);
body = GUILayout.TextArea(body);
GUILayout.EndScrollView();
if (GUI.GetNameOfFocusedControl() == "address" && mailMatches.Count > 0) {
GUILayout.BeginArea(suggestionBox, skin.box);
foreach (string mail in mailMatches) {
if (GUILayout.Button(mail, skin.label)) {
//do stuff
}
}
GUILayout.EndArea();
}
}
Anyone know how to overcome this?
i found a similar question with a hack by drawing the box both as the start and end of the gui function so the first one catches the mouse click event and the second one gets drawn on top. otherwise id have to capture the mouse event myself if its in the button area... pretty poor design on unity's part
Your answer
Follow this Question
Related Questions
Is there any way to make a virtual keyboard (QWERTY) 2 Answers
Drop focus from Button after click 0 Answers
Clickable GUI.Window 1 Answer
Way to determine if a GUI element has focus 1 Answer
Using GUI.FocusControl on TextField selects all text 4 Answers