Search Unity

Question Help with editor window script. why when typing in textfield there is horizontal scrollbar?

Discussion in 'Immediate Mode GUI (IMGUI)' started by eshelshlomi1999, May 8, 2023.

  1. eshelshlomi1999

    eshelshlomi1999

    Joined:
    Apr 1, 2023
    Posts:
    17
    I want to disable the horizontal bar when typing in the search field (text field).

    Code (csharp):
    1.  
    2. string searchString;
    3.     void OnGUI()
    4.     {
    5.         int counter = 0;
    6.         GUI.color = Color.white;
    7.         GUILayout.Space(30);
    8.         searchString = GUILayout.TextField(searchString, GUI.skin.FindStyle("ToolbarSeachTextField"));
    9.         if (GUILayout.Button("", GUI.skin.FindStyle("ToolbarSeachCancelButton")))
    10.         {
    11.             searchString = "";
    12.             GUI.FocusControl(null);
    13.         }
    14.  
    15.         GUILayout.Space(15);
    16.  
    17.         GUIStyle TextFieldStyles = new GUIStyle(EditorStyles.textField);
    18.         GUI.contentColor = Color.white;
    19.         GUI.color = Color.white;
    20.  
    21.         //Value Color
    22.         TextFieldStyles.normal.textColor = Color.white;
    23.  
    24.         //Label Color
    25.         EditorStyles.label.normal.textColor = Color.yellow;
    26.         EditorGUILayout.LabelField("         Overall number of GameObjects in Hierarchy: " + test.Count.ToString());
    27.         EditorGUILayout.Space(10);
    28.         EditorGUILayout.LabelField("         GameObject                                                                                 Script");
    29.         GUILayout.Space(5);
    30.         EditorStyles.label.normal.textColor = Color.white;
    31.  
    32.         scrollPos =
    33.             EditorGUILayout.BeginScrollView(scrollPos, false, true,
    34.             GUILayout.ExpandWidth(true));
    35.  
    36.        
    37.  
    38.         foreach (GameObjectAndScriptName item in gameObjectAndScriptNames)
    39.         {
    40.             EditorGUILayout.BeginHorizontal();
    41.  
    42.             if (searchString != null)
    43.             {
    44.                 if (item.ScriptName.Contains(searchString, StringComparison.CurrentCultureIgnoreCase))
    45.                 {
    46.                     EditorGUIUtility.labelWidth = 25;
    47.                     EditorGUILayout.ObjectField(counter.ToString(), item.GameObject, typeof(GameObject), true);
    48.                     counter++;
    49.                     foreach (UnityEngine.Transform g in item.GameObject.transform.GetComponentsInChildren<UnityEngine.Transform>())
    50.                     {
    51.  
    52.                     }
    53.  
    54.                     num.Add(EditorGUILayout.TextField(item.ScriptName).Length);
    55.                 }
    56.             }
    57.             else
    58.             {
    59.                 EditorGUIUtility.labelWidth = 25;
    60.                 EditorGUILayout.ObjectField(counter.ToString(), item.GameObject, typeof(GameObject), true);
    61.  
    62.                 num.Add(EditorGUILayout.TextField(item.ScriptName).Length);
    63.                 if (counter != gameObjectAndScriptNames.Count)
    64.                 {
    65.                     counter++;
    66.                 }
    67.             }
    68.  
    69.             EditorGUILayout.EndHorizontal();
    70.         }
    71.  
    72.         GUILayout.EndScrollView();
    73.     }
    74.  
    whenever I type something in the search field it's making at the bottom a horizontal scroll bar and Icant figure out how to disable this scroll bar.

    I see now that also on the right the vertical scroll bar appears. but if there is one time when searching or some items why the vertical scroll bar show? it should show only if there are many items to the bottom.


    screenshot showing the scroll bar at the bottom once I'm typing in the search field:

    you can see also the Script is not accurate under the yellow Script text.




    this is a screenshot when the search field is empty.

    the script name is accurate under the yellow Script text.
    there is only vertical scroll bar as I wanted.
    no horizontal scroll bar on the bottom.

    this is how it should be also when typing in the search field and it find one item 10 items 100 items or not find anything.