Skip to content

Commit c6bbdd3

Browse files
committed
Display elmenet handle at the top of available space; show "Collection is Empty" label for empty lists; minor refactor changes
1 parent 3372701 commit c6bbdd3

File tree

5 files changed

+18
-35
lines changed

5 files changed

+18
-35
lines changed

Assets/Editor Toolbox/Editor/Drawers/Toolbox/PropertyList/ReorderableListAttributeDrawer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@ static ReorderableListAttributeDrawer()
1111
{
1212
storage = new PropertyDataStorage<ReorderableListBase, ReorderableListAttribute>(false, (p, a) =>
1313
{
14-
return ToolboxEditorGui.CreateList(p,
14+
var list = ToolboxEditorGui.CreateList(p,
1515
a.ListStyle,
1616
a.ElementLabel,
1717
a.FixedSize,
1818
a.Draggable,
1919
a.HasHeader,
2020
a.HasLabels,
2121
a.Foldable);
22+
return list;
2223
});
2324
}
2425

2526
private static readonly PropertyDataStorage<ReorderableListBase, ReorderableListAttribute> storage;
2627

27-
2828
/// <summary>
2929
/// Draws a <see cref="ReorderableList"/> if given property was previously cached or creates completely new instance.
3030
/// </summary>

Assets/Editor Toolbox/Editor/Internal/ReorderableList.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ public class ReorderableList : ReorderableListBase
1414

1515
public ElementHeightCallbackDelegate elementHeightCallback;
1616

17-
1817
/// <summary>
1918
/// Offset between a dragging handle and the real mouse position.
2019
/// </summary>
@@ -24,7 +23,6 @@ public class ReorderableList : ReorderableListBase
2423

2524
private Rect middleRect;
2625

27-
2826
public ReorderableList(SerializedProperty list)
2927
: base(list)
3028
{ }
@@ -45,7 +43,6 @@ public ReorderableList(SerializedProperty list, string elementLabel, bool dragga
4543
: base(list, elementLabel, draggable, hasHeader, fixedSize, hasLabels, foldable)
4644
{ }
4745

48-
4946
protected override void DoListMiddle()
5047
{
5148
var rect = GUILayoutUtility.GetRect(0, MiddleHeight, GUILayout.ExpandWidth(true));
@@ -354,7 +351,6 @@ protected override int GetCoveredElementIndex(Vector2 mousePosition)
354351
return middleRect.Contains(mousePosition) ? GetCoveredElementIndex(mousePosition.y) : -1;
355352
}
356353

357-
358354
private float GetRowHeight(int index)
359355
{
360356
return GetElementHeight(index) + ElementSpacing;
@@ -396,7 +392,6 @@ private Rect GetRowRect(int index, Rect listRect)
396392
return new Rect(listRect.x, listRect.y + GetElementYOffset(index), listRect.width, GetElementHeight(index));
397393
}
398394

399-
400395
public void DoList(Rect rect)
401396
{
402397
var headerRect = new Rect(rect.x, rect.y, rect.width, HeaderHeight);
@@ -411,7 +406,6 @@ public void DoList(Rect rect)
411406
}
412407
}
413408

414-
415409
public float MiddleHeight
416410
{
417411
get

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

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ public abstract class ReorderableListBase
2222

2323
public delegate object OverrideNewElementDelegate(int index);
2424

25-
2625
public DrawRectCallbackDelegate drawHeaderCallback;
2726
public DrawRectCallbackDelegate drawEmptyCallback;
2827
public DrawRectCallbackDelegate drawFooterCallback;
@@ -50,7 +49,6 @@ public abstract class ReorderableListBase
5049

5150
public OverrideNewElementDelegate overrideNewElementCallback;
5251

53-
5452
protected const string defaultLabelFormat = "{0} {1}";
5553
protected const string defaultElementName = "Element";
5654

@@ -61,7 +59,6 @@ public abstract class ReorderableListBase
6159

6260
protected float draggedY;
6361

64-
6562
public ReorderableListBase(SerializedProperty list)
6663
: this(list, null, true, true, false)
6764
{ }
@@ -103,7 +100,6 @@ public ReorderableListBase(SerializedProperty list, string elementLabel, bool dr
103100
Index = -1;
104101
}
105102

106-
107103
private void DoDraggingAndSelection()
108104
{
109105
var isClicked = false;
@@ -264,12 +260,10 @@ private void DoDraggingAndSelection()
264260
}
265261
}
266262

267-
268263
protected abstract void DoListMiddle();
269264

270265
protected abstract void DoListMiddle(Rect middleRect);
271266

272-
273267
protected virtual bool DoListHeader()
274268
{
275269
if (!HasHeader)
@@ -405,7 +399,6 @@ protected virtual void HandleHeaderEvents(Rect rect)
405399

406400
protected abstract int GetCoveredElementIndex(Vector2 mousePosition);
407401

408-
409402
public string GetElementDefaultName(int index)
410403
{
411404
return string.Format(defaultLabelFormat, defaultElementName, index);
@@ -491,7 +484,6 @@ public void RemoveElement(int index)
491484
}
492485
}
493486

494-
495487
/// <summary>
496488
/// Draws whole list at once.
497489
/// </summary>
@@ -518,7 +510,6 @@ public virtual void DoList(GUIContent label)
518510
DoDraggingAndSelection();
519511
}
520512

521-
522513
#region Methods: Default interaction/draw calls/controls
523514

