Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

EditorWindow: window keeps in memory which button was last used

Discussion in 'Immediate Mode GUI (IMGUI)' started by FeastSC2, Sep 5, 2017.

  1. FeastSC2

    FeastSC2

    Joined:
    Sep 30, 2016
    Posts:
    978
    I would like my window to forget which button/text field I last used before it lost focus.

    Right now, after my window loses focus, as it regains focus later on, the text field last used becomes active again, meaning that it has the keyboard focus and that if I write something it will be written in that text field.

    What can I do to not have this happen anymore?
    https://i.imgur.com/cFAOGCJ.gifv
     
  2. PsyKaw

    PsyKaw

    Joined:
    Aug 16, 2012
    Posts:
    102
    FeastSC2 likes this.
  3. FeastSC2

    FeastSC2

    Joined:
    Sep 30, 2016
    Posts:
    978
    I used this and it still acted like before
    Code (CSharp):
    1.     void OnFocus()
    2.     {
    3.         // Make the window not focus on where last typed in.
    4.         Debug.Log("Focussing");
    5.  
    6.         GUIUtility.keyboardControl = 0;
    7.     }
    8.  
    9.     private void OnLostFocus()
    10.     {
    11.         Debug.Log("Losing focus");
    12.  
    13.         GUIUtility.keyboardControl = 0;
    14.     }
    With the code beneath at least it makes me not edit the text anymore. Thanks for leading me to the answer PsyKaw!
    Code (CSharp):
    1. EditorGUIUtility.editingTextField = false;
     
    PsyKaw likes this.
  4. FeastSC2

    FeastSC2

    Joined:
    Sep 30, 2016
    Posts:
    978
    I'm trying to set a text field in focus, using https://docs.unity3d.com/ScriptReference/30_search.html?q=GetControlID

    I don't really understand how to use the GetControlID since I can't point to which TextField it should acquire the id from?
    Code (CSharp):
    1. GUIUtility.keyboardControl = GUIUtility.GetControlID(FocusType.Keyboard);
    2.                 SceneFilter = GUILayout.TextField(SceneFilter, GUILayout.Width(filterChoice.Length * 100));
     
  5. PsyKaw

    PsyKaw

    Joined:
    Aug 16, 2012
    Posts:
    102
    FeastSC2 likes this.