mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-19 05:40:38 +01:00
Escher: Some more cleanup
Change-Id: Ia3c77717f082f82bbf97393614f21996ab964cdb
This commit is contained in:
@@ -5,11 +5,10 @@
|
||||
|
||||
class ChildlessView : public View {
|
||||
using View::View;
|
||||
protected:
|
||||
int numberOfSubviews() const override;
|
||||
void layoutSubviews() override;
|
||||
private:
|
||||
int numberOfSubviews() const override;
|
||||
View * subviewAtIndex(int index) override;
|
||||
void layoutSubviews() override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -8,18 +8,18 @@ class ScrollView : public View {
|
||||
public:
|
||||
ScrollView(View * contentView);
|
||||
|
||||
int numberOfSubviews() const override;
|
||||
void layoutSubviews() override;
|
||||
|
||||
void setContentOffset(KDPoint offset);
|
||||
protected:
|
||||
KDCoordinate maxContentWidth();
|
||||
void layoutSubviews() override;
|
||||
#if ESCHER_VIEW_LOGGING
|
||||
virtual const char * className() const override;
|
||||
virtual void logAttributes(std::ostream &os) const override;
|
||||
#endif
|
||||
private:
|
||||
int numberOfSubviews() const override;
|
||||
View * subviewAtIndex(int index) override;
|
||||
|
||||
KDPoint m_offset;
|
||||
View * m_contentView;
|
||||
ScrollViewIndicator m_verticalScrollIndicator;
|
||||
|
||||
@@ -10,10 +10,7 @@ class TabView : public View {
|
||||
public:
|
||||
TabView();
|
||||
|
||||
// View
|
||||
void drawRect(KDRect rect) const override;
|
||||
int numberOfSubviews() const override;
|
||||
void layoutSubviews() override;
|
||||
|
||||
void addTabNamed(const char * name);
|
||||
//TODO: void removeLastTab();
|
||||
@@ -24,7 +21,10 @@ protected:
|
||||
void logAttributes(std::ostream &os) const override;
|
||||
#endif
|
||||
private:
|
||||
int numberOfSubviews() const override;
|
||||
View * subviewAtIndex(int index) override;
|
||||
void layoutSubviews() override;
|
||||
|
||||
static constexpr uint8_t k_maxNumberOfTabs = 4;
|
||||
TabViewCell m_cells[k_maxNumberOfTabs];
|
||||
uint8_t m_numberOfTabs;
|
||||
|
||||
@@ -16,9 +16,6 @@ class TableView : public ScrollView {
|
||||
public:
|
||||
TableView(TableViewDataSource * dataSource);
|
||||
|
||||
// View
|
||||
void layoutSubviews() override;
|
||||
|
||||
void scrollToRow(int index);
|
||||
View * cellAtIndex(int index);
|
||||
protected:
|
||||
@@ -30,9 +27,6 @@ private:
|
||||
public:
|
||||
ContentView(TableView * tableView, TableViewDataSource * dataSource);
|
||||
|
||||
int numberOfSubviews() const override;
|
||||
void layoutSubviews() override;
|
||||
|
||||
KDCoordinate height() const;
|
||||
void scrollToRow(int index) const;
|
||||
View * cellAtIndex(int index);
|
||||
@@ -41,7 +35,10 @@ private:
|
||||
const char * className() const override;
|
||||
#endif
|
||||
private:
|
||||
int numberOfSubviews() const override;
|
||||
View * subviewAtIndex(int index) override;
|
||||
void layoutSubviews() override;
|
||||
|
||||
int numberOfDisplayableCells() const;
|
||||
int cellScrollingOffset() const;
|
||||
bool cellAtIndexIsBeforeFullyVisibleRange(int index) const;
|
||||
@@ -50,6 +47,8 @@ private:
|
||||
TableViewDataSource * m_dataSource;
|
||||
};
|
||||
|
||||
void layoutSubviews() override;
|
||||
|
||||
ContentView m_contentView;
|
||||
};
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ TabView::TabView() :
|
||||
{
|
||||
}
|
||||
|
||||
/* View */
|
||||
void TabView::drawRect(KDRect rect) const {
|
||||
KDFillRect(rect, KDColorRGB(0xb5, 0x1d, 0xab));
|
||||
}
|
||||
|
||||
@@ -17,6 +17,16 @@ void TableView::scrollToRow(int index) {
|
||||
m_contentView.scrollToRow(index);
|
||||
}
|
||||
|
||||
View * TableView::cellAtIndex(int index) {
|
||||
return m_contentView.cellAtIndex(index);
|
||||
}
|
||||
|
||||
#if ESCHER_VIEW_LOGGING
|
||||
const char * TableView::className() const {
|
||||
return "TableView";
|
||||
}
|
||||
#endif
|
||||
|
||||
void TableView::layoutSubviews() {
|
||||
// We only have to layout our contentView.
|
||||
// We will size it here, and ScrollView::layoutSubviews will position it.
|
||||
@@ -30,16 +40,6 @@ void TableView::layoutSubviews() {
|
||||
ScrollView::layoutSubviews();
|
||||
}
|
||||
|
||||
View * TableView::cellAtIndex(int index) {
|
||||
return m_contentView.cellAtIndex(index);
|
||||
}
|
||||
|
||||
#if ESCHER_VIEW_LOGGING
|
||||
const char * TableView::className() const {
|
||||
return "TableView";
|
||||
}
|
||||
#endif
|
||||
|
||||
/* TableView::ContentView */
|
||||
|
||||
TableView::ContentView::ContentView(TableView * tableView, TableViewDataSource * dataSource) :
|
||||
@@ -49,6 +49,40 @@ TableView::ContentView::ContentView(TableView * tableView, TableViewDataSource *
|
||||
{
|
||||
}
|
||||
|
||||
KDCoordinate TableView::ContentView::height() const {
|
||||
return m_dataSource->numberOfCells() * m_dataSource->cellHeight();
|
||||
}
|
||||
|
||||
void TableView::ContentView::scrollToRow(int index) const {
|
||||
if (cellAtIndexIsBeforeFullyVisibleRange(index)) {
|
||||
// Let's scroll the tableView to put that cell on the top
|
||||
KDPoint contentOffset;
|
||||
contentOffset.x = 0;
|
||||
contentOffset.y = index*m_dataSource->cellHeight();
|
||||
m_tableView->setContentOffset(contentOffset);
|
||||
return;
|
||||
}
|
||||
if (cellAtIndexIsAfterFullyVisibleRange(index)) {
|
||||
// Let's scroll the tableView to put that cell on the bottom
|
||||
KDPoint contentOffset;
|
||||
contentOffset.x = 0;
|
||||
contentOffset.y = (index+1)*m_dataSource->cellHeight() - m_tableView->bounds().height;
|
||||
m_tableView->setContentOffset(contentOffset);
|
||||
return;
|
||||
}
|
||||
// Nothing to do if the cell is already visible!
|
||||
}
|
||||
|
||||
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";
|
||||
}
|
||||
#endif
|
||||
|
||||
int TableView::ContentView::numberOfSubviews() const {
|
||||
return MIN(m_dataSource->numberOfCells(), numberOfDisplayableCells());
|
||||
}
|
||||
@@ -78,40 +112,6 @@ void TableView::ContentView::layoutSubviews() {
|
||||
}
|
||||
}
|
||||
|
||||
View * TableView::ContentView::cellAtIndex(int index) {
|
||||
return m_dataSource->reusableCell(index - cellScrollingOffset());
|
||||
}
|
||||
|
||||
KDCoordinate TableView::ContentView::height() const {
|
||||
return m_dataSource->numberOfCells() * m_dataSource->cellHeight();
|
||||
}
|
||||
|
||||
void TableView::ContentView::scrollToRow(int index) const {
|
||||
if (cellAtIndexIsBeforeFullyVisibleRange(index)) {
|
||||
// Let's scroll the tableView to put that cell on the top
|
||||
KDPoint contentOffset;
|
||||
contentOffset.x = 0;
|
||||
contentOffset.y = index*m_dataSource->cellHeight();
|
||||
m_tableView->setContentOffset(contentOffset);
|
||||
return;
|
||||
}
|
||||
if (cellAtIndexIsAfterFullyVisibleRange(index)) {
|
||||
// Let's scroll the tableView to put that cell on the bottom
|
||||
KDPoint contentOffset;
|
||||
contentOffset.x = 0;
|
||||
contentOffset.y = (index+1)*m_dataSource->cellHeight() - m_tableView->bounds().height;
|
||||
m_tableView->setContentOffset(contentOffset);
|
||||
return;
|
||||
}
|
||||
// Nothing to do if the cell is already visible!
|
||||
}
|
||||
|
||||
#if ESCHER_VIEW_LOGGING
|
||||
const char * TableView::ContentView::className() const {
|
||||
return "TableView::ContentView";
|
||||
}
|
||||
#endif
|
||||
|
||||
int TableView::ContentView::numberOfDisplayableCells() const {
|
||||
int result = m_tableView->bounds().height / m_dataSource->cellHeight() + 1;
|
||||
assert(result <= m_dataSource->reusableCellCount());
|
||||
|
||||
Reference in New Issue
Block a user