コード例 #1
0
        /// <inheritdoc/>
        public override void ChangeItemsCount(ItemCountChangeMode changeMode, int cellsCount, int indexIfAppendingOrRemoving = -1, bool contentPanelEndEdgeStationary = false, bool keepVelocity = false)
        {
            base.ChangeItemsCount(changeMode, cellsCount, indexIfAppendingOrRemoving, contentPanelEndEdgeStationary, keepVelocity);

            // Showing a loading indicator when there are no items
            SetWaitingForData(GetItemsCount() == 0);
        }
コード例 #2
0
        /// <inheritdoc/>
        protected override void CollectItemsSizes(ItemCountChangeMode changeMode, int count, int indexIfInsertingOrRemoving, ItemsDescriptor itemsDesc)
        {
            base.CollectItemsSizes(changeMode, count, indexIfInsertingOrRemoving, itemsDesc);

            // CollectItemsSizes is called whenever the items count changes, but before the view is actually updated.
            // The reason we need it here is that when inserting an item, it's initial size will be _Params.DefaultItemSize
            // (which is taken from the prefab's actual size), but we want it to be NON_EXPANDED_SIZE (which is close to zero),
            // so we can expand it after.
            // It's not something very important, but it looks a bit odd without it

            if (changeMode != ItemCountChangeMode.INSERT)
            {
                return;
            }

            if (count > 1)
            {
                // Not an animated insertion, since the count would've been 1 in that case
                return;
            }

            if (_InsertDeleteAnimation == null)
            {
                // No animation running => the item will directly appear expanded (with _Params.DefaultItemSize)
                return;
            }

            if (_InsertDeleteAnimation.itemIndex == indexIfInsertingOrRemoving)
            {
                itemsDesc.BeginChangingItemsSizes(indexIfInsertingOrRemoving);
                itemsDesc[indexIfInsertingOrRemoving] = NON_EXPANDED_SIZE;
                itemsDesc.EndChangingItemsSizes();
            }
        }
コード例 #3
0
        protected override void CollectItemsSizes(ItemCountChangeMode changeMode, int count, int indexIfInsertingOrRemoving, ItemsDescriptor itemsDesc)
        {
            base.CollectItemsSizes(changeMode, count, indexIfInsertingOrRemoving, itemsDesc);

            if (changeMode != ItemCountChangeMode.RESET)
            {
                return;
            }

            if (count == 0)
            {
                return;
            }

            // Randomize sizes
            int indexOfFirstItemThatWillChangeSize = 0;
            int end = indexOfFirstItemThatWillChangeSize + count;

            itemsDesc.BeginChangingItemsSizes(indexOfFirstItemThatWillChangeSize);
            for (int i = indexOfFirstItemThatWillChangeSize; i < end; ++i)
            {
                itemsDesc[i] = UnityEngine.Random.Range(_Params.DefaultItemSize / 3, _Params.DefaultItemSize * 3);
            }
            itemsDesc.EndChangingItemsSizes();
        }
コード例 #4
0
        public override void ChangeItemsCount(ItemCountChangeMode changeMode, int itemsCount, int indexIfInsertingOrRemoving = -1, bool contentPanelEndEdgeStationary = false, bool keepVelocity = false)
        {
            // No animation should be preserved between count changes
            _ExpandCollapseAnimation = null;

            base.ChangeItemsCount(changeMode, itemsCount, indexIfInsertingOrRemoving, contentPanelEndEdgeStationary, keepVelocity);
        }
コード例 #5
0
        /// <inheritdoc/>
        public override void ChangeItemsCount(ItemCountChangeMode changeMode, int itemsCount, int indexIfInsertingOrRemoving = -1, bool contentPanelEndEdgeStationary = false, bool keepVelocity = false)
        {
            base.ChangeItemsCount(changeMode, itemsCount, indexIfInsertingOrRemoving, contentPanelEndEdgeStationary, keepVelocity);

            if (OnItemsUpdated != null)
            {
                OnItemsUpdated.Invoke();
            }
        }
