- Home /
GUILayout.TextArea/TextField not working.
Hello there.
I'm having a strange problem with GUILayout's TextArea and TextField functions. While I used it several time before without having any problem, I can't seem to find out what's wrong here.
_currentFile = GUILayout.TextArea(_currentFile);
Where _currentFile is a member of my MonoBehaviour. This variable is only edited here. Does someone know what the hell is going on with TextField/TextArea all of a sudden ?
Thanks in advance. :)
not really enough information to help you out here... What exactly is it doing?
Exactly. What code is around this line? GUILayout uses layouting groups, so it depends on the other elements how big and where the area / field will show up.
"I can't seem to find out what's wrong here."
sorry, but we can't either...
Here's the whole OnGUI code (it's a file browser) :
GUILayout.BeginArea(new Rect ( 30, 30, Screen.width-60, Screen.height-60), "Enregistrer sous...", (GUIStyle)"box");
GUILayout.Space(30);
GUI.skin.box.alignment = TextAnchor.$$anonymous$$iddleLeft;
// top toolbar
GUILayout.BeginHorizontal();
// Display current directory
GUILayout.Box(_currentDir);
// Goto parent button
DirectoryInfo parent = new DirectoryInfo(_currentDir).Parent;
if ( parent == null || !parent.FullName.Contains( _viewScope ) )
GUI.enabled = false;
if ( GUILayout.Button(_parentTex,GUILayout.Width(GUI.skin.button.fixedHeight) ) )
RegisterNewLocation(new DirectoryInfo(_currentDir).Parent.FullName);
GUI.enabled = true;
// Previous button
if ( _historyIndex <= 0 ) GUI.enabled = false;
if ( GUILayout.Button(_previousTex,GUILayout.Width(GUI.skin.button.fixedHeight) ) )
_currentDir = _history[--_historyIndex];
GUI.enabled = true;
// Next button
if ( _historyIndex >= _history.Count-1 ) GUI.enabled = false;
if ( GUILayout.Button(_nextTex,GUILayout.Width(GUI.skin.button.fixedHeight) ) )
_currentDir = _history[++_historyIndex];
GUI.enabled = true;
GUILayout.EndHorizontal();
//Debug.Log("History Index : " + _historyIndex + "/ History nb elements : " + _history.Count);
GUI.skin.box.alignment = TextAnchor.UpperCenter;
GUILayout.Space(10);
// $$anonymous$$ain panels
GUILayout.BeginHorizontal();
// DIR VIEW
_scrollPosDirView = GUILayout.BeginScrollView(_scrollPosDirView, "box", GUILayout.Width(Screen.width*0.25f));
GUILayout.BeginHorizontal();
GUILayout.Label(_dirTex, GUILayout.Height(GUI.skin.button.fixedHeight), GUILayout.Width(GUI.skin.button.fixedHeight));
if ( _viewScope.Equals(_currentDir) ) GUI.SetNextControlName("SelectedDir");
if ( GUILayout.Button ( new DirectoryInfo(_viewScope).Name ))
{
_currentDir = _viewScope;
}
GUILayout.EndHorizontal();
GUI.FocusControl("SelectedDir");
DisplayRecursively(_viewScope, _currentDir);
GUILayout.EndScrollView();
// FILE VIEW
_scrollPosFileView = GUILayout.BeginScrollView(_scrollPosFileView, "box");
DisplayIconView(_currentDir);
GUILayout.EndScrollView();
GUILayout.EndHorizontal();
GUILayout.Space(5);
// Filename text field
GUILayout.BeginHorizontal();
GUILayout.Label("Nom du fichier : ", GUILayout.Width(Screen.width*0.2f) );
_currentFile = GUILayout.TextArea(_currentFile);
GUILayout.EndHorizontal();
// Error Box
GUILayout.Box(_error);
// Confirm buttons
GUILayout.BeginHorizontal();
GUILayout.Space(Screen.width*0.6f);
if(GUILayout.Button("O$$anonymous$$"))
{
}
if(GUILayout.Button("Cancel"))
{
_callback("");
Destroy(this.gameObject);
}
GUILayout.EndHorizontal();
GUILayout.EndArea();
I think I found what part of my code is wrong :
// $$anonymous$$ain panels
GUILayout.BeginHorizontal();
// DIR VIEW
_scrollPosDirView = GUILayout.BeginScrollView(_scrollPosDirView, "box", GUILayout.Width(Screen.width*0.25f));
GUILayout.BeginHorizontal();
GUILayout.Label(_dirTex, GUILayout.Height(GUI.skin.button.fixedHeight), GUILayout.Width(GUI.skin.button.fixedHeight));
if ( _viewScope.Equals(_currentDir) ) GUI.SetNextControlName("SelectedDir");
if ( GUILayout.Button ( new DirectoryInfo(_viewScope).Name ))
{
_currentDir = _viewScope;
}
GUILayout.EndHorizontal();
GUI.FocusControl("SelectedDir");
DisplayRecursively(_viewScope, _currentDir);
GUILayout.EndScrollView();
// FILE VIEW
_scrollPosFileView = GUILayout.BeginScrollView(_scrollPosFileView, "box");
DisplayIconView(_currentDir);
GUILayout.EndScrollView();
GUILayout.EndHorizontal();
I still don't know how to solve that issue, but if I delete that part, my TextField works just fine. There must definitely be something with the GUI system that I don't understand.
Answer by DocteurCox · Jun 18, 2013 at 02:39 PM
I finally found what was wrong. To highlight some elements, I used GUI.FocusControl which prevented me from focusing the TextField by clicking on it.
Really sorry for that useless question :x