mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
Escher: TableView reuses cells
Change-Id: Icdbfafba351057affc2bcb74f9c967971ffee667
This commit is contained in:
@@ -6,8 +6,8 @@
|
||||
class TableViewDataSource {
|
||||
public:
|
||||
virtual int numberOfCells() = 0;
|
||||
virtual View * cellAtIndex(int index) = 0;
|
||||
virtual void willDisplayCellAtIndex(int index) = 0;
|
||||
virtual View * reusableCell(int index) = 0;
|
||||
virtual void willDisplayCellForIndex(View * cell, int index) = 0;
|
||||
virtual KDCoordinate cellHeight() = 0;
|
||||
};
|
||||
|
||||
@@ -28,9 +28,10 @@ private:
|
||||
void layoutSubviews() override;
|
||||
protected:
|
||||
#if ESCHER_VIEW_LOGGING
|
||||
const char * className() const override;
|
||||
const char * className() const override;
|
||||
#endif
|
||||
private:
|
||||
int numberOfDisplayableCells() const;
|
||||
int cellScrollingOffset();
|
||||
TableViewDataSource * m_dataSource;
|
||||
};
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user