コード例 #6
0
        public void ReinitializeSizes(ItemCountChangeMode changeMode, int count, int indexIfInsertingOrRemoving = -1, float?newDefaultSize = null)
        {
            if (newDefaultSize != null)
            {
                if (newDefaultSize != _DefaultSize)
                {
                    if (changeMode != ItemCountChangeMode.RESET)
                    {
                        throw new UnityException("Cannot preserve old sizes if the newDefaultSize is different!");
                    }

                    _DefaultSize = newDefaultSize.Value;
                }
            }

            if (changeMode == ItemCountChangeMode.RESET)
            {
                _Sizes.Clear();
                _SizesCumulative.Clear();
                _Keys.Clear();
                itemsCount = count;

                return;
            }

            if (indexIfInsertingOrRemoving < 0 || indexIfInsertingOrRemoving > itemsCount)
            {
                throw new ArgumentOutOfRangeException("indexIfInsertingOrRemoving", indexIfInsertingOrRemoving, "Should be positive and less than itemsCount=" + itemsCount);
            }

            int newCount;

            if (changeMode == ItemCountChangeMode.INSERT)
            {
                ShiftSizesKeys(indexIfInsertingOrRemoving, count);

                newCount = itemsCount + count;
            }
            else
            {
                if (count < 0)
                {
                    throw new ArgumentOutOfRangeException("count", count, "Cannot be negative!");
                }

                if (indexIfInsertingOrRemoving + count > itemsCount)
                {
                    throw new ArgumentOutOfRangeException("RemoveItems: index + count", indexIfInsertingOrRemoving + count, "Should be positive and less than- or or equal to itemsCount=" + itemsCount);
                }

                count = -count;
                ShiftSizesKeys(indexIfInsertingOrRemoving, count);
                newCount = itemsCount + count;
            }
            itemsCount = newCount;
        }
コード例 #7
0
        /// <inheritdoc/>
        public override void ChangeItemsCount(ItemCountChangeMode changeMode, int itemsCount, int indexIfInsertingOrRemoving = -1, bool contentPanelEndEdgeStationary = false, bool keepVelocity = false)
        {
            // No animation should be preserved between count changes.
            // In case of insertion and removals, we don't touch it, since we expect those to be handled by the AnimatedInsert and AnimatedRemove, respectively
            if (changeMode == ItemCountChangeMode.RESET)
            {
                _InsertDeleteAnimation = null;
            }

            base.ChangeItemsCount(changeMode, itemsCount, indexIfInsertingOrRemoving, contentPanelEndEdgeStationary, keepVelocity);
        }
コード例 #8
0
        /// <inheritdoc/>
        public override void ChangeItemsCount(ItemCountChangeMode changeMode, int cellsCount, int indexIfAppendingOrRemoving = -1, bool contentPanelEndEdgeStationary = false, bool keepVelocity = false)
        {
            // Assure nothing is selected before changing the count
            // Update: not calling RefreshSelectionStateForVisibleCells(), since UpdateCellViewsHolder() will be called for all cells anyway
            if (_SelectionMode)
            {
                SetSelectionMode(false);
            }
            UpdateSelectionActionButtons();

            base.ChangeItemsCount(changeMode, cellsCount, indexIfAppendingOrRemoving, contentPanelEndEdgeStationary, keepVelocity);
        }
コード例 #9
0
        /// <summary>
        /// See <see cref="OSA{TParams, TItemViewsHolder}.ChangeItemsCount(ItemCountChangeMode, int, int, bool, bool)"/>
        /// </summary>
        /// <param name="changeMode"></param>
        /// <param name="itemsCount"></param>
        /// <param name="indexIfInsertingOrRemoving"></param>
        /// <param name="contentPanelEndEdgeStationary"></param>
        /// <param name="keepVelocity"></param>
        public override void ChangeItemsCount(ItemCountChangeMode changeMode, int itemsCount, int indexIfInsertingOrRemoving = -1, bool contentPanelEndEdgeStationary = false, bool keepVelocity = false)
        {
            // On any adding/resetting items, invalidate current sorting types of current columns
            // When items are removed, sorting remains valid
            if (changeMode != ItemCountChangeMode.REMOVE)
            {
                InvalidateAnyColumnSorting();
            }

            InvalidateOptionsPanelState();

            base.ChangeItemsCount(changeMode, itemsCount, indexIfInsertingOrRemoving, contentPanelEndEdgeStationary, keepVelocity);
        }
