Custom Inspector GUI.Button not working, Input not registered

Hey, I have a ScriptableObject class which contains a bool[,] field.
I made a Custom Inspector for it that draws the defaut inspector and then draw a grid of buttons of size 50 by 50 pixels. I want this button to toggle the corresponding value in the scriptable object bool[,] field.

public override void OnInspectorGUI() {
            DrawDefaultInspector();
            
             SummonShapeData shapeData = (SummonShapeData)target;
            
             // Calculate draw coords
             // Rect lastRect = GUILayoutUtility.GetLastRect();
             // float drawHeight = lastRect.yMax + EditorGUIUtility.standardVerticalSpacing + 40;
             const float k_leftMargin = 40;
             const int k_cellSize = 50;
             const int k_padding = 5;
            
             var drawRect = new Rect(0, 0, k_cellSize, k_cellSize);
             for (int x = 0; x < shapeData.width; x++) {
                 for (int y = 0; y < shapeData.height; y++) {
                     // Calculate rect position
                     drawRect.x = k_leftMargin + k_cellSize * x + k_padding * x;
                     drawRect.y = 0 + k_cellSize * y + k_padding * y;
                     
                     // Calculate color
                     var savedColor = GUI.color;
                     GUI.color = shapeData.shape[x, y] ? Color.cyan : savedColor;
                     
                     if (GUI.Button(drawRect, "")) {
                         Debug.Log("Button clicked at " + x + ", " + y);
                         shapeData.shape[x, y] ^= true;
                     }
            
                     GUI.color = savedColor;
                 }
             }

             EditorUtility.SetDirty(target);
        }

This is what I came with. As you can see it renders the inspector exactly like I want it:

The grid of buttons adapt if I change the width or the height, the hover effect works as well. Although, nothing happens when I click onto a button. I made some research and decided to try to check for the input on my own and check if the mouse position was indeed inside the rect. What I found was using Event.current to check if the type was EventType.MouseDown and then get the Event.current.mousePosition. This did work only when the click happens inside of the “default drawn rect”, by that I mean the width, height and “script” fields that Unity draws with the custom inspector. It seems that it also considers the things I draw using the Layout workflow such as GUILayout.Button.
So I came to a conclusion, when I draw things in the Inspector with layout or default inspector, Unity calculates the “inspector” rect where it handles events and buttons and interactivity. Although, drawing my own stuff out of this rect makes the interaction disabled. I tried to find some solutions to tell Unity, hey consider this part of the inspector as a drawn rect to “enable” input handling but nothing was related. I also red all the Editor class but nothing related.

Any path to solve this issue is welcomed, don’t hesitate if you need any more information to solve this problem. Thanks in advance.

Padrox

I found a solution on my own. What I did is to calculate the total height of the content I drew I use GUILayout.Space(totalDrawHeight) and then you can leave it like that or even draw buttons or additional stuff. It will then consider the draw space as interactable.