From ca27adc25f1f58ad934ff36b7ac038b5959098fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Thu, 29 Sep 2016 14:33:12 +0200 Subject: [PATCH 1/5] [escher] rename the table view class in "simple table view" Change-Id: Ie94f445ae2f830254373d7e7d0917884d88a66fb --- escher/Makefile | 2 +- escher/include/escher.h | 2 +- escher/include/escher/list_view.h | 6 +- .../{table_view.h => simple_table_view.h} | 16 ++--- escher/src/list_view.cpp | 2 +- .../{table_view.cpp => simple_table_view.cpp} | 60 +++++++++---------- 6 files changed, 44 insertions(+), 44 deletions(-) rename escher/include/escher/{table_view.h => simple_table_view.h} (80%) rename escher/src/{table_view.cpp => simple_table_view.cpp} (71%) diff --git a/escher/Makefile b/escher/Makefile index 12224b3d3..57a76c332 100644 --- a/escher/Makefile +++ b/escher/Makefile @@ -12,6 +12,7 @@ objs += $(addprefix escher/src/,\ responder.o\ scroll_view.o\ scroll_view_indicator.o\ + simple_table_view.o\ solid_color_view.o\ stack_view.o\ stack_view_controller.o\ @@ -20,7 +21,6 @@ objs += $(addprefix escher/src/,\ tab_view.o\ tab_view_cell.o\ tab_view_controller.o\ - table_view.o\ table_view_cell.o\ text_field.o\ text_view.o\ diff --git a/escher/include/escher.h b/escher/include/escher.h index 42ea1465d..0d19e8a96 100644 --- a/escher/include/escher.h +++ b/escher/include/escher.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -19,7 +20,6 @@ #include #include #include -#include #include #include #include diff --git a/escher/include/escher/list_view.h b/escher/include/escher/list_view.h index f908d5514..beba4b84f 100644 --- a/escher/include/escher/list_view.h +++ b/escher/include/escher/list_view.h @@ -1,9 +1,9 @@ #ifndef ESCHER_LIST_VIEW_H #define ESCHER_LIST_VIEW_H -#include +#include -class ListViewDataSource : public TableViewDataSource{ +class ListViewDataSource : public SimpleTableViewDataSource{ public: int numberOfColumns() override; KDCoordinate cellWidth() override; @@ -11,7 +11,7 @@ public: virtual void willDisplayCellForIndex(View * cell, int index); }; -class ListView : public TableView { +class ListView : public SimpleTableView { public: ListView(ListViewDataSource * dataSource, KDCoordinate topMargin = 0, KDCoordinate rightMargin = 0, KDCoordinate bottomMargin = 0, KDCoordinate leftMargin = 0); diff --git a/escher/include/escher/table_view.h b/escher/include/escher/simple_table_view.h similarity index 80% rename from escher/include/escher/table_view.h rename to escher/include/escher/simple_table_view.h index beaae14c2..aac7bf2a2 100644 --- a/escher/include/escher/table_view.h +++ b/escher/include/escher/simple_table_view.h @@ -1,9 +1,9 @@ -#ifndef ESCHER_TABLE_VIEW_H -#define ESCHER_TABLE_VIEW_H +#ifndef ESCHER_SIMPLE_TABLE_VIEW_H +#define ESCHER_SIMPLE_TABLE_VIEW_H #include -class TableViewDataSource { +class SimpleTableViewDataSource { public: virtual int numberOfRows() = 0; virtual int numberOfColumns() = 0; @@ -14,9 +14,9 @@ public: virtual int reusableCellCount() = 0; }; -class TableView : public ScrollView { +class SimpleTableView : public ScrollView { public: - TableView(TableViewDataSource * dataSource, KDCoordinate topMargin = 0, KDCoordinate rightMargin = 0, + SimpleTableView(SimpleTableViewDataSource * dataSource, KDCoordinate topMargin = 0, KDCoordinate rightMargin = 0, KDCoordinate bottomMargin = 0, KDCoordinate leftMargin = 0); void scrollToCell(int x, int y); @@ -28,7 +28,7 @@ protected: private: class ContentView : public View { public: - ContentView(TableView * tableView, TableViewDataSource * dataSource); + ContentView(SimpleTableView * tableView, SimpleTableViewDataSource * dataSource); KDCoordinate height() const; KDCoordinate width() const; @@ -56,8 +56,8 @@ private: bool columnAtIndexIsBeforeFullyVisibleRange(int index) const; bool rowAtIndexIsAfterFullyVisibleRange(int index) const; bool columnAtIndexIsAfterFullyVisibleRange(int index) const; - TableView * m_tableView; - TableViewDataSource * m_dataSource; + SimpleTableView * m_tableView; + SimpleTableViewDataSource * m_dataSource; }; void layoutSubviews() override; diff --git a/escher/src/list_view.cpp b/escher/src/list_view.cpp index fa143d947..0080e3c4d 100644 --- a/escher/src/list_view.cpp +++ b/escher/src/list_view.cpp @@ -24,7 +24,7 @@ void ListViewDataSource::willDisplayCellForIndex(View * cell, int index) { ListView::ListView(ListViewDataSource * dataSource, KDCoordinate topMargin, KDCoordinate rightMargin, KDCoordinate bottomMargin, KDCoordinate leftMargin) : - TableView(dataSource, topMargin, rightMargin, bottomMargin, leftMargin) + SimpleTableView(dataSource, topMargin, rightMargin, bottomMargin, leftMargin) { } diff --git a/escher/src/table_view.cpp b/escher/src/simple_table_view.cpp similarity index 71% rename from escher/src/table_view.cpp rename to escher/src/simple_table_view.cpp index 75eca0379..4f7d3808f 100644 --- a/escher/src/table_view.cpp +++ b/escher/src/simple_table_view.cpp @@ -1,4 +1,4 @@ -#include +#include #include extern "C" { @@ -7,34 +7,34 @@ extern "C" { #define MIN(x,y) ((x)<(y) ? (x) : (y)) -void TableViewDataSource::willDisplayCellAtLocation(View * cell, int x, int y) { +void SimpleTableViewDataSource::willDisplayCellAtLocation(View * cell, int x, int y) { } -TableView::TableView(TableViewDataSource * dataSource, KDCoordinate topMargin, KDCoordinate rightMargin, +SimpleTableView::SimpleTableView(SimpleTableViewDataSource * dataSource, KDCoordinate topMargin, KDCoordinate rightMargin, KDCoordinate bottomMargin, KDCoordinate leftMargin) : ScrollView(&m_contentView, topMargin, rightMargin, bottomMargin, leftMargin), - m_contentView(TableView::ContentView(this, dataSource)) + m_contentView(SimpleTableView::ContentView(this, dataSource)) { } // This method computes the minimal scrolling needed to properly display the // requested cell. -void TableView::scrollToCell(int x, int y) { +void SimpleTableView::scrollToCell(int x, int y) { m_contentView.scrollToCell(x, y); } -View * TableView::cellAtLocation(int x, int y) { +View * SimpleTableView::cellAtLocation(int x, int y) { return m_contentView.cellAtLocation(x, y); } #if ESCHER_VIEW_LOGGING -const char * TableView::className() const { - return "TableView"; +const char * SimpleTableView::className() const { + return "SimpleTableView"; } #endif -void TableView::layoutSubviews() { +void SimpleTableView::layoutSubviews() { // We only have to layout our contentView. // We will size it here, and ScrollView::layoutSubviews will position it. @@ -44,31 +44,31 @@ void TableView::layoutSubviews() { ScrollView::layoutSubviews(); } -/* TableView::ContentView */ +/* SimpleTableView::ContentView */ -TableView::ContentView::ContentView(TableView * tableView, TableViewDataSource * dataSource) : +SimpleTableView::ContentView::ContentView(SimpleTableView * tableView, SimpleTableViewDataSource * dataSource) : View(), m_tableView(tableView), m_dataSource(dataSource) { } -KDCoordinate TableView::ContentView::realCellWidth() const { +KDCoordinate SimpleTableView::ContentView::realCellWidth() const { int cellWidth = m_dataSource->cellWidth(); cellWidth = cellWidth ? cellWidth : m_tableView->maxContentWidthDisplayableWithoutScrolling(); return cellWidth; } -KDCoordinate TableView::ContentView::height() const { +KDCoordinate SimpleTableView::ContentView::height() const { return m_dataSource->numberOfRows() * m_dataSource->cellHeight(); } -KDCoordinate TableView::ContentView::width() const { +KDCoordinate SimpleTableView::ContentView::width() const { return m_dataSource->numberOfColumns() * realCellWidth(); } -void TableView::ContentView::scrollToCell(int x, int y) const { +void SimpleTableView::ContentView::scrollToCell(int x, int y) const { KDCoordinate contentOffsetX = m_tableView->contentOffset().x(); KDCoordinate contentOffsetY = m_tableView->contentOffset().y(); if (columnAtIndexIsBeforeFullyVisibleRange(x)) { @@ -88,31 +88,31 @@ void TableView::ContentView::scrollToCell(int x, int y) const { m_tableView->setContentOffset(KDPoint(contentOffsetX, contentOffsetY)); } -View * TableView::ContentView::cellAtLocation(int x, int y) { +View * SimpleTableView::ContentView::cellAtLocation(int x, int y) { int relativeX = x-columnsScrollingOffset(); int relativeY = y-rowsScrollingOffset(); return m_dataSource->reusableCell(relativeY*numberOfDisplayableColumns()+relativeX); } #if ESCHER_VIEW_LOGGING -const char * TableView::ContentView::className() const { +const char * SimpleTableView::ContentView::className() const { return "TableView::ContentView"; } #endif -int TableView::ContentView::numberOfSubviews() const { +int SimpleTableView::ContentView::numberOfSubviews() const { int result = numberOfDisplayableRows() * numberOfDisplayableColumns(); assert(result <= m_dataSource->reusableCellCount()); return result; } -View * TableView::ContentView::subviewAtIndex(int index) { +View * SimpleTableView::ContentView::subviewAtIndex(int index) { assert(index >= 0); assert(index < m_dataSource->reusableCellCount()); return m_dataSource->reusableCell(index); } -void TableView::ContentView::layoutSubviews() { +void SimpleTableView::ContentView::layoutSubviews() { int rowOffset = rowsScrollingOffset(); int columnOffset = columnsScrollingOffset(); @@ -135,24 +135,24 @@ void TableView::ContentView::layoutSubviews() { } } -int TableView::ContentView::numberOfFullyDisplayableRows() const { +int SimpleTableView::ContentView::numberOfFullyDisplayableRows() const { // The number of displayable rows taking into accounts margins return m_tableView->maxContentHeightDisplayableWithoutScrolling()/m_dataSource->cellHeight(); } -int TableView::ContentView::numberOfFullyDisplayableColumns() const { +int SimpleTableView::ContentView::numberOfFullyDisplayableColumns() const { // The number of displayable columns taking into accounts margins return m_tableView->maxContentWidthDisplayableWithoutScrolling()/m_dataSource->cellHeight(); } -int TableView::ContentView::numberOfDisplayableRows() const { +int SimpleTableView::ContentView::numberOfDisplayableRows() const { return MIN( m_dataSource->numberOfRows(), m_tableView->bounds().height() / m_dataSource->cellHeight() + 2 ); } -int TableView::ContentView::numberOfDisplayableColumns() const { +int SimpleTableView::ContentView::numberOfDisplayableColumns() const { KDCoordinate width = realCellWidth(); if (width == 0) { return 0; @@ -163,14 +163,14 @@ int TableView::ContentView::numberOfDisplayableColumns() const { ); } -int TableView::ContentView::rowsScrollingOffset() const { +int SimpleTableView::ContentView::rowsScrollingOffset() const { /* Here, we want to translate the offset at which our tableView 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(); } -int TableView::ContentView::columnsScrollingOffset() const { +int SimpleTableView::ContentView::columnsScrollingOffset() const { /* Here, we want to translate the offset at which our tableView is displaying * us into an integer offset we can use to ask cells to our data source. */ KDCoordinate width = realCellWidth(); @@ -181,20 +181,20 @@ int TableView::ContentView::columnsScrollingOffset() const { return pixelScrollingOffset / width; } -bool TableView::ContentView::rowAtIndexIsBeforeFullyVisibleRange(int index) const { +bool SimpleTableView::ContentView::rowAtIndexIsBeforeFullyVisibleRange(int index) const { return index <= rowsScrollingOffset(); } -bool TableView::ContentView::columnAtIndexIsBeforeFullyVisibleRange(int index) const { +bool SimpleTableView::ContentView::columnAtIndexIsBeforeFullyVisibleRange(int index) const { return index <= columnsScrollingOffset(); } -bool TableView::ContentView::rowAtIndexIsAfterFullyVisibleRange(int index) const { +bool SimpleTableView::ContentView::rowAtIndexIsAfterFullyVisibleRange(int index) const { int relativeIndex = index - rowsScrollingOffset(); return (relativeIndex >= numberOfFullyDisplayableRows()); } -bool TableView::ContentView::columnAtIndexIsAfterFullyVisibleRange(int index) const { +bool SimpleTableView::ContentView::columnAtIndexIsAfterFullyVisibleRange(int index) const { int relativeIndex = index - columnsScrollingOffset(); return (relativeIndex >= numberOfFullyDisplayableColumns()); } From d7231faf5c87ec1dd4f300528704108e3476e2cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Thu, 29 Sep 2016 14:38:53 +0200 Subject: [PATCH 2/5] [escher] add getter for margins in scrollview Change-Id: If12d7e6aec1f801c3b667ea9b0d44b85acd7ae42 --- escher/include/escher/scroll_view.h | 2 ++ escher/src/scroll_view.cpp | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/escher/include/escher/scroll_view.h b/escher/include/escher/scroll_view.h index f55f529c8..4380d59ea 100644 --- a/escher/include/escher/scroll_view.h +++ b/escher/include/escher/scroll_view.h @@ -11,6 +11,8 @@ public: void setContentOffset(KDPoint offset); KDPoint contentOffset(); + KDCoordinate topMargin() const; + KDCoordinate leftMargin() const; void drawRect(KDContext * ctx, KDRect rect) const override; protected: KDCoordinate maxContentWidthDisplayableWithoutScrolling(); diff --git a/escher/src/scroll_view.cpp b/escher/src/scroll_view.cpp index d6dbaf954..e2c3ad93d 100644 --- a/escher/src/scroll_view.cpp +++ b/escher/src/scroll_view.cpp @@ -120,6 +120,13 @@ KDPoint ScrollView::contentOffset() { return m_offset; } +KDCoordinate ScrollView::topMargin() const { + return m_topMargin; +} + +KDCoordinate ScrollView::leftMargin() const { + return m_leftMargin; +} KDCoordinate ScrollView::maxContentWidthDisplayableWithoutScrolling() { return m_frame.width() - m_leftMargin - m_rightMargin; From 71304967074407c393c2c7fb37e4ed21277f1f5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Thu, 29 Sep 2016 14:54:11 +0200 Subject: [PATCH 3/5] [escher] add a table view handling cells of different types and sizes Change-Id: I678aa4273ccea33fd293205407c51c162515786e --- escher/Makefile | 1 + escher/include/escher.h | 1 + escher/include/escher/table_view.h | 87 +++++++++++ escher/src/table_view.cpp | 238 +++++++++++++++++++++++++++++ 4 files changed, 327 insertions(+) create mode 100644 escher/include/escher/table_view.h create mode 100644 escher/src/table_view.cpp diff --git a/escher/Makefile b/escher/Makefile index 57a76c332..82220c591 100644 --- a/escher/Makefile +++ b/escher/Makefile @@ -21,6 +21,7 @@ objs += $(addprefix escher/src/,\ tab_view.o\ tab_view_cell.o\ tab_view_controller.o\ + table_view.o\ table_view_cell.o\ text_field.o\ text_view.o\ diff --git a/escher/include/escher.h b/escher/include/escher.h index 0d19e8a96..d60d09190 100644 --- a/escher/include/escher.h +++ b/escher/include/escher.h @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include diff --git a/escher/include/escher/table_view.h b/escher/include/escher/table_view.h new file mode 100644 index 000000000..24ed7ab3c --- /dev/null +++ b/escher/include/escher/table_view.h @@ -0,0 +1,87 @@ +#ifndef ESCHER_TABLE_VIEW_H +#define ESCHER_TABLE_VIEW_H + +#include + +class TableViewDataSource { +public: + virtual int numberOfRows() = 0; + virtual int numberOfColumns() = 0; + virtual void willDisplayCellAtLocation(View * cell, int i, int j); + virtual KDCoordinate columnWidth(int i) = 0; + virtual KDCoordinate rowHeight(int j) = 0; + /* return the number of pixels to include in offset to display the column i at + the top */ + virtual KDCoordinate cumulatedWidthFromIndex(int i) = 0; + virtual KDCoordinate cumulatedHeightFromIndex(int j) = 0; + /* return the number of columns (starting with first ones) that can be fully + * displayed in offsetX pixels. + * Caution: if the offset is exactly the size of n columns, the function + * returns n-1. */ + virtual int indexFromCumulatedWidth(KDCoordinate offsetX) = 0; + virtual int indexFromCumulatedHeight(KDCoordinate offsetY) = 0; + virtual View * reusableCell(int index, int type) = 0; + virtual int reusableCellCount(int type) = 0; + virtual int typeAtLocation(int i, int j) = 0; +}; + +class TableView : public ScrollView { +public: + TableView(TableViewDataSource * dataSource, KDCoordinate topMargin = 0, + KDCoordinate rightMargin = 0, KDCoordinate bottomMargin = 0, KDCoordinate leftMargin = 0); + + void scrollToCell(int i, int j); + View * cellAtLocation(int i, int j); +protected: +#if ESCHER_VIEW_LOGGING + const char * className() const override; +#endif +private: + class ContentView : public View { + public: + ContentView(TableView * tableView, TableViewDataSource * dataSource); + + KDCoordinate height() const; + KDCoordinate width() const; + void scrollToCell(int i, int j) const; + View * cellAtLocation(int i, int j); + protected: +#if ESCHER_VIEW_LOGGING + const char * className() const override; +#endif + private: + int numberOfSubviews() const override; + View * subviewAtIndex(int index) override; + void layoutSubviews() override; + + /* realCellWidth enables to handle list view for which + * TableViewDataSource->cellWidht = 0 */ + KDCoordinate columnWidth(int x) const; + /* These two methods transform an index (of subview for instance) into + * coordinates that refer to the data source entire table */ + int absoluteColumnNumberFromSubviewIndex(int index) const; + int absoluteRowNumberFromSubviewIndex(int index) const; + int numberOfFullyDisplayableRows() const; + int numberOfFullyDisplayableColumns() const; + int numberOfDisplayableRows() const; + int numberOfDisplayableColumns() const; + int rowsScrollingOffset() const; + int columnsScrollingOffset() const; + bool rowAtIndexIsBeforeFullyVisibleRange(int index) const; + bool columnAtIndexIsBeforeFullyVisibleRange(int index) const; + bool rowAtIndexIsAfterFullyVisibleRange(int index) const; + bool columnAtIndexIsAfterFullyVisibleRange(int index) const; + int typeOfSubviewAtIndex(int index) const; + /* This method transform a index (of subview for instance) into an index + * refering to the set of cells of type "type". */ + int typeIndexFromSubviewIndex(int index, int type) const; + TableView * m_tableView; + TableViewDataSource * m_dataSource; + }; + + void layoutSubviews() override; + + ContentView m_contentView; +}; + +#endif diff --git a/escher/src/table_view.cpp b/escher/src/table_view.cpp new file mode 100644 index 000000000..567310328 --- /dev/null +++ b/escher/src/table_view.cpp @@ -0,0 +1,238 @@ +#include +#include + +extern "C" { +#include +} + +#define MIN(x,y) ((x)<(y) ? (x) : (y)) + +void TableViewDataSource::willDisplayCellAtLocation(View * cell, int i, int j) { +} + +TableView::TableView(TableViewDataSource * dataSource, KDCoordinate topMargin, KDCoordinate rightMargin, + KDCoordinate bottomMargin, KDCoordinate leftMargin) : + ScrollView(&m_contentView, topMargin, rightMargin, bottomMargin, leftMargin), + m_contentView(TableView::ContentView(this, dataSource)) +{ +} + +// This method computes the minimal scrolling needed to properly display the +// requested cell. +void TableView::scrollToCell(int i, int j) { + m_contentView.scrollToCell(i, j); +} + +View * TableView::cellAtLocation(int i, int j) { + return m_contentView.cellAtLocation(i, j); +} + +#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. + + KDRect contentViewFrame(0, 0, m_contentView.width(), m_contentView.height()); + m_contentView.setFrame(contentViewFrame); + + ScrollView::layoutSubviews(); +} + +/* TableView::ContentView */ + +TableView::ContentView::ContentView(TableView * tableView, TableViewDataSource * dataSource) : + View(), + m_tableView(tableView), + m_dataSource(dataSource) +{ +} + +KDCoordinate TableView::ContentView::columnWidth(int i) const { + int columnWidth = m_dataSource->columnWidth(i); + columnWidth = columnWidth ? columnWidth : m_tableView->maxContentWidthDisplayableWithoutScrolling(); + return columnWidth; +} + + +KDCoordinate TableView::ContentView::height() const { + return m_dataSource->cumulatedHeightFromIndex(m_dataSource->numberOfRows()); +} + +KDCoordinate TableView::ContentView::width() const { + int result = m_dataSource->cumulatedWidthFromIndex(m_dataSource->numberOfColumns()); + // handle the case of list: cumulatedWidthFromIndex() = 0 + return result ? result : m_tableView->maxContentWidthDisplayableWithoutScrolling(); +} + +void TableView::ContentView::scrollToCell(int x, int y) const { + KDCoordinate contentOffsetX = m_tableView->contentOffset().x(); + KDCoordinate contentOffsetY = m_tableView->contentOffset().y(); + if (columnAtIndexIsBeforeFullyVisibleRange(x)) { + // Let's scroll the tableView to put that cell on the left (while keeping the left margin) + contentOffsetX = m_dataSource->cumulatedWidthFromIndex(x); + } else if (columnAtIndexIsAfterFullyVisibleRange(x)) { + // Let's scroll the tableView to put that cell on the right (while keeping the right margin) + contentOffsetX = m_dataSource->cumulatedWidthFromIndex(x+1)-m_tableView->maxContentWidthDisplayableWithoutScrolling(); + } + if (rowAtIndexIsBeforeFullyVisibleRange(y)) { + // Let's scroll the tableView to put that cell on the top (while keeping the top margin) + contentOffsetY = m_dataSource->cumulatedHeightFromIndex(y); + } else if (rowAtIndexIsAfterFullyVisibleRange(y)) { + // Let's scroll the tableView to put that cell on the bottom (while keeping the bottom margin) + contentOffsetY = m_dataSource->cumulatedHeightFromIndex(y+1) - m_tableView->maxContentHeightDisplayableWithoutScrolling(); + } + m_tableView->setContentOffset(KDPoint(contentOffsetX, contentOffsetY)); +} + +int TableView::ContentView::typeOfSubviewAtIndex(int index) const { + assert(index >= 0); + int i = absoluteColumnNumberFromSubviewIndex(index); + int j = absoluteRowNumberFromSubviewIndex(index); + int type = m_dataSource->typeAtLocation(i, j); + return type; +} + +int TableView::ContentView::typeIndexFromSubviewIndex(int index, int type) const { + int typeIndex = 0; + for (int k = 0; k < index; k++) { + if (typeOfSubviewAtIndex(k) == type) { + typeIndex++; + } + } + assert(typeIndex < m_dataSource->reusableCellCount(type)); + return typeIndex; +} + +View * TableView::ContentView::cellAtLocation(int x, int y) { + int relativeX = x-columnsScrollingOffset(); + int relativeY = y-rowsScrollingOffset(); + int type = m_dataSource->typeAtLocation(x, y); + int index = relativeY*numberOfDisplayableColumns()+relativeX; + int typeIndex = typeIndexFromSubviewIndex(index, type); + return m_dataSource->reusableCell(typeIndex, type); +} + +#if ESCHER_VIEW_LOGGING +const char * TableView::ContentView::className() const { + return "TableView::ContentView"; +} +#endif + +int TableView::ContentView::numberOfSubviews() const { + int result = numberOfDisplayableRows() * numberOfDisplayableColumns(); + return result; +} + +int TableView::ContentView::absoluteColumnNumberFromSubviewIndex(int index) const { + /* "x = i % columns" but we avoid a call to modulo not to implement + * "__aeabi_idivmod" */ + int j = index / numberOfDisplayableColumns(); + int i = index - j * numberOfDisplayableColumns(); + int columnOffset = columnsScrollingOffset(); + return i + columnOffset; +} + +int TableView::ContentView::absoluteRowNumberFromSubviewIndex(int index) const { + int j = index / numberOfDisplayableColumns(); + int rowOffset = rowsScrollingOffset(); + return j + rowOffset; +} + +View * TableView::ContentView::subviewAtIndex(int index) { + int type = typeOfSubviewAtIndex(index); + int typeIndex = typeIndexFromSubviewIndex(index, type); + return m_dataSource->reusableCell(typeIndex, type); +} + +void TableView::ContentView::layoutSubviews() { + for (int index=0; indexrowHeight(j); + KDCoordinate columnWidth = this->columnWidth(i); + KDCoordinate verticalOffset = m_dataSource->cumulatedHeightFromIndex(j); + KDCoordinate horizontalOffset = m_dataSource->cumulatedWidthFromIndex(i); + KDRect cellFrame(horizontalOffset, verticalOffset, + columnWidth, rowHeight); + + cell->setFrame(cellFrame); + + m_dataSource->willDisplayCellAtLocation(cell, i, j); + } +} + + +int TableView::ContentView::numberOfFullyDisplayableRows() const { + // The number of displayable rows taking into accounts margins + int rowOffsetWithMargin = m_dataSource->indexFromCumulatedHeight(m_tableView->contentOffset().y() + + m_tableView->topMargin()); + int displayedHeightWithOffsetAndMargin = m_dataSource->indexFromCumulatedHeight(m_tableView->maxContentHeightDisplayableWithoutScrolling() + + m_tableView->contentOffset().y() + m_tableView->topMargin()); + return displayedHeightWithOffsetAndMargin - rowOffsetWithMargin; +} + +int TableView::ContentView::numberOfFullyDisplayableColumns() const { + // The number of displayable rows taking into accounts margins + int columnOffsetWithMargin = m_dataSource->indexFromCumulatedWidth(m_tableView->contentOffset().x() + + m_tableView->leftMargin()); + int displayedWidthWithOffsetAndMargin = m_dataSource->indexFromCumulatedWidth(m_tableView->maxContentWidthDisplayableWithoutScrolling() + + m_tableView->contentOffset().x() + m_tableView->leftMargin()); + return displayedWidthWithOffsetAndMargin - columnOffsetWithMargin; +} + +int TableView::ContentView::numberOfDisplayableRows() const { + int rowOffset = rowsScrollingOffset(); + int displayedHeightWithOffset = m_dataSource->indexFromCumulatedHeight(m_tableView->bounds().height() + m_tableView->contentOffset().y()); + return MIN( + m_dataSource->numberOfRows(), + displayedHeightWithOffset + 1 + ) - rowOffset; +} + +int TableView::ContentView::numberOfDisplayableColumns() const { + int columnOffset = columnsScrollingOffset(); + int displayedWidthWithOffset = m_dataSource->indexFromCumulatedWidth(m_tableView->bounds().width() + m_tableView->contentOffset().x()); + return MIN( + m_dataSource->numberOfColumns(), + displayedWidthWithOffset + 1 + ) - columnOffset; +} + +int TableView::ContentView::rowsScrollingOffset() const { + /* Here, we want to translate the offset at which our tableView is displaying + * us into an integer offset we can use to ask cells to our data source. */ + return m_dataSource->indexFromCumulatedHeight(m_tableView->contentOffset().y()); +} + +int TableView::ContentView::columnsScrollingOffset() const { + /* Here, we want to translate the offset at which our tableView is displaying + * us into an integer offset we can use to ask cells to our data source. */ + return m_dataSource->indexFromCumulatedWidth(m_tableView->contentOffset().x()); +} + +bool TableView::ContentView::rowAtIndexIsBeforeFullyVisibleRange(int index) const { + return index <= rowsScrollingOffset(); +} + +bool TableView::ContentView::columnAtIndexIsBeforeFullyVisibleRange(int index) const { + return index <= columnsScrollingOffset(); +} + +bool TableView::ContentView::rowAtIndexIsAfterFullyVisibleRange(int index) const { + int minHeightToDisplayRowAtIndex = m_dataSource->cumulatedHeightFromIndex(index+1); + int heightToTheBottomOfTheScreen = m_tableView->contentOffset().y()+m_tableView->maxContentHeightDisplayableWithoutScrolling()+m_tableView->topMargin(); + return minHeightToDisplayRowAtIndex >= heightToTheBottomOfTheScreen; +} + +bool TableView::ContentView::columnAtIndexIsAfterFullyVisibleRange(int index) const { + int minWidthToDisplayColumnAtIndex = m_dataSource->cumulatedWidthFromIndex(index+1); + int widthToTheRightOfTheScreen = m_tableView->contentOffset().x()+m_tableView->maxContentWidthDisplayableWithoutScrolling()+m_tableView->leftMargin(); + return minWidthToDisplayColumnAtIndex >= widthToTheRightOfTheScreen; +} From dad80001afea3903235528fb922c9d3b8073040f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Thu, 29 Sep 2016 17:37:23 +0200 Subject: [PATCH 4/5] [escher] break table view and table view data source in two files Change-Id: I98407e8900727d1ce8fea78c721f56192a24e1f8 --- escher/Makefile | 1 + escher/include/escher.h | 1 + escher/include/escher/table_view.h | 23 +-------------- .../include/escher/table_view_data_source.h | 28 +++++++++++++++++++ escher/src/table_view.cpp | 3 -- escher/src/table_view_data_source.cpp | 4 +++ 6 files changed, 35 insertions(+), 25 deletions(-) create mode 100644 escher/include/escher/table_view_data_source.h create mode 100644 escher/src/table_view_data_source.cpp diff --git a/escher/Makefile b/escher/Makefile index 82220c591..e95ee39a9 100644 --- a/escher/Makefile +++ b/escher/Makefile @@ -23,6 +23,7 @@ objs += $(addprefix escher/src/,\ tab_view_controller.o\ table_view.o\ table_view_cell.o\ + table_view_data_source.o\ text_field.o\ text_view.o\ tiled_view.o\ diff --git a/escher/include/escher.h b/escher/include/escher.h index d60d09190..38db06028 100644 --- a/escher/include/escher.h +++ b/escher/include/escher.h @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include diff --git a/escher/include/escher/table_view.h b/escher/include/escher/table_view.h index 24ed7ab3c..f50649101 100644 --- a/escher/include/escher/table_view.h +++ b/escher/include/escher/table_view.h @@ -2,28 +2,7 @@ #define ESCHER_TABLE_VIEW_H #include - -class TableViewDataSource { -public: - virtual int numberOfRows() = 0; - virtual int numberOfColumns() = 0; - virtual void willDisplayCellAtLocation(View * cell, int i, int j); - virtual KDCoordinate columnWidth(int i) = 0; - virtual KDCoordinate rowHeight(int j) = 0; - /* return the number of pixels to include in offset to display the column i at - the top */ - virtual KDCoordinate cumulatedWidthFromIndex(int i) = 0; - virtual KDCoordinate cumulatedHeightFromIndex(int j) = 0; - /* return the number of columns (starting with first ones) that can be fully - * displayed in offsetX pixels. - * Caution: if the offset is exactly the size of n columns, the function - * returns n-1. */ - virtual int indexFromCumulatedWidth(KDCoordinate offsetX) = 0; - virtual int indexFromCumulatedHeight(KDCoordinate offsetY) = 0; - virtual View * reusableCell(int index, int type) = 0; - virtual int reusableCellCount(int type) = 0; - virtual int typeAtLocation(int i, int j) = 0; -}; +#include class TableView : public ScrollView { public: diff --git a/escher/include/escher/table_view_data_source.h b/escher/include/escher/table_view_data_source.h new file mode 100644 index 000000000..62dcffc2a --- /dev/null +++ b/escher/include/escher/table_view_data_source.h @@ -0,0 +1,28 @@ +#ifndef ESCHER_TABLE_VIEW_DATA_SOURCE_H +#define ESCHER_TABLE_VIEW_DATA_SOURCE_H + +#include + +class TableViewDataSource { +public: + virtual int numberOfRows() = 0; + virtual int numberOfColumns() = 0; + virtual void willDisplayCellAtLocation(View * cell, int i, int j); + virtual KDCoordinate columnWidth(int i) = 0; + virtual KDCoordinate rowHeight(int j) = 0; + /* return the number of pixels to include in offset to display the column i at + the top */ + virtual KDCoordinate cumulatedWidthFromIndex(int i) = 0; + virtual KDCoordinate cumulatedHeightFromIndex(int j) = 0; + /* return the number of columns (starting with first ones) that can be fully + * displayed in offsetX pixels. + * Caution: if the offset is exactly the size of n columns, the function + * returns n-1. */ + virtual int indexFromCumulatedWidth(KDCoordinate offsetX) = 0; + virtual int indexFromCumulatedHeight(KDCoordinate offsetY) = 0; + virtual View * reusableCell(int index, int type) = 0; + virtual int reusableCellCount(int type) = 0; + virtual int typeAtLocation(int i, int j) = 0; +}; + +#endif \ No newline at end of file diff --git a/escher/src/table_view.cpp b/escher/src/table_view.cpp index 567310328..65b01c2a7 100644 --- a/escher/src/table_view.cpp +++ b/escher/src/table_view.cpp @@ -7,9 +7,6 @@ extern "C" { #define MIN(x,y) ((x)<(y) ? (x) : (y)) -void TableViewDataSource::willDisplayCellAtLocation(View * cell, int i, int j) { -} - TableView::TableView(TableViewDataSource * dataSource, KDCoordinate topMargin, KDCoordinate rightMargin, KDCoordinate bottomMargin, KDCoordinate leftMargin) : ScrollView(&m_contentView, topMargin, rightMargin, bottomMargin, leftMargin), diff --git a/escher/src/table_view_data_source.cpp b/escher/src/table_view_data_source.cpp new file mode 100644 index 000000000..eb728bff9 --- /dev/null +++ b/escher/src/table_view_data_source.cpp @@ -0,0 +1,4 @@ +#include + +void TableViewDataSource::willDisplayCellAtLocation(View * cell, int i, int j) { +} From c3bf55d622b8b7aff447e2d230c5be9d3b7662a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Thu, 29 Sep 2016 17:43:14 +0200 Subject: [PATCH 5/5] [escher] make simple table view data source inherit from table view Change-Id: Ia3c64b643f633e4c7c6fd0f921fe6a79336a7b64 --- escher/Makefile | 2 +- escher/include/escher.h | 2 +- escher/include/escher/list_view.h | 4 +- escher/include/escher/simple_table_view.h | 68 ------ .../escher/simple_table_view_data_source.h | 23 ++ escher/src/list_view.cpp | 4 +- escher/src/simple_table_view.cpp | 200 ------------------ escher/src/simple_table_view_data_source.cpp | 52 +++++ 8 files changed, 80 insertions(+), 275 deletions(-) delete mode 100644 escher/include/escher/simple_table_view.h create mode 100644 escher/include/escher/simple_table_view_data_source.h delete mode 100644 escher/src/simple_table_view.cpp create mode 100644 escher/src/simple_table_view_data_source.cpp diff --git a/escher/Makefile b/escher/Makefile index e95ee39a9..5889d1ed6 100644 --- a/escher/Makefile +++ b/escher/Makefile @@ -12,7 +12,7 @@ objs += $(addprefix escher/src/,\ responder.o\ scroll_view.o\ scroll_view_indicator.o\ - simple_table_view.o\ + simple_table_view_data_source.o\ solid_color_view.o\ stack_view.o\ stack_view_controller.o\ diff --git a/escher/include/escher.h b/escher/include/escher.h index 38db06028..a071a4f9e 100644 --- a/escher/include/escher.h +++ b/escher/include/escher.h @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/escher/include/escher/list_view.h b/escher/include/escher/list_view.h index beba4b84f..99c220989 100644 --- a/escher/include/escher/list_view.h +++ b/escher/include/escher/list_view.h @@ -1,7 +1,7 @@ #ifndef ESCHER_LIST_VIEW_H #define ESCHER_LIST_VIEW_H -#include +#include class ListViewDataSource : public SimpleTableViewDataSource{ public: @@ -11,7 +11,7 @@ public: virtual void willDisplayCellForIndex(View * cell, int index); }; -class ListView : public SimpleTableView { +class ListView : public TableView { public: ListView(ListViewDataSource * dataSource, KDCoordinate topMargin = 0, KDCoordinate rightMargin = 0, KDCoordinate bottomMargin = 0, KDCoordinate leftMargin = 0); diff --git a/escher/include/escher/simple_table_view.h b/escher/include/escher/simple_table_view.h deleted file mode 100644 index aac7bf2a2..000000000 --- a/escher/include/escher/simple_table_view.h +++ /dev/null @@ -1,68 +0,0 @@ -#ifndef ESCHER_SIMPLE_TABLE_VIEW_H -#define ESCHER_SIMPLE_TABLE_VIEW_H - -#include - -class SimpleTableViewDataSource { -public: - virtual int numberOfRows() = 0; - virtual int numberOfColumns() = 0; - virtual void willDisplayCellAtLocation(View * cell, int x, int y); - virtual KDCoordinate cellHeight() = 0; - virtual KDCoordinate cellWidth() = 0; - virtual View * reusableCell(int index) = 0; - virtual int reusableCellCount() = 0; -}; - -class SimpleTableView : public ScrollView { -public: - SimpleTableView(SimpleTableViewDataSource * dataSource, KDCoordinate topMargin = 0, KDCoordinate rightMargin = 0, - KDCoordinate bottomMargin = 0, KDCoordinate leftMargin = 0); - - void scrollToCell(int x, int y); - View * cellAtLocation(int x, int y); -protected: -#if ESCHER_VIEW_LOGGING - const char * className() const override; -#endif -private: - class ContentView : public View { - public: - ContentView(SimpleTableView * tableView, SimpleTableViewDataSource * dataSource); - - KDCoordinate height() const; - KDCoordinate width() const; - void scrollToCell(int x, int y) const; - View * cellAtLocation(int x, int y); - protected: -#if ESCHER_VIEW_LOGGING - const char * className() const override; -#endif - private: - int numberOfSubviews() const override; - View * subviewAtIndex(int index) override; - void layoutSubviews() override; - - /* realCellWidth enables to handle list view for which - * TableViewDataSource->cellWidht = 0 */ - KDCoordinate realCellWidth() const; - int numberOfFullyDisplayableRows() const; - int numberOfFullyDisplayableColumns() const; - int numberOfDisplayableRows() const; - int numberOfDisplayableColumns() const; - int rowsScrollingOffset() const; - int columnsScrollingOffset() const; - bool rowAtIndexIsBeforeFullyVisibleRange(int index) const; - bool columnAtIndexIsBeforeFullyVisibleRange(int index) const; - bool rowAtIndexIsAfterFullyVisibleRange(int index) const; - bool columnAtIndexIsAfterFullyVisibleRange(int index) const; - SimpleTableView * m_tableView; - SimpleTableViewDataSource * m_dataSource; - }; - - void layoutSubviews() override; - - ContentView m_contentView; -}; - -#endif diff --git a/escher/include/escher/simple_table_view_data_source.h b/escher/include/escher/simple_table_view_data_source.h new file mode 100644 index 000000000..ae9257183 --- /dev/null +++ b/escher/include/escher/simple_table_view_data_source.h @@ -0,0 +1,23 @@ +#ifndef ESCHER_SIMPLE_TABLE_VIEW_DATA_SOURCE_H +#define ESCHER_SIMPLE_TABLE_VIEW_DATA_SOURCE_H + +#include + +class SimpleTableViewDataSource : public TableViewDataSource { +public: + virtual KDCoordinate cellHeight() = 0; + virtual KDCoordinate cellWidth() = 0; + KDCoordinate columnWidth(int i) override; + KDCoordinate rowHeight(int j) override; + KDCoordinate cumulatedWidthFromIndex(int i) override; + KDCoordinate cumulatedHeightFromIndex(int j) override; + int indexFromCumulatedWidth(KDCoordinate offsetX) override; + int indexFromCumulatedHeight(KDCoordinate offsetY) override; + virtual View * reusableCell(int index) = 0; + virtual int reusableCellCount() = 0; + View * reusableCell(int index, int type) override; + int reusableCellCount(int type) override; + int typeAtLocation(int i, int j) override; +}; + +#endif diff --git a/escher/src/list_view.cpp b/escher/src/list_view.cpp index 0080e3c4d..5d1f2c4d0 100644 --- a/escher/src/list_view.cpp +++ b/escher/src/list_view.cpp @@ -5,8 +5,6 @@ extern "C" { #include } -#define MIN(x,y) ((x)<(y) ? (x) : (y)) - int ListViewDataSource::numberOfColumns() { return 1; } @@ -24,7 +22,7 @@ void ListViewDataSource::willDisplayCellForIndex(View * cell, int index) { ListView::ListView(ListViewDataSource * dataSource, KDCoordinate topMargin, KDCoordinate rightMargin, KDCoordinate bottomMargin, KDCoordinate leftMargin) : - SimpleTableView(dataSource, topMargin, rightMargin, bottomMargin, leftMargin) + TableView(dataSource, topMargin, rightMargin, bottomMargin, leftMargin) { } diff --git a/escher/src/simple_table_view.cpp b/escher/src/simple_table_view.cpp deleted file mode 100644 index 4f7d3808f..000000000 --- a/escher/src/simple_table_view.cpp +++ /dev/null @@ -1,200 +0,0 @@ -#include -#include - -extern "C" { -#include -} - -#define MIN(x,y) ((x)<(y) ? (x) : (y)) - -void SimpleTableViewDataSource::willDisplayCellAtLocation(View * cell, int x, int y) { -} - - -SimpleTableView::SimpleTableView(SimpleTableViewDataSource * dataSource, KDCoordinate topMargin, KDCoordinate rightMargin, - KDCoordinate bottomMargin, KDCoordinate leftMargin) : - ScrollView(&m_contentView, topMargin, rightMargin, bottomMargin, leftMargin), - m_contentView(SimpleTableView::ContentView(this, dataSource)) -{ -} - -// This method computes the minimal scrolling needed to properly display the -// requested cell. -void SimpleTableView::scrollToCell(int x, int y) { - m_contentView.scrollToCell(x, y); -} - -View * SimpleTableView::cellAtLocation(int x, int y) { - return m_contentView.cellAtLocation(x, y); -} - -#if ESCHER_VIEW_LOGGING -const char * SimpleTableView::className() const { - return "SimpleTableView"; -} -#endif - -void SimpleTableView::layoutSubviews() { - // We only have to layout our contentView. - // We will size it here, and ScrollView::layoutSubviews will position it. - - KDRect contentViewFrame(0, 0, m_contentView.width(), m_contentView.height()); - m_contentView.setFrame(contentViewFrame); - - ScrollView::layoutSubviews(); -} - -/* SimpleTableView::ContentView */ - -SimpleTableView::ContentView::ContentView(SimpleTableView * tableView, SimpleTableViewDataSource * dataSource) : - View(), - m_tableView(tableView), - m_dataSource(dataSource) -{ -} - -KDCoordinate SimpleTableView::ContentView::realCellWidth() const { - int cellWidth = m_dataSource->cellWidth(); - cellWidth = cellWidth ? cellWidth : m_tableView->maxContentWidthDisplayableWithoutScrolling(); - return cellWidth; -} - - -KDCoordinate SimpleTableView::ContentView::height() const { - return m_dataSource->numberOfRows() * m_dataSource->cellHeight(); -} - -KDCoordinate SimpleTableView::ContentView::width() const { - return m_dataSource->numberOfColumns() * realCellWidth(); -} - -void SimpleTableView::ContentView::scrollToCell(int x, int y) const { - KDCoordinate contentOffsetX = m_tableView->contentOffset().x(); - KDCoordinate contentOffsetY = m_tableView->contentOffset().y(); - if (columnAtIndexIsBeforeFullyVisibleRange(x)) { - // Let's scroll the tableView to put that cell on the left (while keeping the left margin) - contentOffsetX = x*realCellWidth(); - } else if (columnAtIndexIsAfterFullyVisibleRange(x)) { - // Let's scroll the tableView to put that cell on the right (while keeping the right margin) - contentOffsetX = (x+1)*realCellWidth() - m_tableView->maxContentWidthDisplayableWithoutScrolling(); - } - if (rowAtIndexIsBeforeFullyVisibleRange(y)) { - // Let's scroll the tableView to put that cell on the top (while keeping the top margin) - contentOffsetY = y*m_dataSource->cellHeight(); - } else if (rowAtIndexIsAfterFullyVisibleRange(y)) { - // Let's scroll the tableView to put that cell on the bottom (while keeping the bottom margin) - contentOffsetY = (y+1)*m_dataSource->cellHeight() - m_tableView->maxContentHeightDisplayableWithoutScrolling(); - } - m_tableView->setContentOffset(KDPoint(contentOffsetX, contentOffsetY)); -} - -View * SimpleTableView::ContentView::cellAtLocation(int x, int y) { - int relativeX = x-columnsScrollingOffset(); - int relativeY = y-rowsScrollingOffset(); - return m_dataSource->reusableCell(relativeY*numberOfDisplayableColumns()+relativeX); -} - -#if ESCHER_VIEW_LOGGING -const char * SimpleTableView::ContentView::className() const { - return "TableView::ContentView"; -} -#endif - -int SimpleTableView::ContentView::numberOfSubviews() const { - int result = numberOfDisplayableRows() * numberOfDisplayableColumns(); - assert(result <= m_dataSource->reusableCellCount()); - return result; -} - -View * SimpleTableView::ContentView::subviewAtIndex(int index) { - assert(index >= 0); - assert(index < m_dataSource->reusableCellCount()); - return m_dataSource->reusableCell(index); -} - -void SimpleTableView::ContentView::layoutSubviews() { - int rowOffset = rowsScrollingOffset(); - int columnOffset = columnsScrollingOffset(); - - for (int i=0; icellHeight(); - KDCoordinate cellWidth = realCellWidth(); - KDRect cellFrame((columnOffset+x)*cellWidth, (rowOffset+y)*cellHeight, - cellWidth, cellHeight); - - cell->setFrame(cellFrame); - - m_dataSource->willDisplayCellAtLocation(cell, columnOffset+x, rowOffset+y); - } -} - -int SimpleTableView::ContentView::numberOfFullyDisplayableRows() const { - // The number of displayable rows taking into accounts margins - return m_tableView->maxContentHeightDisplayableWithoutScrolling()/m_dataSource->cellHeight(); -} - -int SimpleTableView::ContentView::numberOfFullyDisplayableColumns() const { - // The number of displayable columns taking into accounts margins - return m_tableView->maxContentWidthDisplayableWithoutScrolling()/m_dataSource->cellHeight(); -} - -int SimpleTableView::ContentView::numberOfDisplayableRows() const { - return MIN( - m_dataSource->numberOfRows(), - m_tableView->bounds().height() / m_dataSource->cellHeight() + 2 - ); -} - -int SimpleTableView::ContentView::numberOfDisplayableColumns() const { - KDCoordinate width = realCellWidth(); - if (width == 0) { - return 0; - } - return MIN( - m_dataSource->numberOfColumns(), - m_tableView->bounds().width() / width + 2 - ); -} - -int SimpleTableView::ContentView::rowsScrollingOffset() const { - /* Here, we want to translate the offset at which our tableView 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(); -} - -int SimpleTableView::ContentView::columnsScrollingOffset() const { - /* Here, we want to translate the offset at which our tableView is displaying - * us into an integer offset we can use to ask cells to our data source. */ - KDCoordinate width = realCellWidth(); - if (width == 0) { - return 0; - } - KDCoordinate pixelScrollingOffset = -m_frame.x(); - return pixelScrollingOffset / width; -} - -bool SimpleTableView::ContentView::rowAtIndexIsBeforeFullyVisibleRange(int index) const { - return index <= rowsScrollingOffset(); -} - -bool SimpleTableView::ContentView::columnAtIndexIsBeforeFullyVisibleRange(int index) const { - return index <= columnsScrollingOffset(); -} - -bool SimpleTableView::ContentView::rowAtIndexIsAfterFullyVisibleRange(int index) const { - int relativeIndex = index - rowsScrollingOffset(); - return (relativeIndex >= numberOfFullyDisplayableRows()); -} - -bool SimpleTableView::ContentView::columnAtIndexIsAfterFullyVisibleRange(int index) const { - int relativeIndex = index - columnsScrollingOffset(); - return (relativeIndex >= numberOfFullyDisplayableColumns()); -} diff --git a/escher/src/simple_table_view_data_source.cpp b/escher/src/simple_table_view_data_source.cpp new file mode 100644 index 000000000..d7a8f33e3 --- /dev/null +++ b/escher/src/simple_table_view_data_source.cpp @@ -0,0 +1,52 @@ +#include +#include + +extern "C" { +#include +} + +KDCoordinate SimpleTableViewDataSource::columnWidth(int i) { + return cellWidth(); +} + +KDCoordinate SimpleTableViewDataSource::rowHeight(int j) { + return cellHeight(); +} + +KDCoordinate SimpleTableViewDataSource::cumulatedWidthFromIndex(int i) { + return cellWidth() * i; +} + +KDCoordinate SimpleTableViewDataSource::cumulatedHeightFromIndex(int j) { + return cellHeight() * j; +} + +int SimpleTableViewDataSource::indexFromCumulatedWidth(KDCoordinate offsetX) { + KDCoordinate width = cellWidth(); + if (width == 0) { + return 0; + } + return (offsetX - 1) / width; +} + +int SimpleTableViewDataSource::indexFromCumulatedHeight(KDCoordinate offsetY) { + KDCoordinate height = cellHeight(); + if (height == 0) { + return 0; + } + return (offsetY - 1) / height; +} + +View * SimpleTableViewDataSource::reusableCell(int index, int type) { + assert(type == 0); + return reusableCell(index); +} + +int SimpleTableViewDataSource::reusableCellCount(int type) { + assert(type == 0); + return reusableCellCount(); +} + +int SimpleTableViewDataSource::typeAtLocation(int i, int j) { + return 0; +}