コード例 #10
0
        /// <summary> Overridden in order to convert the cellsCount to groupsCount before passing it to the base's implementation</summary>
        /// <seealso cref="SRIA{TParams, TItemViewsHolder}.ChangeItemsCount(ItemCountChangeMode, int, int, bool, bool)"/>
        public override void ChangeItemsCount(
            ItemCountChangeMode changeMode,
            int cellsCount /*param name changed from itemsCount*/,
            int indexIfAppendingOrRemoving     = -1,
            bool contentPanelEndEdgeStationary = false,
            bool keepVelocity = false
            )
        {
            if (changeMode != ItemCountChangeMode.RESET)
            {
                throw new InvalidOperationException("Only ItemCountChangeMode.RESET is supported with a GridAdapter for now");
            }

            _CellsCount = cellsCount;

            // The number of groups is passed to the base's implementation
            int groupsCount = _Params.GetNumberOfRequiredGroups(_CellsCount);

            base.ChangeItemsCount(changeMode, groupsCount, indexIfAppendingOrRemoving, contentPanelEndEdgeStationary, keepVelocity);
        }
コード例 #11
0
        public void ReinitializeSizes(
            ItemCountChangeMode changeMode,
            int count,
            int indexIfInsertingOrRemoving,
            double?newDefaultSize = null
            )
        {
            if (newDefaultSize != null)
            {
                if (newDefaultSize != _DefaultSize)
                {
                    if (changeMode != ItemCountChangeMode.RESET)
                    {
                        throw new OSAException("Cannot preserve old sizes if the newDefaultITemSize is different!");
                    }

                    _DefaultSize = newDefaultSize.Value;
                    //_AverageSize = _DefaultSize = newDefaultSize.Value;
                }
                AssureValidDefaultItemSizeOrThrow();
            }

            int newCount;

            if (changeMode == ItemCountChangeMode.RESET)
            {
                newCount = count;
                if (newCount < 0)
                {
                    throw new ArgumentOutOfRangeException("OSA.ItemsDescriptor.ReinitializeSizes: Can't have negative count: " + newCount);
                }

                ClearAllKeysAndSizes();
            }
            else
            {
                if (indexIfInsertingOrRemoving < 0)
                {
                    throw new ArgumentOutOfRangeException("indexIfInsertingOrRemoving", indexIfInsertingOrRemoving, "Should be positive or 0");
                }

                if (count < 0)
                {
                    throw new ArgumentOutOfRangeException("count", count, "Cannot be negative!");
                }

                if (changeMode == ItemCountChangeMode.REMOVE)
                {
                    if (indexIfInsertingOrRemoving + count > itemsCount)
                    {
                        throw new ArgumentOutOfRangeException("RemoveItems: index + count", indexIfInsertingOrRemoving + count, "Should be positive and less than- or or equal to itemsCount=" + itemsCount);
                    }
                }
                else
                {
                    if (indexIfInsertingOrRemoving > itemsCount)
                    {
                        throw new ArgumentOutOfRangeException("InsertItems: indexIfInsertingOrRemoving", indexIfInsertingOrRemoving, "Should be positive and less than- or equal to itemsCount=" + itemsCount);
                    }
                }

                int change = (int)changeMode * count;
                newCount = itemsCount + change;
                if (newCount < 0)
                {
                    throw new ArgumentOutOfRangeException("newCount", "OSA.ItemsDescriptor.ReinitializeSizes: Can't have negative count " + newCount);
                }

                if (newCount == 0)
                {
                    ClearAllKeysAndSizes();
                }
                else
                {
                    if (itemsCount > 0)
                    {
                        if (indexIfInsertingOrRemoving < itemsCount)                         // if it's the same, it means we're adding at the end, which doesn't require keys shifting
                        {
                            ShiftSizesKeysAfterInsertOrRemove(GetItemViewIndexFromRealIndexChecked(indexIfInsertingOrRemoving), change);
                        }
                    }
                }
            }
            itemsCount = newCount;
        }
