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