How do you indent GUI inside an Editor window?

(Please note: I’m using 2017.4 LTS)

I’ve spent ages googling for a way to indent controls / labels etc. in an editor window…

The usual EditorGUI.indentLevel++ / – or using EditorGUI.IndentLevelScope() don’t seem to work.


class EditorExample : EditorWindow
{
    [MenuItem("EditorExample")]
    static void Init()
    {
        var window = GetWindow<EditorExample>();
        window.Show();
    }

    void OnGUI()
    {
        EditorGUI.indentLevel++;
        {
            GUILayout.Label( "This label is NOT indented" );
        }
        EditorGUI.indentLevel--;

        using ( new EditorGUI.IndentLevelScope() )
        {
            GUILayout.Label( "This label is NOT indented" );
        }
    }
}
1 Like

I found a simple solution in the end, actually very obvious…


class EditorExample : EditorWindow
{
    [MenuItem("EditorExample")]
    static void Init()
    {
        var window = GetWindow<EditorExample>();
        window.Show();
    }

    void OnGUI()
    {
        using( new GUILayout.HorizontalScope() )
        {
            GUILayout.Space( 20f ); // horizontal indent size of 20 (pixels)
	
            using( new GUILayout.VerticalScope() )
            {
                // anything you do in here will be indented by 20 (pixels)
                // relative to stuff outside the top using( xxx) scope
            }
        }
    }
}