コード例 #12
0
        public void ReinitializeRealIndexOfFirstItemInView(
            int oldCount,
            ItemCountChangeMode changeMode,
            int count,
            int indexIfInsertingOrRemoving,
            int itemIndexOfFirstVHIfInsertingOrRemoving,
            bool canLoop)
        {
            int newCount = itemsCount;

            if (newCount == 0)
            {
                realIndexOfFirstItemInView = -1;
                return;
            }

            if (changeMode == ItemCountChangeMode.RESET)
            {
                realIndexOfFirstItemInView = 0;
                return;
            }

            if (canLoop)
            {
                throw new OSAException("At the moment, only ItemCountChangeMode.RESET is supported when looping");
            }

            realIndexOfFirstItemInView = 0;

            //int oldRealIndexOfFirstItemInView = realIndexOfFirstItemInView;
            //realIndexOfFirstItemInView = 0;
            //if (canLoop && oldRealIndexOfFirstItemInView >= 0)
            //{
            //	if (changeMode == ItemCountChangeMode.REMOVE)
            //	{
            //		int itemsAfterRealIndexPrev = oldCount - oldRealIndexOfFirstItemInView;
            //		if (itemsAfterRealIndexPrev < count)
            //			throw new OSAException("Looping and itemsAfterRealIndexPrev < removeCount, " + itemsAfterRealIndexPrev + "<" + count);
            //	}

            //	if (itemIndexOfFirstVHIfInsertingOrRemoving < 0)
            //		return;

            //	int change = (int)changeMode * count;
            //	realIndexOfFirstItemInView = oldRealIndexOfFirstItemInView;
            //	if (itemIndexOfFirstVHIfInsertingOrRemoving > indexIfInsertingOrRemoving
            //		|| oldRealIndexOfFirstItemInView >= indexIfInsertingOrRemoving && itemIndexOfFirstVHIfInsertingOrRemoving != 0)
            //	{
            //		realIndexOfFirstItemInView += change;
            //	}

            //	//if (indexIfInsertingOrRemoving < oldRealIndexOfFirstItemInView)
            //	//{
            //	//	realIndexOfFirstItemInView += change;

            //	//}
            //	//else if (indexIfInsertingOrRemoving == oldRealIndexOfFirstItemInView)
            //	//{
            //	//	if (changeMode == ItemCountChangeMode.REMOVE)
            //	//	{
            //	//		int itemsAfterRealIndexPrev = oldCount - oldRealIndexOfFirstItemInView;
            //	//		if (itemsAfterRealIndexPrev < count)
            //	//			throw new OSAException("itemsAfterRealIndexPrev < count, " + itemsAfterRealIndexPrev + "<" + count);

            //	//		realIndexOfFirstItemInView += change;
            //	//	}
            //	//	else
            //	//		realIndexOfFirstItemInView += change;
            //	//}
            //	//else
            //	//{
            //	//	// Bugfix: in case of looping, items are not shifted towards end anymore, only their ItemIndex is increased,
            //	//	// but because no items are added before the viewport in this case, realIndexOfFirstItemInView should
            //	//	// also increase to keep the ItemIndex distance from the first VH the same
            //	//	// Similar case if removing
            //	//	realIndexOfFirstItemInView += change;
            //	//}
            //}
        }
コード例 #13
0
 /// <summary>
 /// This is called during changing the items count.
 /// The base implementation reinitializes the items descriptor so that all items will have the same size, specified in <see cref="BaseParams.DefaultItemSize"/>
 /// If overriding the method and the item default size should remain the same as <see cref="BaseParams.DefaultItemSize"/>,
 /// don't forget to call the base implementation! Otherwise, call <see cref="ItemsDescriptor.ReinitializeSizes(ItemCountChangeMode, int, int, float?)"/> with the new default size as parameter.
 /// Use <see cref="ItemsDescriptor.BeginChangingItemsSizes(int)"/> before and <see cref="ItemsDescriptor.EndChangingItemsSizes()"/> after
 /// setting sizes. The indices of items for which you set custom sizes must be one after another (4,5,6,7.. etc). Gaps are not allowed.
 /// Use "itemsDesc[itemIndexInView] = size" syntax for setting custom sizes. In this call, <see cref="AbstractViewsHolder.ItemIndex"/> will be the same as <see cref="BaseItemViewsHolder.itemIndexInView"/>, even if looping is enabled.
 /// </summary>
 /// <param name="itemsDesc">The container for all the info related to items' sizes</param>
 protected virtual void CollectItemsSizes(ItemCountChangeMode changeMode, int count, int indexIfInsertingOrRemoving, ItemsDescriptor itemsDesc)
 {
     itemsDesc.ReinitializeSizes(changeMode, count, indexIfInsertingOrRemoving, _Params.DefaultItemSize);
 }
