Search Unity

TextField and FocusControl behaviour on 2.0.2

Discussion in 'Immediate Mode GUI (IMGUI)' started by nafonso, Jan 31, 2008.

  1. nafonso

    nafonso

    Joined:
    Aug 10, 2006
    Posts:
    377
    Hi,

    I had the following code in 2.0.1:

    Code (csharp):
    1. GUI.SetNextControlName("textInput");
    2. m_messageText = GUILayout.TextField(m_messageText);
    3. GUI.FocusControl("textInput");
    4.  
    And it worked as expected, the TextField would always have the focus. However, with 2.0.2, every time we use FocusControl on TextFields, the TextField's text will become selected (i.e. basically we can only write 1 character at a time).

    I was want to know if this is expected behaviour, and if I should find a way to know when I have to "focus it", or if it is a bug, i.e. if Unity should not be selecting the text because in the last call the same element already had the focus.

    Regards,
    Afonso
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I had the same question, but got distracted by other things and neglected to investigate more to see if I was just doing something wrong. So I guess it's not just me. ;)

    --Eric
     
  3. seon

    seon

    Joined:
    Jan 10, 2007
    Posts:
    1,441
    This is still busted, and no one from UT has jumped in with a solution.

    Can we get an alternative option/method for now on how to make a textfield have focus until this issue is fixed?

    This just doesnt work properly...

    Code (csharp):
    1.  
    2. GUI.SetNextControlName("input");
    3. chat_message = GUI.TextField (Rect (Screen.width-250, 30, 240, 20), chat_message, 25);
    4. GUI.FocusControl("input");
    5.  
     
  4. nafonso

    nafonso

    Joined:
    Aug 10, 2006
    Posts:
    377
    What I advise is to set focus on the first time, e.g.:

    Code (csharp):
    1. void Start(){
    2.    m_hasFocus = false;
    3. }
    4.  
    5. void OnGUI(){
    6.    GUI.SetNextControlName("input");
    7.    m_inputText = GUI.TextField(...);
    8.    if( !m_hasFocus ){
    9.       m_hasFocus = true;
    10.       GUI.FocusControl("input");
    11.    }
    12. }
    This works fine if you only have an input text field, and if you click any button it will leave the screen, e.g. submitting a name to a top score.

    However, if you have multiple things that can get focus, you will be in trouble. You will have to set the m_hasFocus to false every time another control grabs the focus (which will probably be when they're clicked?).

    And if you use ScrollViews, then you are really in trouble :p Unity 2.0.2 introduced another bug to the GUI that when a ScrollView gets filled and shows the scroll bars, it gets the focus, which means that if you are using a chat (like in my case), you can't really do anything about it, because you can't know when the ScrollView got the focus.

    Hopefully these bugs will be corrected in the next update.

    Regards,
    Afonso
     
  5. seon

    seon

    Joined:
    Jan 10, 2007
    Posts:
    1,441
    Thanks Afonso... thats what I am doing already, but it's not so nice :(

    I am sure UT will get it sorted quickly for us :)
     
  6. DocSWAB

    DocSWAB

    Joined:
    Aug 28, 2006
    Posts:
    615
    *BUMP*

    I noticed that focus control does work with scroll areas in the IDE, but not standalones.

    I assume someone filed a bug report on this?
     
  7. seon

    seon

    Joined:
    Jan 10, 2007
    Posts:
    1,441
    never assume.... always bug report it. UT don't mind duplicates.. and would rather that than it not getting reported because everyone thought the other guy did it.
     
  8. Samantha

    Samantha

    Joined:
    Aug 31, 2005
    Posts:
    609
    Bingo. It takes me four seconds to close a bug that I recognize as a duplicate. It takes a million years for the dev team to fix a bug that never gets reported :)

    Generally, if you find a bug you don't need to ask about it on the forum. Just report it. I look at the incoming bugs every day so you can rest assured that the bug reporter is not going into a black hole.
     
  9. SixTimesNothing

    SixTimesNothing

    Joined:
    Dec 26, 2007
    Posts:
    167
    *bump*

    has this issue been resolved yet? i'm running into the aforementioned issue with ScrollViews in a chat interface. i can't type into the input TextArea once the scroll view is full and the scrollbars are shown. any help would be really appreciated.