mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-19 05:40:38 +01:00
Escher: Add TableView::cellAtIndex
Change-Id: I7b78b7fa05d4c1390dd7c58ef098b3708c972119
This commit is contained in:
@@ -15,9 +15,10 @@ public:
|
||||
class TableView : public ScrollView {
|
||||
public:
|
||||
TableView(TableViewDataSource * dataSource);
|
||||
void layoutSubviews() override;
|
||||
|
||||
void scrollToRow(int index);
|
||||
void layoutSubviews() override;
|
||||
View * cellAtIndex(int index);
|
||||
protected:
|
||||
#if ESCHER_VIEW_LOGGING
|
||||
const char * className() const override;
|
||||
@@ -31,12 +32,15 @@ private:
|
||||
View * subview(int index) override;
|
||||
void storeSubviewAtIndex(View * view, int index) override;
|
||||
void layoutSubviews() override;
|
||||
|
||||
View * cellAtIndex(int index);
|
||||
protected:
|
||||
#if ESCHER_VIEW_LOGGING
|
||||
const char * className() const override;
|
||||
#endif
|
||||
private:
|
||||
int numberOfDisplayableCells() const;
|
||||
int cellScrollingOffset() const;
|
||||
TableViewDataSource * m_dataSource;
|
||||
};
|
||||
|
||||
|
||||
@@ -30,6 +30,10 @@ void TableView::scrollToRow(int index) {
|
||||
setContentOffset(contentOffset);
|
||||
}
|
||||
|
||||
View * TableView::cellAtIndex(int index) {
|
||||
return m_contentView.cellAtIndex(index);
|
||||
}
|
||||
|
||||
#if ESCHER_VIEW_LOGGING
|
||||
const char * TableView::className() const {
|
||||
return "TableView";
|
||||
@@ -62,10 +66,7 @@ void TableView::ContentView::storeSubviewAtIndex(View * view, int index) {
|
||||
}
|
||||
|
||||
void TableView::ContentView::layoutSubviews() {
|
||||
/* Here, we want to translate the offset at which our superview is displaying
|
||||
* us into an integer offset we can use to ask cells to our data source. */
|
||||
KDCoordinate pixelScrollingOffset = m_frame.y;
|
||||
int cellOffset = pixelScrollingOffset / m_dataSource->cellHeight();
|
||||
int cellOffset = cellScrollingOffset();
|
||||
|
||||
for (int i=0; i<numberOfSubviews(); i++) {
|
||||
View * cell = subview(i);
|
||||
@@ -83,6 +84,10 @@ void TableView::ContentView::layoutSubviews() {
|
||||
}
|
||||
}
|
||||
|
||||
View * TableView::ContentView::cellAtIndex(int index) {
|
||||
return m_dataSource->reusableCell(index - cellScrollingOffset());
|
||||
}
|
||||
|
||||
#if ESCHER_VIEW_LOGGING
|
||||
const char * TableView::ContentView::className() const {
|
||||
return "TableView::ContentView";
|
||||
@@ -94,3 +99,10 @@ int TableView::ContentView::numberOfDisplayableCells() const {
|
||||
assert(result <= m_dataSource->reusableCellCount());
|
||||
return result;
|
||||
}
|
||||
|
||||
int TableView::ContentView::cellScrollingOffset() const {
|
||||
/* Here, we want to translate the offset at which our superview is displaying
|
||||
* us into an integer offset we can use to ask cells to our data source. */
|
||||
KDCoordinate pixelScrollingOffset = m_frame.y;
|
||||
return pixelScrollingOffset / m_dataSource->cellHeight();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user