BepInEx / BepInEx.Utility

Generic utility plugins for the BepInEx plugin loader (mono)
GNU General Public License v3.0
76 stars 9 forks source link

BepInEx.OptimizeIMGUI Nested ExpandHeight in Vertical Group #6

Closed JustAGuest4168 closed 1 year ago

JustAGuest4168 commented 1 year ago

When nesting Vertical and Horizontal Groups, I discovered an issue with a Button with ExpandHeight(true) inside a Horizontal Group nested inside another Vertical Group with ExpandHeight(false) causing the Vertical Groups ExpandHeight(false) to be negated. Screenshots of with and without BepInEx.OptimizeIMGUI and condensed sample code below.

Without BepInEx.OptimizeIMGUI (Correct): image

With BepInEx.OptimizeIMGUI (Incorrect): image

Condensed Sample code:

public class NewBehaviourScript : MonoBehaviour
{
    private Rect uiWindow2 = new Rect(UnityEngine.Screen.width / 2 + 20, 20, 120, 400);
    private void OnGUI()
    {
        uiWindow2 = GUILayout.Window(34566, uiWindow2, DisplayUIWindowX, "TEST");
    }
    private void DisplayUIWindowX(int windowId)
    {
        GUILayout.BeginVertical(GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
        {
            //Header
            GUILayout.BeginVertical("box", GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(false));
            {
                //Toolbar
                {
                    GUILayout.BeginHorizontal(GUILayout.ExpandHeight(false));
                    {
                        //Header
                        GUILayout.Label("TEST", GUILayout.ExpandWidth(true));

                        //Options
                        if (GUILayout.Button("O", GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(true)))
                        {
                        }
                    }
                    GUILayout.EndHorizontal();

                    //Options
                }
            }
            GUILayout.EndVertical();

            //Content
            GUILayout.BeginVertical("box", GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
            {
                //Abstract
                //this.DisplayUIWindowBase();
                GUILayout.FlexibleSpace();
            }
            GUILayout.EndVertical();

            //Info
            GUILayout.BeginVertical("box", GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(false));
            {
                GUILayout.BeginHorizontal();
                {
                    GUILayout.Label("Info: " + "", GUILayout.ExpandWidth(true));
                    if (GUILayout.Button("Clear", GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(true)))
                    {
                        //info = "";
                    }
                }
                GUILayout.EndHorizontal();
            }
            GUILayout.EndVertical();
        }
        GUILayout.EndVertical();

        GUI.DragWindow();
    }
}
ManlyMarco commented 1 year ago

It looks like it's not an easy thing to fix without straight up disabling the feature, so unfortunately I'll have to mark this as a nofix. If anyone is able to fix this I'll be happy to merge a PR.

For now I added a warning to the readme https://github.com/BepInEx/BepInEx.Utility/commit/ba276feebe3880c80ab6689f57006311ce7eea07