OnGUI() layout

hello I am developing a GUI in the editor with the following code

    void OnGUI()
    {
        int bigSpace = 20;

        GUILayout.Space(bigSpace);

        GUILayout.BeginHorizontal();

        if (GUILayout.Button("Button with a very long text"))
        {
            // button click
        }

        if (GUILayout.Button("Short Text"))
        {
            // button click
        }

        GUILayout.EndHorizontal();

        padding = EditorGUILayout.TextField("Padding", padding);
}

getting the following result

8404890--1110027--editor.png )

the width of the elements is adjusted according to their content. How can I make them occupy 50% permanently?

I need them to be vertically aligned with the same size

Well, that’s tricky as the layout system takes all the content into account. So if one is larger than the available space the splitting becomes uneven. It that’s important you can use sub layout groups by using 2 BeginAreas and split the space manually the way you like. Though as I said, the layout system of the IMGUI system is not that flexible out of the box. You can workaround almost all problems, but some solutions are kinda hacky and may have visual artifacts when the space is resized or the content size changes.

Or the version of Unity changes… look how the Unity array-within-array has been broken for the past year or so and has only recently been fixed.

But there are still dozens of old LTS versions where arrays within arrays are just dead broken.

Editor inspector stuff laid out with IMGUI should be kept as simple as possible: make it give you the value you need, but don’t chase too far down the rathole of detail / fiddly stuff.