public void UpdateList()
        {
            if (dataList == null)
            {
                return;
            }

            for (int i = 0; i < dataList.Count; i++)
            {
                ListItemData tempData = dataList[i];
                if (IsOverRange(tempData))       // 超过的回收
                {
                    SetPoolChildController(tempData.Controller);
                    tempData.Controller = null;
                }
                else
                {
                    if (tempData.Controller == null)
                    {
                        //Logger.Log("New {2}: \tx = {0}\ty = {1}\theight = {3}", tempData.Pos.x, tempData.Pos.y, i, tempData.Height);
                        tempData.Controller = GetPoolChildController();
                        ResetAnchor(tempData.Controller.Rect);
                        tempData.Controller.SetAnchoredPosition(tempData.Pos);
                        tempData.Controller.SetRectSize(tempData.Width, tempData.Height);
                        tempData.Controller.Name = i.ToString();

                        tempData.Controller.SetListData(tempData);
                    }
                }
            }
        }
        public ListItemData Clone()
        {
            ListItemData newData = new ListItemData();

            newData.Data       = this.Data;
            newData.Width      = this.Width;
            newData.Height     = this.Height;
            newData.Pos        = this.Pos;
            newData.Controller = null;
            return(newData);
        }
        public void AddListItem(ListItemData data, int index = -1)
        {
            if (index == -1)
            {
                index = Mathf.Max(0, dataList.Count);
            }

            if (index > 0)
            {
                ListItemData lastData = dataList[index - 1];
                data.Pos = lastData.Pos + (IsHorizontal ? Vector3.right * lastData.Width : Vector3.down * lastData.Height);
            }
            dataList.Insert(index, data);

            float oriSize    = IsHorizontal ? view.contentRectRrans.sizeDelta.x : view.contentRectRrans.sizeDelta.y;
            float totalSize  = IsHorizontal ? oriSize + data.Width : oriSize + data.Height;
            float cellLength = IsHorizontal ? view.contentRectRrans.sizeDelta.y : view.contentRectRrans.sizeDelta.x;

            totalSize = Mathf.Max(totalSize, IsHorizontal ?
                                  (int)Mathf.Abs(GetContentRect().x) : (int)Mathf.Abs(GetContentRect().y));

            view.contentRectRrans.sizeDelta = IsHorizontal ?
                                              new Vector2(totalSize, cellLength) : new Vector2(cellLength, totalSize);

            for (int i = index; i < dataList.Count; i++)
            {
                ListItemData tempData = dataList[i];
                if (i > index)
                {
                    tempData.Pos += IsHorizontal ? Vector3.right * data.Width : Vector3.down * data.Height;
                }

                if (IsOverRange(tempData))       // 超过的回收
                {
                    SetPoolChildController(tempData.Controller);
                    tempData.Controller = null;
                }
                else
                {
                    if (tempData.Controller == null)
                    {
                        Logger.Log("New {2}: \tx = {0}\ty = {1}\theight = {3}", tempData.Pos.x, tempData.Pos.y, i, tempData.Height);
                        tempData.Controller = GetPoolChildController();
                    }
                    ResetAnchor(tempData.Controller.Rect);
                    tempData.Controller.SetAnchoredPosition(tempData.Pos);
                    tempData.Controller.SetRectSize(tempData.Width, tempData.Height);
                    tempData.Controller.Name = i.ToString();

                    tempData.Controller.SetListData(tempData);
                }
            }
        }
        public void UpdateItem(ListItemData data, int index)
        {
            if (index < 0 || index >= dataList.Count)
            {
                Logger.Error("UpdateItem - index out of range");
                return;
            }

            ListItemData oriData    = dataList[index];
            float        oriSize    = IsHorizontal ? view.contentRectRrans.sizeDelta.x : view.contentRectRrans.sizeDelta.y;
            float        deltaSize  = IsHorizontal ? -oriData.Width + data.Width : -oriData.Height + data.Height;
            float        totalSize  = oriSize + deltaSize;
            float        cellLength = IsHorizontal ? view.contentRectRrans.sizeDelta.y : view.contentRectRrans.sizeDelta.x;

            totalSize = Mathf.Max(totalSize, IsHorizontal ?
                                  (int)Mathf.Abs(GetContentRect().x) : (int)Mathf.Abs(GetContentRect().y));
            view.contentRectRrans.sizeDelta = IsHorizontal ?
                                              new Vector2(totalSize, cellLength) : new Vector2(cellLength, totalSize);

            dataList[index].Width  = data.Width;
            dataList[index].Height = data.Height;

            for (int i = index; i < dataList.Count; i++)
            {
                ListItemData tempData = dataList[i];
                if (i > index)
                {
                    tempData.Pos += IsHorizontal ? Vector3.right * deltaSize : Vector3.down * deltaSize;
                }

                if (IsOverRange(tempData))       // 超过的回收
                {
                    SetPoolChildController(tempData.Controller);
                    tempData.Controller = null;
                }
                else
                {
                    if (tempData.Controller == null)
                    {
                        Logger.Log("New {2}: \tx = {0}\ty = {1}\theight = {3}", tempData.Pos.x, tempData.Pos.y, i, tempData.Height);
                        tempData.Controller = GetPoolChildController();
                    }
                    ResetAnchor(tempData.Controller.Rect);
                    tempData.Controller.SetAnchoredPosition(tempData.Pos);
                    tempData.Controller.SetRectSize(tempData.Width, tempData.Height);
                    tempData.Controller.Name = i.ToString();

                    tempData.Controller.SetListData(tempData);
                }
            }
        }
 private bool IsOverRange(ListItemData data)
 {
     if (IsHorizontal)
     {
         float contentPos    = view.contentRectRrans.anchoredPosition.x;
         float itemPosMin    = data.Pos.x + contentPos;
         float itemPosMax    = itemPosMin + data.Width;
         float contentMaxPos = GetContentRect().xMax;
         return(itemPosMin > contentMaxPos || itemPosMax < 0f);
     }
     else
     {
         float contentPos    = view.contentRectRrans.anchoredPosition.y;
         float itemPosMax    = data.Pos.y + contentPos;
         float itemPosMin    = itemPosMax - data.Height;
         float contentMinPos = GetContentRect().yMin;
         return(itemPosMin > 0f || itemPosMax < contentMinPos);
     }
 }