524515
/// <summary>
@@ -693,9 +684,7 @@ public virtual void DrawStandardElementHandle(Rect rect, int index, bool selecte
693684
rect.xMin += xDiff / 2;
694685
rect.xMax -= xDiff / 2;
695686

696-
var yDiff = rect.height - Style.handleHeight;
697-
rect.yMin += yDiff / 2;
698-
rect.yMax -= yDiff / 2;
687+
rect.y += Style.handleHeight + Style.spacing / 2;
699688
#if UNITY_2019_3_OR_NEWER
700689
rect.y += Style.spacing;
701690
#endif
@@ -733,7 +722,6 @@ public virtual void DrawStandardElementBackground(Rect rect, int index, bool sel
733722

734723
#endregion
735724

736-
737725
/// <summary>
738726
/// Index of the currently active (hovered) element.
739727
/// </summary>
@@ -864,7 +852,6 @@ public SerializedObject SerializedObject
864852
get => List.serializedObject;
865853
}
866854

867-
868855
/// <summary>
869856
/// Static representation of the standard list styling.
870857
/// Provides all needed <see cref="GUIStyle"/>s, paddings, widths, heights, etc.
@@ -896,7 +883,6 @@ protected static class Style
896883
internal static readonly float handleHeight = 7.0f;
897884
internal static readonly float dragAreaWidth = 40.0f;
898885
internal static readonly float sizeAreaWidth = 19.0f;
899-
internal static readonly float minEmptyHeight = 8.0f;
900886

901887
internal static readonly Color selectionColor = new Color(0.3f, 0.47f, 0.75f);
902888

@@ -923,7 +909,7 @@ static Style()
923909
iconToolbarAddContent = EditorGUIUtility.TrIconContent("Toolbar Plus", "Add to list");
924910
iconToolbarDropContent = EditorGUIUtility.TrIconContent("Toolbar Plus More", "Choose to add to list");
925911
iconToolbarRemoveContent = EditorGUIUtility.TrIconContent("Toolbar Minus", "Remove selection from list");
926-
emptyOrInvalidListContent = EditorGUIUtility.TrTextContent("List is Empty");
912+
emptyOrInvalidListContent = EditorGUIUtility.TrTextContent("Collection is Empty");
927913

928914
namePropertyStyle = new GUIStyle(EditorStyles.label)
929915
{

Assets/Editor Toolbox/Editor/Internal/ToolboxEditorList.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public class ToolboxEditorList : ReorderableListBase
2020
private Rect middleRect;
2121
private Rect headerRect;
2222

23-
2423
public ToolboxEditorList(SerializedProperty list)
2524
: base(list)
2625
{ }
@@ -41,7 +40,6 @@ public ToolboxEditorList(SerializedProperty list, string elementLabel, bool drag
4140
: base(list, elementLabel, draggable, hasHeader, fixedSize, hasLabels, foldable)
4241
{ }
4342

44-
4543
private void ValidateElementsRects(int arraySize)
4644
{
4745
if (elementsRects == null)
@@ -57,12 +55,20 @@ private void ValidateElementsRects(int arraySize)
5755
}
5856
}
5957

60-
private void DrawEmptyList()
58+
private void DrawEmptyList(Rect middleRect)
6159
{
6260
using (var emptyListGroup = new EditorGUILayout.VerticalScope(Style.contentGroupStyle))
6361
{
64-
var rect = EditorGUILayout.GetControlRect(GUILayout.Height(Style.minEmptyHeight));
65-
drawEmptyCallback?.Invoke(rect);
62+
if (drawEmptyCallback != null)
63+
{
64+
drawEmptyCallback.Invoke(middleRect);
65+
}
66+
else
67+
{
68+
var height = EditorGUIUtility.singleLineHeight;
69+
var rect = EditorGUILayout.GetControlRect(GUILayout.Height(height));
70+
EditorGUI.LabelField(rect, Style.emptyOrInvalidListContent);
71+
}
6672
}
6773
}
6874

@@ -198,7 +204,6 @@ private void DrawTargetGap(int targetIndex, int draggingIndex)
198204
EditorGUI.DrawRect(rect, Style.selectionColor);
199205
}
200206

201-
202207
protected override void DoListMiddle()
203208
{
204209
using (var middleGroup = new EditorGUILayout.VerticalScope())
@@ -230,7 +235,7 @@ protected override void DoListMiddle(Rect middleRect)
230235
//handle empty or invalid array
231236
if (!IsPropertyValid || !IsExpanded || IsEmpty)
232237
{
233-
DrawEmptyList();
238+
DrawEmptyList(middleRect);
234239
return;
235240
}
236241

@@ -340,7 +345,6 @@ protected override void HandleHeaderEvents(Rect rect)
340345
DraggingUtility.DoDragAndDropForProperty(rect, List);
341346
}
342347

343-
344348
/// <inheritdoc/>
345349
public override void DoList(GUIContent label)
346350
{
@@ -352,7 +356,6 @@ public override void DoList(GUIContent label)
352356
}
353357
}
354358

355-
356359
/// <inheritdoc/>
357360
public override float ElementSpacing { get; set; } = 1.0f;
358361

Assets/Editor Toolbox/Editor/ToolboxEditorGui.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ private static Rect GetLineRect(Rect rect, float thickness, float padding, bool
2525
/// Draws horizontal line.
2626
/// Uses built-in layouting system.
2727
/// </summary>
28-
public static void DrawLine(float thickness = 0.75f, float padding = 6.0f)
28+
public static void DrawLine(float thickness = 0.75f, float padding = 6.0f, bool horizontal = true)
2929
{
30-
DrawLine(thickness, padding, new Color(0.3f, 0.3f, 0.3f));
30+
DrawLine(thickness, padding, new Color(0.3f, 0.3f, 0.3f), horizontal);
3131
}
3232

3333
/// <summary>

0 commit comments

Comments
 (0)