Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question TreeView input field not working

Discussion in 'Scripting' started by simiel7, Feb 23, 2021.

  1. simiel7

    simiel7

    Joined:
    Dec 18, 2020
    Posts:
    7
    Hi!

    I created a TreeView with MultiColumnHeader and it works fine for showing the information that I need.
    Although, my problem is with the editing / using input fields.

    I have two columns, for example some key - value pairs and I want to edit the value field inside this TreeView.
    I tried with multiple TextFields, like EditorGUI.TextField, EditorGUILayout.TextField or DelayedTextField, but the result was the same.
    The field is there visually and I can select any line / row, but the input field not get the focus (or at least this is what I see) and not recognize any keys, in this way I'm not able to change the value of this input field.

    I couldn't find any clue what I missed or how it can work. I already checked this manual https://docs.unity3d.com/2021.1/Documentation/Manual/TreeViewAPI.html.

    Here is the main part of my code for this:
    Code (CSharp):
    1. protected override void RowGUI(RowGUIArgs args) {
    2. if (Event.current.rawType != EventType.Repaint)
    3.             {
    4.                 return;
    5.             }
    6.     for (int i = 0; i < args.GetNumVisibleColumns(); i++) {
    7.         CellGui(args.GetCellRect(i), (Column)args.GetColumn(i), ref args);
    8.     }
    9. }
    10.  
    11. private void CellGui(Rect cellRect, Column column, ref RowGUIArgs args) {
    12.     CenterRectUsingSingleLineHeight(ref cellRect);
    13.     Translation translation = data.translationList[args.item.id - 1];
    14.     switch (column) {
    15.         case Column.Key:
    16.             DefaultGUI.Label(cellRect, translation.key, args.selected, args.focused);
    17.             break;
    18.         case Column.Translation:
    19.             // Not get the focus when clicked on it, cannot edit the field, cannot recognize any key press, etc.
    20.             translation.translation = EditorGUI.DelayedTextField(cellRect, translation.translation);
    21.             break;
    22. }}

    Here is an example image:
    translation_test.PNG
     
    Last edited: Feb 25, 2021
  2. simiel7

    simiel7

    Joined:
    Dec 18, 2020
    Posts:
    7
    Nevermind, I found what caused my issue and prevent the actions to receive in the input fields.
    If you have a simple treeview and the input fields are not react to the interactions, it worth to just check the flow and events.

    I just simply blocked the events with this line in the RowGUI method:
    Code (CSharp):
    1. if (Event.current.rawType != EventType.Repaint)
    2. {
    3.     return;
    4. }
    It was my mistake to mess with this, but maybe somebody will end up in the same situation.
     
    Hosnkobf likes this.