Skip to content

Commit 2bc293d

Browse files
committed
Resizable size property field in the ReorderableList drawer
1 parent 9ea0cda commit 2bc293d

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

Assets/Editor Toolbox/Editor/Internal/ReorderableListBase.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public abstract class ReorderableListBase
5252

5353

5454
protected const string defaultLabelFormat = "{0} {1}";
55+
protected const string defaultElementName = "Element";
5556

5657
/// <summary>
5758
/// Hotcontrol index, unique for this instance.
@@ -408,7 +409,7 @@ protected virtual void HandleHeaderEvents(Rect rect)
408409

409410
public string GetElementDefaultName(int index)
410411
{
411-
return string.Format(defaultLabelFormat, "Element", index);
412+
return string.Format(defaultLabelFormat, defaultElementName, index);
412413
}
413414

414415
public string GetElementDefinedName(int index)
@@ -621,20 +622,22 @@ public virtual void DrawStandardHeader(Rect rect)
621622
var label = EditorGUI.BeginProperty(rect, TitleLabel, List);
622623
//display the property label using the preprocessed name
623624
DrawStandardName(rect, label, Foldable);
624-
625-
var diff = rect.height - Style.sizePropertyStyle.fixedHeight;
626-
rect.yMin += diff / 2;
627-
rect.yMax -= diff / 2;
628-
rect.xMin = rect.xMax - Style.sizeAreaWidth;
629-
630625
using (new EditorGUI.DisabledScope(FixedSize))
631626
{
632627
var property = Size;
628+
var sizeValue = property.intValue;
629+
630+
var potentialSizeContent = new GUIContent(sizeValue.ToString());
631+
var width = Style.sizePropertyStyle.CalcSize(potentialSizeContent).x;
632+
var diff = rect.height - Style.sizePropertyStyle.fixedHeight;
633+
rect.yMin += diff / 2;
634+
rect.yMax -= diff / 2;
635+
rect.xMin = rect.xMax - Mathf.Max(Style.sizeAreaWidth, width);
633636

634637
EditorGUI.BeginProperty(rect, Style.sizePropertyContent, property);
635638
EditorGUI.BeginChangeCheck();
636639
//cache the size value using the delayed int field
637-
var sizeValue = Mathf.Max(EditorGUI.DelayedIntField(rect, property.intValue, Style.sizePropertyStyle), 0);
640+
sizeValue = Mathf.Max(EditorGUI.DelayedIntField(rect, sizeValue, Style.sizePropertyStyle), 0);
638641
if (EditorGUI.EndChangeCheck())
639642
{
640643
property.intValue = sizeValue;

0 commit comments

Comments
 (0)