arimger/Unity-Editor-Toolbox

MinMaxSlider indentation

mbaske opened this issue · 2 comments

Hi, awesome package, thanks for sharing!
I came across a rendering issue with MinMaxSlider for nested properties. My current workaround is temporarily overriding EditorGUI.indentLevel in ToolboxEditorGui.cs

    public static void DrawMinMaxSlider(Rect rect, GUIContent label, ref float xValue, ref float yValue, float minValue, float maxValue)
    {
        int indentLevel = EditorGUI.indentLevel;
        EditorGUI.indentLevel = 0;
        
        var padding = 8.0f;
        var labelWidth = EditorGUIUtility.labelWidth;
        var fieldWidth = EditorGUIUtility.fieldWidth;

        var minFieldRect = new Rect(rect.xMin + labelWidth, rect.y, fieldWidth, rect.height);
        var maxFieldRect = new Rect(rect.xMax - fieldWidth, rect.y, fieldWidth, rect.height);
        var labelRect = new Rect(rect.x + indentLevel * 15, rect.y, labelWidth, rect.height);
        //set slider rect between min and max fields + additional padding
        var sliderRect = new Rect(rect.x + labelWidth + fieldWidth + padding,
                                  rect.y,
                                  rect.width - labelWidth - fieldWidth * 2 - padding * 2,
                                  rect.height);

        //begin drawing using GUI methods
        EditorGUI.LabelField(labelRect, label);
        EditorGUI.BeginChangeCheck();
        xValue = EditorGUI.FloatField(minFieldRect, xValue);
        yValue = EditorGUI.FloatField(maxFieldRect, yValue);
        EditorGUI.MinMaxSlider(sliderRect, ref xValue, ref yValue, minValue, maxValue);

        //values validation (xValue can't be higher than yValue etc.)
        xValue = Mathf.Clamp(xValue, minValue, Mathf.Min(maxValue, yValue));
        yValue = Mathf.Clamp(yValue, Mathf.Max(minValue, xValue), maxValue);
        
        EditorGUI.indentLevel = indentLevel;
    }

I'm using EditorGUI's default 15px per level for adding the indent back to labelRect.
Running Unity 2021.3 on Linux/Pop_OS.

nested
nested_fix

Thanks for the issue and sorry for the bug! I will fix it ASAP.

Fixed in: #46