Exemplo n.º 1
0
        public void Update(bool updateAll)
        {
            int count = mItemSizeGroupList.Count;

            if (count == 0 || 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;
                }
            }
        }
Exemplo n.º 2
0
        public void GetItemIndexAndPosAtGivenPos(float pos, ref int index, ref float itemPos)
        {
            Update(true);
            index   = 0;
            itemPos = 0f;
            int count = mItemSizeGroupList.Count;

            if (count == 0)
            {
                return;
            }

            ItemSizeGroup hitGroup = null;

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

            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;
                }
            }

            if (hitGroup == null)
            {
                return;
            }
            int hitIndex = hitGroup.GetItemIndexByPos(pos - hitGroup.mGroupStartPos);

            if (hitIndex < 0)
            {
                return;
            }

            index   = hitIndex + hitGroup.mGroupIndex * mItemMaxCountPerGroup;
            itemPos = hitGroup.GetItemStartPos(hitIndex);
        }
Exemplo n.º 3
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)
            {
                int d = needMaxGroupCount - count;
                for (int i = 0; i < d; ++i)
                {
                    ItemSizeGroup tGroup = new ItemSizeGroup(count + i, mItemDefaultSize);
                    mItemSizeGroupList.Add(tGroup);
                }
            }
            count = mItemSizeGroupList.Count;
            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;
            }
        }
Exemplo n.º 4
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;
        }