Example #1
0
    public void BeginEditWithCell(PUSimpleTableCell cell)
    {
        isEdit = true;
        cell.isEdit = true;

        cell.puGameObject.rectTransform.SetParent (contentObject.transform, false);
    }
    public void BeginEditWithCell(PUSimpleTableCell cell)
    {
        isEdit      = true;
        cell.isEdit = true;

        cell.puGameObject.rectTransform.SetParent(contentObject.transform, false);
    }
    public PUSimpleTableCell LoadCellForData(object cellData, PUSimpleTableCell reusedCell)
    {
        PUSimpleTableCell cell = reusedCell;

        if (reusedCell == null)
        {
            string className = cellData.GetType().Name + "TableCell";
            Type   cellType  = Type.GetType(className, true);

            cell = (Activator.CreateInstance(cellType)) as PUSimpleTableCell;
            cell.LoadIntoPUGameObject(this, cellData);
        }
        else
        {
            cell.cellData            = cellData;
            cell.puGameObject.parent = this;
            cell.puGameObject.rectTransform.SetParent(this.contentObject.transform, false);

            cell.UpdateContents();
        }

        if (cell.IsHeader())
        {
            cell.puGameObject.rectTransform.sizeDelta = new Vector2(cell.puGameObject.rectTransform.sizeDelta.x, headerSize.Value.y);
        }
        else
        {
            cell.puGameObject.rectTransform.sizeDelta = new Vector2(cell.puGameObject.rectTransform.sizeDelta.x, cellSize.Value.y);
        }
        cell.puGameObject.rectTransform.anchorMin = new Vector2(0, 1);
        cell.puGameObject.rectTransform.anchorMax = new Vector2(0, 1);
        cell.puGameObject.rectTransform.pivot     = new Vector2(0, 1);

        return(cell);
    }
 public void ClearTable()
 {
     for (int i = activeTableCells.Count - 1; i >= 0; i--)
     {
         PUSimpleTableCell cell = activeTableCells [i];
         EnqueueTableCell(cell);
     }
 }
    public void EnqueueTableCell(PUSimpleTableCell cell)
    {
        string dataKey = cell.cellData.GetType ().Name;
        if (pooledTableCells.ContainsKey (dataKey) == false) {
            pooledTableCells [dataKey] = new List<PUSimpleTableCell> ();
        }
        pooledTableCells [dataKey].Add (cell);
        cell.puGameObject.gameObject.SetActive (false);

        activeTableCells.Remove (cell);
    }
    public void EnqueueTableCell(PUSimpleTableCell cell)
    {
        string dataKey = cell.cellData.GetType().Name;

        if (pooledTableCells.ContainsKey(dataKey) == false)
        {
            pooledTableCells [dataKey] = new List <PUSimpleTableCell> ();
        }
        pooledTableCells [dataKey].Add(cell);
        cell.puGameObject.gameObject.SetActive(false);

        activeTableCells.Remove(cell);
    }
    public int ObjectIndexOfCell(PUSimpleTableCell cell)
    {
        int idx = 0;

        foreach (List <object> subtableObjects in allSegmentedObjects)
        {
            foreach (object item in subtableObjects)
            {
                if (cell.cellData == item)
                {
                    return(idx);
                }
                idx++;
            }
        }
        return(-1);
    }
