Esempio n. 1
0
        public bool GetItemIndexAndPosAtGivenPos(float pos, ref int index, ref float itemPos)
        {
            Update(true);
            index   = 0;
            itemPos = 0f;
            int count = mItemSizeGroupList.Count;

            if (count == 0)
            {
                return(true);
            }
            ItemSizeGroup hitGroup = null;

            int low  = 0;
            int high = count - 1;

            if (mItemDefaultSize == 0f)
            {
                if (mMaxNotEmptyGroupIndex < 0)
                {
                    mMaxNotEmptyGroupIndex = 0;
                }
                high = mMaxNotEmptyGroupIndex;
            }
            while (low <= high)
            {
                int           mid    = (low + high) / 2;
                ItemSizeGroup tGroup = mItemSizeGroupList[mid];
                if (tGroup.mGroupStartPos <= pos && tGroup.mGroupEndPos >= pos)
                {
                    hitGroup = tGroup;
                    break;
                }
                else if (pos > tGroup.mGroupEndPos)
                {
                    low = mid + 1;
                }
                else
                {
                    high = mid - 1;
                }
            }
            int hitIndex = -1;

            if (hitGroup != null)
            {
                hitIndex = hitGroup.GetItemIndexByPos(pos - hitGroup.mGroupStartPos);
            }
            else
            {
                return(false);
            }
            if (hitIndex < 0)
            {
                return(false);
            }
            index   = hitIndex + hitGroup.mGroupIndex * mItemMaxCountPerGroup;
            itemPos = hitGroup.GetItemStartPos(hitIndex);
            return(true);
        }
Esempio n. 2
0
        public void SetItemSize(int itemIndex, float size)
        {
            int           groupIndex   = itemIndex / mItemMaxCountPerGroup;
            int           indexInGroup = itemIndex % mItemMaxCountPerGroup;
            ItemSizeGroup tGroup       = mItemSizeGroupList[groupIndex];
            float         changedSize  = tGroup.SetItemSize(indexInGroup, size);

            if (changedSize != 0f)
            {
                if (groupIndex < mDirtyBeginIndex)
                {
                    mDirtyBeginIndex = groupIndex;
                }
            }
            mTotalSize += changedSize;
            if (groupIndex > mMaxNotEmptyGroupIndex && size > 0)
            {
                mMaxNotEmptyGroupIndex = groupIndex;
            }
        }
Esempio n. 3
0
        public void Update(bool updateAll)
        {
            int count = mItemSizeGroupList.Count;

            if (count == 0)
            {
                return;
            }
            if (mDirtyBeginIndex >= count)
            {
                return;
            }
            int loopCount = 0;

            for (int i = mDirtyBeginIndex; i < count; ++i)
            {
                loopCount++;
                ItemSizeGroup tGroup = mItemSizeGroupList[i];
                mDirtyBeginIndex++;
                tGroup.UpdateAllItemStartPos();
                if (i == 0)
                {
                    tGroup.mGroupStartPos = 0;
                    tGroup.mGroupEndPos   = tGroup.mGroupSize;
                }
                else
                {
                    tGroup.mGroupStartPos = mItemSizeGroupList[i - 1].mGroupEndPos;
                    tGroup.mGroupEndPos   = tGroup.mGroupStartPos + tGroup.mGroupSize;
                }
                if (!updateAll && loopCount > 1)
                {
                    return;
                }
            }
        }
Esempio n. 4
0
        public void SetItemMaxCount(int maxCount)
        {
            mDirtyBeginIndex = 0;
            mTotalSize       = 0;
            int st = maxCount % mItemMaxCountPerGroup;
            int lastGroupItemCount = st;
            int needMaxGroupCount  = maxCount / mItemMaxCountPerGroup;

            if (st > 0)
            {
                needMaxGroupCount++;
            }
            else
            {
                lastGroupItemCount = mItemMaxCountPerGroup;
            }
            int count = mItemSizeGroupList.Count;

            if (count > needMaxGroupCount)
            {
                int d = count - needMaxGroupCount;
                mItemSizeGroupList.RemoveRange(needMaxGroupCount, d);
            }
            else if (count < needMaxGroupCount)
            {
                if (count > 0)
                {
                    mItemSizeGroupList[count - 1].ClearOldData();
                }
                int d = needMaxGroupCount - count;
                for (int i = 0; i < d; ++i)
                {
                    ItemSizeGroup tGroup = new ItemSizeGroup(count + i, mItemDefaultSize);
                    mItemSizeGroupList.Add(tGroup);
                }
            }
            else
            {
                if (count > 0)
                {
                    mItemSizeGroupList[count - 1].ClearOldData();
                }
            }
            count = mItemSizeGroupList.Count;
            if ((count - 1) < mMaxNotEmptyGroupIndex)
            {
                mMaxNotEmptyGroupIndex = count - 1;
            }
            if (mMaxNotEmptyGroupIndex < 0)
            {
                mMaxNotEmptyGroupIndex = 0;
            }
            if (count == 0)
            {
                return;
            }
            for (int i = 0; i < count - 1; ++i)
            {
                mItemSizeGroupList[i].SetItemCount(mItemMaxCountPerGroup);
            }
            mItemSizeGroupList[count - 1].SetItemCount(lastGroupItemCount);
            for (int i = 0; i < count; ++i)
            {
                mTotalSize = mTotalSize + mItemSizeGroupList[i].mGroupSize;
            }
        }