Skip to content

Commit cf65e6b

Browse files
committed
Fix drawing MinMaxSlider in nested classes and arrays
1 parent 1a0f1c3 commit cf65e6b

2 files changed

Lines changed: 16 additions & 12 deletions

File tree

Assets/Editor Toolbox/Editor/Drawers/Regular/MinMaxSliderAttributeDrawer.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
namespace Toolbox.Editor.Drawers
55
{
6+
using Toolbox.Editor.Internal;
7+
68
[CustomPropertyDrawer(typeof(MinMaxSliderAttribute))]
79
public class MinMaxSliderAttributeDrawer : PropertyDrawerBase
810
{
@@ -20,7 +22,11 @@ protected override void OnGUISafe(Rect position, SerializedProperty property, GU
2022

2123
label = EditorGUI.BeginProperty(position, label, property);
2224
EditorGUI.BeginChangeCheck();
23-
ToolboxEditorGui.DrawMinMaxSlider(position, label, ref xValue, ref yValue, minValue, maxValue);
25+
using (new ZeroIndentScope())
26+
{
27+
ToolboxEditorGui.DrawMinMaxSlider(position, label, ref xValue, ref yValue, minValue, maxValue);
28+
}
29+
2430
if (EditorGUI.EndChangeCheck())
2531
{
2632
property.vector2Value = new Vector2(xValue, yValue);

Assets/Editor Toolbox/Editor/ToolboxEditorGui.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -205,21 +205,19 @@ public static void DrawMinMaxSlider(Rect rect, string label, ref float xValue, r
205205

206206
public static void DrawMinMaxSlider(Rect rect, GUIContent label, ref float xValue, ref float yValue, float minValue, float maxValue)
207207
{
208-
var padding = 8.0f;
209-
var labelWidth = EditorGUIUtility.labelWidth;
208+
rect = EditorGUI.PrefixLabel(rect, label);
209+
210210
var fieldWidth = EditorGUIUtility.fieldWidth;
211-
212-
var minFieldRect = new Rect(rect.xMin + labelWidth, rect.y, fieldWidth, rect.height);
211+
var minFieldRect = new Rect(rect.xMin, rect.y, fieldWidth, rect.height);
213212
var maxFieldRect = new Rect(rect.xMax - fieldWidth, rect.y, fieldWidth, rect.height);
214-
var labelRect = new Rect(rect.x, rect.y, labelWidth, rect.height);
213+
215214
//set slider rect between min and max fields + additional padding
216-
var sliderRect = new Rect(rect.x + labelWidth + fieldWidth + padding,
217-
rect.y,
218-
rect.width - labelWidth - fieldWidth * 2 - padding * 2,
219-
rect.height);
215+
var spacing = 8.0f;
216+
var sliderRect = Rect.MinMaxRect(minFieldRect.xMax + spacing,
217+
rect.yMin,
218+
maxFieldRect.xMin - spacing,
219+
rect.yMax);
220220

221-
//begin drawing using GUI methods
222-
EditorGUI.LabelField(labelRect, label);
223221
EditorGUI.BeginChangeCheck();
224222
xValue = EditorGUI.FloatField(minFieldRect, xValue);
225223
yValue = EditorGUI.FloatField(maxFieldRect, yValue);

0 commit comments

Comments
 (0)