Example #8
0
    public void EmptyTable()
    {
        // TODO: cancel any background loads
        //if (tableUpdateScript != null)
        //	tableUpdateScript.StopReloadTableCells();

        // When the table size changes, we need to not reuse table cells...
        for (int i = activeTableCells.Count - 1; i >= 0; i--)
        {
            PUSimpleTableCell cell = activeTableCells [i];
            cell.unload();
            activeTableCells.RemoveAt(i);
        }

        foreach (string key in pooledTableCells.Keys)
        {
            foreach (PUSimpleTableCell cell in pooledTableCells[key])
            {
                cell.unload();
            }
        }
        pooledTableCells.Clear();
    }
    public PUSimpleTableCell DequeueTableCell(object cellData)
    {
        string dataKey = cellData.GetType().Name;

        if (pooledTableCells.ContainsKey(dataKey) == false)
        {
            pooledTableCells [dataKey] = new List <PUSimpleTableCell> ();
        }

        PUSimpleTableCell cell = null;

        if (pooledTableCells [dataKey].Count > 0)
        {
            cell = pooledTableCells[dataKey][0];
            pooledTableCells [dataKey].RemoveAt(0);
        }

        cell = LoadCellForData(cellData, cell);
        cell.puGameObject.gameObject.SetActive(true);

        activeTableCells.Add(cell);

        return(cell);
    }
    public IEnumerator ReloadSubtable(List <object> subtableObjects, Dictionary <object, PUSimpleTableCell> visibleCells)
    {
        RectTransform contentRectTransform = contentObject.transform as RectTransform;

        currentScrollY = (int)contentRectTransform.anchoredPosition.y;

        // 1) Run through allObjects; instantiate a cell object based on said object class
        float currentLayoutY = 0;
        float nextY          = 0;
        float x       = 0;
        float offsetX = 0;


        float cellWidth = MathParser.step(contentRectTransform.sizeDelta.x, cellSize.Value.x);

        if (expandCellWidth == false)
        {
            cellWidth = cellSize.Value.x;
        }

        float cellHeight = cellSize.Value.y;

        int cellsPerRow = Mathf.FloorToInt(rectTransform.rect.width / cellWidth);

        if (cellsPerRow < 1)
        {
            cellsPerRow = 1;
        }

        currentLayoutY = -contentRectTransform.sizeDelta.y;


        // Handle the header
        int hasHeader = 0;

        if (headerSize.Value.y > 0 && subtableObjects.Count > 0)
        {
            hasHeader = 1;
            //currentLayoutY -= headerSize.Value.y;
        }

        // Can I skip a known quantity in the beginning and end?
        int totalVisibleCells = (Mathf.CeilToInt((rectTransform.rect.height + cellHeight) / cellHeight) * cellsPerRow) + cellsPerRow;
        int firstVisibleCell  = Mathf.FloorToInt((Mathf.Abs(contentRectTransform.anchoredPosition.y) + currentLayoutY - cellHeight) / cellHeight) * cellsPerRow;

        if (firstVisibleCell < 0)
        {
            totalVisibleCells += firstVisibleCell;
            firstVisibleCell   = 0;
        }


        if (hasHeader == 1)
        {
            object            myCellData = subtableObjects [0];
            PUSimpleTableCell cell       = null;
            if (PUSimpleTableCell.TestForVisibility(currentLayoutY, headerSize.Value.y, rectTransform, contentRectTransform))
            {
                if (visibleCells.ContainsKey(myCellData))
                {
                    cell = visibleCells [myCellData];
                }
                else
                {
                    cell = DequeueTableCell(myCellData);
                }
                cell.puGameObject.rectTransform.anchoredPosition = new Vector2(x, currentLayoutY);
            }

            currentLayoutY -= headerSize.Value.y;
        }



        // Update the content size
        float subtableWidth  = contentRectTransform.sizeDelta.x;
        float subtableHeight = cellHeight * Mathf.Ceil((subtableObjects.Count - hasHeader) / (float)cellsPerRow);

        contentRectTransform.sizeDelta = new Vector2(subtableWidth, contentRectTransform.sizeDelta.y + subtableHeight + headerSize.Value.y);

        currentLayoutY += -Mathf.FloorToInt(firstVisibleCell / cellsPerRow) * cellHeight;
        nextY           = currentLayoutY - cellHeight;


        if (hasHeader == 1)
        {
            firstVisibleCell += 1;
        }

        for (int i = firstVisibleCell; i < firstVisibleCell + totalVisibleCells; i++)
        {
            if (i < subtableObjects.Count)
            {
                object myCellData = subtableObjects [i];

                PUSimpleTableCell cell = null;

                // Can I fit on the current line?
                if (x + cellWidth > (contentRectTransform.rect.width + 1))
                {
                    x = 0;
                    currentLayoutY = nextY;
                }

                totalCellsChecked++;
                if (PUSimpleTableCell.TestForVisibility(currentLayoutY, cellHeight, rectTransform, contentRectTransform))
                {
                    if (visibleCells.ContainsKey(myCellData))
                    {
                        cell = visibleCells [myCellData];
                    }
                    else
                    {
                        cell = DequeueTableCell(myCellData);
                    }

                    if (cell.isEdit == false)
                    {
                        cell.puGameObject.rectTransform.anchoredPosition = new Vector2(x + offsetX, currentLayoutY);
                    }
                }

                x    += cellWidth;
                nextY = currentLayoutY - cellHeight;

                yield return(null);
            }
        }
    }
    public IEnumerator ReloadTableAsync()
    {
        isReloadingTableAsync = true;

        yield return(null);

        if (rectTransform == null)
        {
            yield break;
        }

        RectTransform contentRectTransform = contentObject.transform as RectTransform;

        contentRectTransform.sizeDelta = new Vector2(rectTransform.rect.width, 0 + _ContentOffset.y);
        //if (TableHeader != null) {
        //contentRectTransform.sizeDelta += new Vector2(0, TableHeader.rectTransform.rect.height);
        //}
        totalCellsChecked = 0;

        // Unload any cells which are not on the screen currently; store the object data for cells which are
        // still visible
        Dictionary <object, PUSimpleTableCell> visibleCells = new Dictionary <object, PUSimpleTableCell>();

        for (int i = activeTableCells.Count - 1; i >= 0; i--)
        {
            PUSimpleTableCell cell = activeTableCells [i];
            if (cell.TestForVisibility() == false)
            {
                EnqueueTableCell(cell);
            }
            else
            {
                visibleCells [cell.cellData] = cell;
            }
        }


        if (TableHeader != null)
        {
            TableHeader.rectTransform.SetParent(contentObject.transform, false);
            TableHeader.rectTransform.anchoredPosition = new Vector2(0, 0);

            contentRectTransform.sizeDelta += new Vector2(0, TableHeader.rectTransform.rect.height);
        }

        if (allSegmentedObjects != null)
        {
            foreach (List <object> subtableObjects in allSegmentedObjects)
            {
                IEnumerator e = ReloadSubtable(subtableObjects, visibleCells);
                while (e.MoveNext())
                {
                    yield return(e.Current);
                }
            }
        }


        if (contentRectTransform.sizeDelta.y == 0)
        {
            contentRectTransform.sizeDelta = new Vector2(rectTransform.rect.width, rectTransform.rect.height + _ContentOffset.y);
        }
        //Debug.Log (totalCellsChecked + " **************");

        if (TableFooter != null)
        {
            TableFooter.rectTransform.SetParent(contentObject.transform, false);
            TableFooter.rectTransform.anchoredPosition = new Vector2(0, -contentRectTransform.sizeDelta.y);

            contentRectTransform.sizeDelta += new Vector2(0, TableFooter.rectTransform.rect.height);
        }

        isReloadingTableAsync = false;
    }
    public PUSimpleTableCell LoadCellForData(object cellData, PUSimpleTableCell reusedCell)
    {
        PUSimpleTableCell cell = reusedCell;
        if (reusedCell == null) {
            string className = cellData.GetType ().Name + "TableCell";
            Type cellType = Type.GetType (className, true);

            cell = (Activator.CreateInstance (cellType)) as PUSimpleTableCell;
            cell.LoadIntoPUGameObject (this, cellData);
        } else {
            cell.cellData = cellData;
            cell.puGameObject.parent = this;
            cell.puGameObject.rectTransform.SetParent (this.contentObject.transform, false);

            cell.UpdateContents ();
        }

        cell.puGameObject.rectTransform.anchorMin = new Vector2 (0, 1);
        cell.puGameObject.rectTransform.anchorMax = new Vector2 (0, 1);
        cell.puGameObject.rectTransform.pivot = new Vector2 (0, 1);

        return cell;
    }