コード例 #14
0
 /// <summary>Self-explanatory. See <see cref="ItemCountChangeMode"/> in order to understand how change modes differ from each other.</summary>
 public virtual void ChangeItemsCount(ItemCountChangeMode changeMode, int itemsCount, int indexIfInsertingOrRemoving = -1, bool contentPanelEndEdgeStationary = false, bool keepVelocity = false)
 {
     ChangeItemsCountInternal(changeMode, itemsCount, indexIfInsertingOrRemoving, contentPanelEndEdgeStationary, keepVelocity);
 }
コード例 #15
0
        /// <inheritdoc/>
        public override void ChangeItemsCount(ItemCountChangeMode changeMode, int itemsCount, int indexIfInsertingOrRemoving = -1, bool contentPanelEndEdgeStationary = false, bool keepVelocity = false)
        {
            _IndexOfCurrentlyExpandedItem = -1;             // at initialization, and each time the item count changes, this should be invalidated

            base.ChangeItemsCount(changeMode, itemsCount, indexIfInsertingOrRemoving, contentPanelEndEdgeStationary, keepVelocity);
        }
コード例 #16
0
        void ChangeItemsCountInternal(ItemCountChangeMode changeMode, int count, int indexIfInsertingOrRemoving, bool contentPanelEndEdgeStationary, bool keepVelocity)
        {
            CancelAnimationsIfAny();

            var ignoreOnScroll_valueBefore = _SkipComputeVisibilityInUpdateOrOnScroll;

            _SkipComputeVisibilityInUpdateOrOnScroll = true;

            int prevCount = _ItemsDesc.itemsCount;
            var velocity  = _Collocation.scrollRect.velocity;

            if (!keepVelocity)
            {
                _Collocation.scrollRect.StopMovement();
            }

            double sizeOfAllItemsBefore = _ItemsDesc.CumulatedSizeOfAllItems;

            _ItemsDesc.realIndexOfFirstItemInView = count > 0 ? 0 : -1;
            CollectItemsSizes(changeMode, count, indexIfInsertingOrRemoving, _ItemsDesc);

            double sizeOfAllItemsAfter            = _ItemsDesc.CumulatedSizeOfAllItems;
            bool   vrtContentPanelIsAtOrBeforeEnd = _InternalState.ContentPanelVirtualInsetFromViewportEnd >= 0d;

            if (sizeOfAllItemsAfter <= sizeOfAllItemsBefore)             // content has shrunk
            {
                if (_InternalState.ContentPanelVirtualInsetFromViewportStart >= 0d)
                {
                    contentPanelEndEdgeStationary = false;
                }
                else if (vrtContentPanelIsAtOrBeforeEnd)
                {
                    contentPanelEndEdgeStationary = true;
                }
            }

            _InternalState.OnItemsCountChanged(prevCount, contentPanelEndEdgeStationary);
            if (GetNumExcessObjects() > 0)
            {
                throw new UnityException("ChangeItemsCountInternal: GetNumExcessObjects() > 0 when calling ChangeItemsCountInternal(); this may be due ComputeVisibility not being finished executing yet");
            }

            _RecyclableItems.AddRange(_VisibleItems);

            if (count == 0)
            {
                ClearCachedRecyclableItems();
            }

            _VisibleItems.Clear();
            _VisibleItemsCount = 0;

            double reportedScrollDelta;

            if (contentPanelEndEdgeStationary)
            {
                reportedScrollDelta = .1f;
            }
            else
            {
                reportedScrollDelta = -.1f;

                if (vrtContentPanelIsAtOrBeforeEnd)
                {
                    reportedScrollDelta = .1f;
                }
            }

            ComputeVisibilityForCurrentPosition(true, true, true, reportedScrollDelta);
            if (!_CorrectedPositionInCurrentComputeVisibilityPass)
            {
                CorrectPositionsOfVisibleItems(true);
            }

            if (keepVelocity)
            {
                _Collocation.scrollRect.velocity = velocity;
            }

            if (ItemsRefreshed != null)
            {
                ItemsRefreshed(prevCount, count);
            }

            _SkipComputeVisibilityInUpdateOrOnScroll = ignoreOnScroll_valueBefore;
        }