Escher: TableView reuses cells

Change-Id: Icdbfafba351057affc2bcb74f9c967971ffee667
This commit is contained in:
Romain Goyet
2016-06-14 10:52:03 +02:00
parent 2586b8d2b4
commit 63ed8207ce
2 changed files with 12 additions and 6 deletions

View File

@@ -30,13 +30,14 @@ TableView::ContentView::ContentView(TableViewDataSource * dataSource) :
}
int TableView::ContentView::numberOfSubviews() const {
int numberOfDisplayableCells = m_frame.height / m_dataSource->cellHeight();
return MIN(m_dataSource->numberOfCells(), numberOfDisplayableCells);
return MIN(m_dataSource->numberOfCells(), numberOfDisplayableCells());
}
View * TableView::ContentView::subview(int index) {
int offset = cellScrollingOffset();
return m_dataSource->cellAtIndex(offset+index);
View * cell = m_dataSource->reusableCell(index);
m_dataSource->willDisplayCellForIndex(cell, offset+index);
return cell;
}
void TableView::ContentView::storeSubviewAtIndex(View * view, int index) {
@@ -59,6 +60,10 @@ void TableView::ContentView::layoutSubviews() {
}
}
int TableView::ContentView::numberOfDisplayableCells() const {
return m_frame.height / m_dataSource->cellHeight();
}
// Index of the topmost cell
int TableView::ContentView::cellScrollingOffset() {
/* Here, we want to translate the offset at which our superview is displaying