Example #13
0
 public int ObjectIndexOfCell(PUSimpleTableCell cell)
 {
     int idx = 0;
     foreach (List<object> subtableObjects in allSegmentedObjects) {
         foreach(object item in subtableObjects){
             if(cell.cellData == item){
                 return idx;
             }
             idx++;
         }
     }
     return -1;
 }
Example #14
0
    public void ReloadTable()
    {
        if (rectTransform == null)
        {
            return;
        }

        RectTransform contentRectTransform = contentObject.transform as RectTransform;

        contentRectTransform.sizeDelta = new Vector2(rectTransform.rect.width, 0 + _ContentOffset.y);
        //if (TableHeader != null) {
        //contentRectTransform.sizeDelta += new Vector2(0, TableHeader.rectTransform.rect.height);
        //}
        totalCellsChecked = 0;

        // Unload any cells which are not on the screen currently; store the object data for cells which are
        // still visible
        Dictionary <object, PUSimpleTableCell> visibleCells = new Dictionary <object, PUSimpleTableCell>();

        for (int i = activeTableCells.Count - 1; i >= 0; i--)
        {
            PUSimpleTableCell cell = activeTableCells [i];
            if (cell.TestForVisibility() == false)
            {
                EnqueueTableCell(cell);
            }
            else
            {
                visibleCells [cell.cellData] = cell;
            }
        }


        if (TableHeader != null && TableHeader.rectTransform != null && contentObject != null)
        {
            TableHeader.rectTransform.SetParent(contentObject.transform, false);
            TableHeader.rectTransform.anchoredPosition = new Vector2(0, 0);

            contentRectTransform.sizeDelta += new Vector2(0, TableHeader.rectTransform.rect.height);
        }

        if (allSegmentedObjects != null)
        {
            foreach (List <object> subtableObjects in allSegmentedObjects)
            {
                ReloadSubtable(subtableObjects, visibleCells);
            }
        }

        foreach (PUSimpleTableCell leftOverCell in visibleCells.Values)
        {
            EnqueueTableCell(leftOverCell);
        }

        if (contentRectTransform.sizeDelta.y == 0)
        {
            contentRectTransform.sizeDelta = new Vector2(rectTransform.rect.width, rectTransform.rect.height + _ContentOffset.y);
        }
        //Debug.Log (totalCellsChecked + " **************");

        if (TableFooter != null)
        {
            TableFooter.rectTransform.SetParent(contentObject.transform, false);
            TableFooter.rectTransform.anchoredPosition = new Vector2(0, -contentRectTransform.sizeDelta.y);

            contentRectTransform.sizeDelta += new Vector2(0, TableFooter.rectTransform.rect.height);
        }
    }