Ejemplo n.º 1
0
        //RefreshItem
        private void setUpdateRectItem(int scrollPerLineIndex)
        {
            if (scrollPerLineIndex < 0)
            {
                return;
            }
            int startDataIndex = 0;
            int endDataIndex   = 0;

            curScrollPerLineIndex = scrollPerLineIndex;
            if (alignment == Alignment.eHorizontal)
            {
                startDataIndex = curScrollPerLineIndex * CountOfRow;
                endDataIndex   = (curScrollPerLineIndex + ViewCount) * CountOfRow;
            }
            else
            {
                startDataIndex = curScrollPerLineIndex * CountOfCol;
                endDataIndex   = (curScrollPerLineIndex + ViewCount) * CountOfCol;
            }

            //move item when unused
            for (int i = listItem.Count - 1; i >= 0; i--)
            {
                UILoopItem item  = listItem[i];
                int        index = item.Index;
                if (index < startDataIndex || index >= endDataIndex)
                {
                    item.Index = 0;
                    listItem.Remove(item);
                    unUseItem.Enqueue(item);
                }
                else
                {
                    item.UpdateItem(_datas, item.Index);
                }
            }

            for (int dataIndex = startDataIndex; dataIndex < endDataIndex; dataIndex++)
            {
                if (dataIndex >= dataCount)
                {
                    continue;
                }
                if (isExistDataByDataIndex(dataIndex))
                {
                    continue;
                }
                createItem(dataIndex);
            }
        }
Ejemplo n.º 2
0
        //add item
        public void AddItem(int dataIndex)
        {
            if (dataIndex < 0 || dataIndex > dataCount)
            {
                return;
            }
            bool isNeedAdd = false;

            for (int i = listItem.Count - 1; i >= 0; i--)
            {
                UILoopItem item = listItem[i];
                if (item.Index >= (dataCount - 1))
                {
                    isNeedAdd = true;
                    break;
                }
            }
            setDataCount(dataCount + 1);

            if (isNeedAdd)
            {
                for (int i = 0; i < listItem.Count; i++)
                {
                    UILoopItem item     = listItem[i];
                    int        oldIndex = item.Index;
                    if (oldIndex >= dataIndex)
                    {
                        item.Index = oldIndex + 1;
                        item.UpdateItem(_datas, item.Index);
                    }
                    item = null;
                }
                setUpdateRectItem(getCurScrollPerLineIndex());
            }
            else
            {
                for (int i = 0; i < listItem.Count; i++)
                {
                    UILoopItem item     = listItem[i];
                    int        oldIndex = item.Index;
                    if (oldIndex >= dataIndex)
                    {
                        item.Index = oldIndex;
                        item.UpdateItem(_datas, item.Index);
                    }
                    item = null;
                }
            }
        }