Пример #1
0
        private void AddRow(int row, bool atEnd)
        {
            WindowComponent newCell = m_dataSource.GetCellForRowInTableView(this, row);

            newCell.transform.SetParent(m_scrollRect.content, false);

            LayoutElement layoutElement = newCell.GetComponent <LayoutElement>();

            if (layoutElement == null)
            {
                layoutElement = newCell.gameObject.AddComponent <LayoutElement>();
            }
            layoutElement.preferredHeight = m_rowHeights[row];
            if (row > 0)
            {
                layoutElement.preferredHeight -= m_verticalLayoutGroup.spacing;
            }

            m_visibleCells[row] = newCell;
            if (atEnd)
            {
                newCell.transform.SetSiblingIndex(m_scrollRect.content.childCount - 2); //One before bottom padding
            }
            else
            {
                newCell.transform.SetSiblingIndex(1); //One after the top padding
            }
            this.onCellVisibilityChanged.Invoke(row, true);
        }
Пример #2
0
        /// <summary>
        /// Notify the table view that one of its rows changed size
        /// </summary>
        public void NotifyCellDimensionsChanged(int row)
        {
            float oldHeight = m_rowHeights[row];

            m_rowHeights[row]      = m_dataSource.GetHeightForRowInTableView(this, row);
            m_cleanCumulativeIndex = Mathf.Min(m_cleanCumulativeIndex, row - 1);
            if (m_visibleRowRange.Contains(row))
            {
                WindowComponent cell = GetCellAtRow(row);
                cell.GetComponent <LayoutElement>().preferredHeight = m_rowHeights[row];
                if (row > 0)
                {
                    cell.GetComponent <LayoutElement>().preferredHeight -= m_verticalLayoutGroup.spacing;
                }
            }
            float heightDelta = m_rowHeights[row] - oldHeight;

            m_scrollRect.content.sizeDelta = new Vector2(m_scrollRect.content.sizeDelta.x,
                                                         m_scrollRect.content.sizeDelta.y + heightDelta);
            m_requiresRefresh = true;
        }
        /// <summary>
        /// Notify the table view that one of its rows changed size
        /// </summary>
        public void NotifyCellDimensionsChanged(int row)
        {
            var oldHeight = this.rowHeights[row];

            this.rowHeights[row]      = this.dataSource.GetRowHeight(row);
            this.cleanCumulativeIndex = Mathf.Min(this.cleanCumulativeIndex, row - 1);
            if (this.visibleRowRange.Contains(row) == true)
            {
                WindowComponent cell = this.GetCellAtRow(row);
                cell.GetComponent <LayoutElement>().preferredHeight = this.rowHeights[row];
                if (row > 0)
                {
                    cell.GetComponent <LayoutElement>().preferredHeight -= this.GetRowSpacing();
                }
            }

            var heightDelta = this.rowHeights[row] - oldHeight;

            this.scrollRect.content.sizeDelta = new Vector2(this.scrollRect.content.sizeDelta.x, this.scrollRect.content.sizeDelta.y + heightDelta);
            this.requiresRefresh = true;
        }