From 93f9a314cf3845382c772ecccd6c987d40d69443 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Gonz=C3=A1lez?= Date: Tue, 9 Apr 2019 20:35:34 -0400 Subject: [PATCH 1/2] Added a new Event to ReorderableList: OnElementDroppedWithMaxItems. It is called when an object is dropped on a ReorderableList with no more space left (currentItems >= maxItems). --- .../ReorderableList/ReorderableList.cs | 1 + .../ReorderableList/ReorderableListElement.cs | 28 +++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/Scripts/Controls/ReorderableList/ReorderableList.cs b/Scripts/Controls/ReorderableList/ReorderableList.cs index 30e256e..188cd86 100644 --- a/Scripts/Controls/ReorderableList/ReorderableList.cs +++ b/Scripts/Controls/ReorderableList/ReorderableList.cs @@ -41,6 +41,7 @@ namespace UnityEngine.UI.Extensions public ReorderableListHandler OnElementDisplacedTo = new ReorderableListHandler(); public ReorderableListHandler OnElementDisplacedFromReturned = new ReorderableListHandler(); public ReorderableListHandler OnElementDisplacedToReturned = new ReorderableListHandler(); + public ReorderableListHandler OnElementDroppedWithMaxItems = new ReorderableListHandler(); private RectTransform _content; private ReorderableListContent _listContent; diff --git a/Scripts/Controls/ReorderableList/ReorderableListElement.cs b/Scripts/Controls/ReorderableList/ReorderableListElement.cs index 4c227fe..5db86bf 100644 --- a/Scripts/Controls/ReorderableList/ReorderableListElement.cs +++ b/Scripts/Controls/ReorderableList/ReorderableListElement.cs @@ -392,12 +392,11 @@ namespace UnityEngine.UI.Extensions if (!isValid) throw new Exception("It's too late to cancel the Transfer! Do so in OnElementDropped!"); - - } - //We don't have an ReorderableList + else { + //We don't have an ReorderableList if (this.isDroppableInSpace) { _reorderableList.OnElementDropped.Invoke(new ReorderableList.ReorderableListEventStruct @@ -414,6 +413,29 @@ namespace UnityEngine.UI.Extensions { CancelDrag(); } + + //If there is no more room for the element in the target list, notify it (OnElementDroppedWithMaxItems event) + if (_currentReorderableListRaycasted != null) + { + if ((_currentReorderableListRaycasted.Content.childCount >= + _currentReorderableListRaycasted.maxItems && + !_currentReorderableListRaycasted.IsDisplacable) + || _currentReorderableListRaycasted.maxItems <= 0) + { + GameObject o = _draggingObject.gameObject; + _reorderableList.OnElementDroppedWithMaxItems.Invoke( + new ReorderableList.ReorderableListEventStruct + { + DroppedObject = o, + IsAClone = _reorderableList.CloneDraggedObject, + SourceObject = _reorderableList.CloneDraggedObject ? gameObject : o, + FromList = _reorderableList, + ToList = _currentReorderableListRaycasted, + FromIndex = _fromIndex + }); + } + } + } } From 61aab3765b836e35e87ef96f2d5d287b2df22931 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Gonz=C3=A1lez?= Date: Wed, 10 Apr 2019 09:43:17 -0400 Subject: [PATCH 2/2] Reorderable lists now have a new field "EqualizeSizesOnDrag", default to false. When it is true it sets every item size (when being dragged over the current list) to the current size of the first element of the list. true was the default behaviour before, and it might be useful in some cases so I left the option there, but in most use cases I encountered so far, and according to Issue 268 (https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/issues/268/re-orderable-lists-different-width-height) the false behaviour is expected. --- Scripts/Controls/ReorderableList/ReorderableList.cs | 4 ++++ Scripts/Controls/ReorderableList/ReorderableListElement.cs | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Scripts/Controls/ReorderableList/ReorderableList.cs b/Scripts/Controls/ReorderableList/ReorderableList.cs index 188cd86..c010421 100644 --- a/Scripts/Controls/ReorderableList/ReorderableList.cs +++ b/Scripts/Controls/ReorderableList/ReorderableList.cs @@ -28,6 +28,10 @@ namespace UnityEngine.UI.Extensions [Tooltip("Should dropped items displace a current item if the list is full?\n " + "Depending on the dropped items origin list, the displaced item may be added, dropped in space or deleted.")] public bool IsDisplacable = false; + + // This sets every item size (when being dragged over this list) to the current size of the first element of this list + [Tooltip("Should items being dragged over this list have their sizes equalized?")] + public bool EqualizeSizesOnDrag = false; public int maxItems = int.MaxValue; diff --git a/Scripts/Controls/ReorderableList/ReorderableListElement.cs b/Scripts/Controls/ReorderableList/ReorderableListElement.cs index 5db86bf..adcee13 100644 --- a/Scripts/Controls/ReorderableList/ReorderableListElement.cs +++ b/Scripts/Controls/ReorderableList/ReorderableListElement.cs @@ -505,7 +505,10 @@ namespace UnityEngine.UI.Extensions { Vector2 size = _draggingObjectOriginalSize; - if (_currentReorderableListRaycasted != null && _currentReorderableListRaycasted.IsDropable && _currentReorderableListRaycasted.Content.childCount > 0) + if (_currentReorderableListRaycasted != null + && _currentReorderableListRaycasted.IsDropable + && _currentReorderableListRaycasted.Content.childCount > 0 + && _currentReorderableListRaycasted.EqualizeSizesOnDrag) { var firstChild = _currentReorderableListRaycasted.Content.GetChild(0); if (firstChild != null)