Search code examples
unity-game-engineunity-editor

Unity ScrollViewScope horizontal scroll not working with EditorGUILayout


I need to use EditorGUI.IndentLevelScope and it only work with EditorGUILayout like LabelField, Foldout, not in GUILayout like Label.

here is my code

                using (var midScroll = new EditorGUILayout.ScrollViewScope(midSPos, true, true))
                {
                    using (new EditorGUI.IndentLevelScope(1))
                    {
                        midSPos = midScroll.scrollPosition;
                        for (int i = 0; i < 50; i++)
                        {
                            EditorGUILayout.LabelField("This is a EditorGUILayout.LabelField. This is a EditorGUILayout.LabelField.", GUI.skin.GetStyle("LinkLabel"));
                        }
                    }
                }

Vertical work but not Horizontal Pic: https://gyazo.com/70382d83222dc7fc2db54c4745836dfc

same code with GUILayout.Label work both what do i miss


Solution

  • End up I found a solution for Label by adding an empty PrefixLabel in front and back to GUILayout again, the scroll now works.

    HorizontalScope
        EditorGUILayout.PrefixLabel("");
        GUILayout.Label("content");
    

    But still, have some issues with my foldout like this since I can't add HorizontalScope to it.

    InitRow(row row)
    {
        if (isShowing = EditorGUILayout.Foldout(isShowing, "Foldout"))
        {
            InitRow(child);
        }
    }