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); }
public void Update(bool updateAll) { int count = this.mItemSizeGroupList.Count; if (count == 0 || this.mDirtyBeginIndex >= count) { return; } int num = 0; for (int mDirtyBeginIndex = this.mDirtyBeginIndex; mDirtyBeginIndex < count; ++mDirtyBeginIndex) { ++num; ItemSizeGroup mItemSizeGroup = this.mItemSizeGroupList[mDirtyBeginIndex]; ++this.mDirtyBeginIndex; mItemSizeGroup.UpdateAllItemStartPos(); if (mDirtyBeginIndex == 0) { mItemSizeGroup.mGroupStartPos = 0.0f; mItemSizeGroup.mGroupEndPos = mItemSizeGroup.mGroupSize; } else { mItemSizeGroup.mGroupStartPos = this.mItemSizeGroupList[mDirtyBeginIndex - 1].mGroupEndPos; mItemSizeGroup.mGroupEndPos = mItemSizeGroup.mGroupStartPos + mItemSizeGroup.mGroupSize; } if (!updateAll && num > 1) { break; } } }
public bool GetItemIndexAndPosAtGivenPos(float pos, ref int index, ref float itemPos) { this.Update(true); index = 0; itemPos = 0.0f; int count = this.mItemSizeGroupList.Count; if (count == 0) { return(true); } ItemSizeGroup itemSizeGroup = (ItemSizeGroup)null; int num1 = 0; int num2 = count - 1; if ((double)this.mItemDefaultSize == 0.0) { if (this.mMaxNotEmptyGroupIndex < 0) { this.mMaxNotEmptyGroupIndex = 0; } num2 = this.mMaxNotEmptyGroupIndex; } while (num1 <= num2) { int index1 = (num1 + num2) / 2; ItemSizeGroup mItemSizeGroup = this.mItemSizeGroupList[index1]; if ((double)mItemSizeGroup.mGroupStartPos <= (double)pos && (double)mItemSizeGroup.mGroupEndPos >= (double)pos) { itemSizeGroup = mItemSizeGroup; break; } if ((double)pos > (double)mItemSizeGroup.mGroupEndPos) { num1 = index1 + 1; } else { num2 = index1 - 1; } } if (itemSizeGroup == null) { return(false); } int itemIndexByPos = itemSizeGroup.GetItemIndexByPos(pos - itemSizeGroup.mGroupStartPos); if (itemIndexByPos < 0) { return(false); } index = itemIndexByPos + itemSizeGroup.mGroupIndex * 100; itemPos = itemSizeGroup.GetItemStartPos(itemIndexByPos); return(true); }
public void GetItemIndexAndPosAtGivenPos(float pos, ref int index, ref float itemPos) { this.Update(true); index = 0; itemPos = 0f; int count = this.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 = this.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; } if (hitIndex < 0) { return; } index = hitIndex + hitGroup.mGroupIndex * mItemMaxCountPerGroup; itemPos = hitGroup.GetItemStartPos(hitIndex); }
public void SetItemSize(int itemIndex, float size) { int groupIndex = itemIndex / mItemMaxCountPerGroup; int indexInGroup = itemIndex % mItemMaxCountPerGroup; ItemSizeGroup tGroup = this.mItemSizeGroupList[groupIndex]; float changedSize = tGroup.SetItemSize(indexInGroup, size); if (changedSize != 0f) { if (groupIndex < this.mDirtyBeginIndex) { this.mDirtyBeginIndex = groupIndex; } } this.mTotalSize += changedSize; }
public void SetItemMaxCount(int maxCount) { this.mDirtyBeginIndex = 0; this.mTotalSize = 0; int st = maxCount % mItemMaxCountPerGroup; int lastGroupItemCount = st; int needMaxGroupCount = maxCount / mItemMaxCountPerGroup; if (st > 0) { needMaxGroupCount++; } else { lastGroupItemCount = mItemMaxCountPerGroup; } int count = this.mItemSizeGroupList.Count; if (count > needMaxGroupCount) { int d = count - needMaxGroupCount; this.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, this.mItemDefaultSize); this.mItemSizeGroupList.Add(tGroup); } } count = this.mItemSizeGroupList.Count; if (count == 0) { return; } for (int i = 0; i < count - 1; ++i) { this.mItemSizeGroupList[i].SetItemCount(mItemMaxCountPerGroup); } this.mItemSizeGroupList[count - 1].SetItemCount(lastGroupItemCount); for (int i = 0; i < count; ++i) { this.mTotalSize = this.mTotalSize + this.mItemSizeGroupList[i].mGroupSize; } }
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; } }
//根据总Item索引设置size大小 public void SetItemSize(int itemIndex, float size) { int groupIndex = itemIndex / mItemMaxCountPerGroup; //Item所在组的索引 int indexInGroup = itemIndex % mItemMaxCountPerGroup; //在组内的索引 ItemSizeGroup tGroup = mItemSizeGroupList[groupIndex]; float changedSize = tGroup.SetItemSize(indexInGroup, size); //更新总索引为itemIndex出的数据-》size,并返回新的Item大小减去之前的大小的差值 if (changedSize != 0f) { if (groupIndex < mDirtyBeginIndex) {//更新 mDirtyBeginIndex = groupIndex; } } mTotalSize += changedSize;//更新大小 if (groupIndex > mMaxNotEmptyGroupIndex && size > 0) { //更新最大不为空的组在链表中的索引 mMaxNotEmptyGroupIndex = groupIndex; } }
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; } } }
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; } }
//设置Item最大数量 public void SetItemMaxCount(int maxCount) { mDirtyBeginIndex = 0; mTotalSize = 0; int st = maxCount % mItemMaxCountPerGroup; int lastGroupItemCount = st; //最后一组Itme计数 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) { //设置每组的Item的数量 mItemSizeGroupList[i].SetItemCount(mItemMaxCountPerGroup); } mItemSizeGroupList[count - 1].SetItemCount(lastGroupItemCount); for (int i = 0; i < count; ++i) { //设置总大小 mTotalSize = mTotalSize + mItemSizeGroupList[i].mGroupSize; } }