protected void OnScroll(float oldPos, float newPos) { float delta = newPos - oldPos; int firstVisibleCellIndex = FirstVisibleCellIndex; int lastVisibleCellIndex = LastVisibleCellIndex; if (delta > 0) { int rowsCount = RowsCount; // wipe invisible rows while (!IsCellVisible(firstVisibleCellIndex, newPos) && VisibleCellsCount > 0) { RemoveVisibleCell(FirstVisibleCell); ++firstVisibleCellIndex; } if (VisibleCellsCount > 0) // not all rows were wiped: just append more visible cells at the end { for (int cellIndex = lastVisibleCellIndex + 1; cellIndex < rowsCount && IsCellVisible(cellIndex, newPos); ++cellIndex) { CTableViewCell cell = TableCellForRow(cellIndex); m_visibleCells.AddLastItem(cell); } } else { int rowIndex = FindFirstVisibleRow(newPos, lastVisibleCellIndex + 1, rowsCount - 1); while (rowIndex < rowsCount && IsCellVisible(rowIndex, newPos)) { CTableViewCell cell = TableCellForRow(rowIndex); m_visibleCells.AddLastItem(cell); ++rowIndex; } } } else if (delta < 0) { while (this.VisibleCellsCount > 0 && !IsCellVisible(lastVisibleCellIndex, newPos)) { RemoveVisibleCell(LastVisibleCell); --lastVisibleCellIndex; } if (VisibleCellsCount > 0) // not all rows were wiped: just prepend more visible cells at the beginning { for (int cellIndex = firstVisibleCellIndex - 1; cellIndex >= m_cellsEntries.HeadIndex && IsCellVisible(cellIndex, newPos); --cellIndex) { CTableViewCell cell = TableCellForRow(cellIndex); m_visibleCells.AddFirstItem(cell); } } else { int rowIndex = FindLastVisibleRow(newPos, m_cellsEntries.HeadIndex, firstVisibleCellIndex - 1); while (rowIndex >= m_cellsEntries.HeadIndex && IsCellVisible(rowIndex, newPos)) { CTableViewCell cell = TableCellForRow(rowIndex); m_visibleCells.AddFirstItem(cell); --rowIndex; } } } if (ScrollDelegate != null) { ScrollDelegate.OnTableScroll(this, oldPos); } }