diff --git a/apps/calculation/history_controller.cpp b/apps/calculation/history_controller.cpp index 931392f1a..c233b78b1 100644 --- a/apps/calculation/history_controller.cpp +++ b/apps/calculation/history_controller.cpp @@ -72,7 +72,7 @@ int HistoryController::numberOfRows() { }; -View * HistoryController::reusableCell(int index, int type) { +TableViewCell * HistoryController::reusableCell(int index, int type) { assert(type == 0); assert(index >= 0); assert(index < k_maxNumberOfDisplayedRows); @@ -84,7 +84,7 @@ int HistoryController::reusableCellCount(int type) { return k_maxNumberOfDisplayedRows; } -void HistoryController::willDisplayCellForIndex(View * cell, int index) { +void HistoryController::willDisplayCellForIndex(TableViewCell * cell, int index) { HistoryViewCell * myCell = (HistoryViewCell *)cell; myCell->setCalculation(m_calculationStore->calculationAtIndex(index)); } diff --git a/apps/calculation/history_controller.h b/apps/calculation/history_controller.h index a7b869ec1..fa9e0e414 100644 --- a/apps/calculation/history_controller.h +++ b/apps/calculation/history_controller.h @@ -22,9 +22,9 @@ public: void reload(); void setActiveCell(int index); int numberOfRows() override; - View * reusableCell(int index, int type) override; + TableViewCell * reusableCell(int index, int type) override; int reusableCellCount(int type) override; - void willDisplayCellForIndex(View * cell, int index) override; + void willDisplayCellForIndex(TableViewCell * cell, int index) override; KDCoordinate rowHeight(int j) override; KDCoordinate cumulatedHeightFromIndex(int j) override; int indexFromCumulatedHeight(KDCoordinate offsetY) override; diff --git a/apps/calculation/history_view_cell.cpp b/apps/calculation/history_view_cell.cpp index 93b6d41fc..fa27eaaf1 100644 --- a/apps/calculation/history_view_cell.cpp +++ b/apps/calculation/history_view_cell.cpp @@ -6,7 +6,6 @@ namespace Calculation { HistoryViewCell::HistoryViewCell() : m_calculation(nullptr), - m_highlighted(false), m_result(BufferTextView(1.0f, 0.5f)) { } @@ -39,16 +38,15 @@ void HistoryViewCell::setCalculation(Calculation * calculation) { m_result.setText(buffer); } -void HistoryViewCell::setHighlighted(bool highlight) { - m_highlighted = highlight; - KDColor backgroundColor = m_highlighted ? Palette::FocusCellBackgroundColor : Palette::CellBackgroundColor; +void HistoryViewCell::reloadCell() { + KDColor backgroundColor = isHighlighted() ? Palette::FocusCellBackgroundColor : Palette::CellBackgroundColor; m_result.setBackgroundColor(backgroundColor); - markRectAsDirty(bounds()); + TableViewCell::reloadCell(); } void HistoryViewCell::drawRect(KDContext * ctx, KDRect rect) const { // Select background color - KDColor backgroundColor = m_highlighted ? Palette::FocusCellBackgroundColor : Palette::CellBackgroundColor; + KDColor backgroundColor = isHighlighted() ? Palette::FocusCellBackgroundColor : Palette::CellBackgroundColor; ctx->fillRect(rect, backgroundColor); // Draw the pretty print if (m_calculation && m_calculation->layout() != nullptr) { diff --git a/apps/calculation/history_view_cell.h b/apps/calculation/history_view_cell.h index a12743801..0489ef8fd 100644 --- a/apps/calculation/history_view_cell.h +++ b/apps/calculation/history_view_cell.h @@ -6,19 +6,18 @@ namespace Calculation { -class HistoryViewCell : public View { +class HistoryViewCell : public TableViewCell { public: HistoryViewCell(); + void reloadCell() override; BufferTextView * result(); void setCalculation(Calculation * calculation); - void setHighlighted(bool highlight); void drawRect(KDContext * ctx, KDRect rect) const override; int numberOfSubviews() const override; View * subviewAtIndex(int index) override; void layoutSubviews() override; private: Calculation * m_calculation; - bool m_highlighted; BufferTextView m_result; }; diff --git a/apps/graph/even_odd_cell.cpp b/apps/graph/even_odd_cell.cpp index d8386d808..ffd590b9a 100644 --- a/apps/graph/even_odd_cell.cpp +++ b/apps/graph/even_odd_cell.cpp @@ -7,8 +7,7 @@ constexpr KDColor EvenOddCell::k_oddLineBackgroundColor; constexpr KDColor EvenOddCell::k_selectedLineBackgroundColor; EvenOddCell::EvenOddCell() : - View(), - m_highlighted(false), + TableViewCell(), m_even(false) { } @@ -18,23 +17,13 @@ void EvenOddCell::setEven(bool even) { reloadCell(); } -void EvenOddCell::setHighlighted(bool highlight) { - m_highlighted = highlight; - reloadCell(); -} - -void EvenOddCell::reloadCell() { - markRectAsDirty(bounds()); -} - KDColor EvenOddCell::backgroundColor() const { // Select the background color according to the even line and the cursor selection KDColor background = m_even ? EvenOddCell::k_evenLineBackgroundColor : EvenOddCell::k_oddLineBackgroundColor; - background = m_highlighted ? EvenOddCell::k_selectedLineBackgroundColor : background; + background = isHighlighted() ? EvenOddCell::k_selectedLineBackgroundColor : background; return background; } - void EvenOddCell::drawRect(KDContext * ctx, KDRect rect) const { KDColor background = backgroundColor(); ctx->fillRect(rect, background); diff --git a/apps/graph/even_odd_cell.h b/apps/graph/even_odd_cell.h index 286c6bc33..472b4a70e 100644 --- a/apps/graph/even_odd_cell.h +++ b/apps/graph/even_odd_cell.h @@ -5,12 +5,10 @@ namespace Graph { -class EvenOddCell : public View { +class EvenOddCell : public TableViewCell { public: EvenOddCell(); void setEven(bool even); - void setHighlighted(bool highlight); - virtual void reloadCell(); KDColor backgroundColor() const; void drawRect(KDContext * ctx, KDRect rect) const override; @@ -19,7 +17,6 @@ public: static constexpr KDColor k_selectedLineBackgroundColor = KDColor(0xC0D3EA); private: - bool m_highlighted; bool m_even; }; diff --git a/apps/graph/list/list_controller.cpp b/apps/graph/list/list_controller.cpp index 1b5e87f10..e1e9ccc69 100644 --- a/apps/graph/list/list_controller.cpp +++ b/apps/graph/list/list_controller.cpp @@ -235,7 +235,7 @@ int ListController::typeAtLocation(int i, int j) { return i; } -View * ListController::reusableCell(int index, int type) { +TableViewCell * ListController::reusableCell(int index, int type) { assert(index >= 0); assert(index < k_maxNumberOfRows); switch (type) { @@ -260,7 +260,7 @@ int ListController::reusableCellCount(int type) { return k_maxNumberOfRows; } -void ListController::willDisplayCellAtLocation(View * cell, int i, int j) { +void ListController::willDisplayCellAtLocation(TableViewCell * cell, int i, int j) { if (j < numberOfRows() - 1) { if (i == 0) { FunctionTitleCell * myFunctionCell = (FunctionTitleCell *)cell; diff --git a/apps/graph/list/list_controller.h b/apps/graph/list/list_controller.h index 94b426500..b6e7d7c10 100644 --- a/apps/graph/list/list_controller.h +++ b/apps/graph/list/list_controller.h @@ -23,14 +23,14 @@ public: int numberOfRows() override; int numberOfColumns() override; - void willDisplayCellAtLocation(View * cell, int i, int j) override; + void willDisplayCellAtLocation(TableViewCell * cell, int i, int j) override; 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; - View * reusableCell(int index, int type) override; + TableViewCell * reusableCell(int index, int type) override; int reusableCellCount(int type) override; int typeAtLocation(int i, int j) override; void configureFunction(Function * function); diff --git a/apps/graph/list/parameter_controller.cpp b/apps/graph/list/parameter_controller.cpp index 857655509..8776533f9 100644 --- a/apps/graph/list/parameter_controller.cpp +++ b/apps/graph/list/parameter_controller.cpp @@ -28,7 +28,7 @@ void ParameterController::didBecomeFirstResponder() { setActiveCell(0); } -void ParameterController::willDisplayCellForIndex(View * cell, int index) { +void ParameterController::willDisplayCellForIndex(TableViewCell * cell, int index) { if (cell == &m_enableCell) { SwitchView * switchView = (SwitchView *)m_enableCell.contentView(); switchView->setState(m_function->isActive()); @@ -105,10 +105,10 @@ int ParameterController::numberOfRows() { }; -View * ParameterController::reusableCell(int index) { +TableViewCell * ParameterController::reusableCell(int index) { assert(index >= 0); assert(index < k_totalNumberOfCell); - View * cells[] = {&m_colorCell, &m_enableCell, &m_deleteCell}; + TableViewCell * cells[] = {&m_colorCell, &m_enableCell, &m_deleteCell}; return cells[index]; } diff --git a/apps/graph/list/parameter_controller.h b/apps/graph/list/parameter_controller.h index 28db56f7e..52e833d35 100644 --- a/apps/graph/list/parameter_controller.h +++ b/apps/graph/list/parameter_controller.h @@ -20,9 +20,9 @@ public: void setActiveCell(int index); int numberOfRows() override; KDCoordinate cellHeight() override; - View * reusableCell(int index) override; + TableViewCell * reusableCell(int index) override; int reusableCellCount() override; - void willDisplayCellForIndex(View * cell, int index) override; + void willDisplayCellForIndex(TableViewCell * cell, int index) override; private: bool handleEnter(); constexpr static int k_totalNumberOfCell = 3; diff --git a/apps/graph/values/abscissa_parameter_controller.cpp b/apps/graph/values/abscissa_parameter_controller.cpp index 728ce31b7..1be5103ab 100644 --- a/apps/graph/values/abscissa_parameter_controller.cpp +++ b/apps/graph/values/abscissa_parameter_controller.cpp @@ -85,10 +85,10 @@ int AbscissaParameterController::numberOfRows() { return k_totalNumberOfCell; }; -View * AbscissaParameterController::reusableCell(int index) { +TableViewCell * AbscissaParameterController::reusableCell(int index) { assert(index >= 0); assert(index < k_totalNumberOfCell); - View * cells[] = {&m_deleteColumn, &m_copyColumn, &m_setInterval}; + TableViewCell * cells[] = {&m_deleteColumn, &m_copyColumn, &m_setInterval}; return cells[index]; } diff --git a/apps/graph/values/abscissa_parameter_controller.h b/apps/graph/values/abscissa_parameter_controller.h index 72f31a27e..419727f92 100644 --- a/apps/graph/values/abscissa_parameter_controller.h +++ b/apps/graph/values/abscissa_parameter_controller.h @@ -17,7 +17,7 @@ public: void setActiveCell(int index); int numberOfRows() override; KDCoordinate cellHeight() override; - View * reusableCell(int index) override; + TableViewCell * reusableCell(int index) override; int reusableCellCount() override; private: bool handleEnter(); diff --git a/apps/graph/values/derivative_parameter_controller.cpp b/apps/graph/values/derivative_parameter_controller.cpp index 80fc0eb6b..c9edd28e7 100644 --- a/apps/graph/values/derivative_parameter_controller.cpp +++ b/apps/graph/values/derivative_parameter_controller.cpp @@ -87,10 +87,10 @@ int DerivativeParameterController::numberOfRows() { return k_totalNumberOfCell; }; -View * DerivativeParameterController::reusableCell(int index) { +TableViewCell * DerivativeParameterController::reusableCell(int index) { assert(index >= 0); assert(index < k_totalNumberOfCell); - View * cells[] = {&m_hideColumn, &m_copyColumn}; + TableViewCell * cells[] = {&m_hideColumn, &m_copyColumn}; return cells[index]; } diff --git a/apps/graph/values/derivative_parameter_controller.h b/apps/graph/values/derivative_parameter_controller.h index bb28349c3..a702fe5fc 100644 --- a/apps/graph/values/derivative_parameter_controller.h +++ b/apps/graph/values/derivative_parameter_controller.h @@ -17,7 +17,7 @@ public: void setActiveCell(int index); int numberOfRows() override; KDCoordinate cellHeight() override; - View * reusableCell(int index) override; + TableViewCell * reusableCell(int index) override; int reusableCellCount() override; void setFunction(Function * function); diff --git a/apps/graph/values/function_parameter_controller.cpp b/apps/graph/values/function_parameter_controller.cpp index 93f9d9166..9f80dcb3a 100644 --- a/apps/graph/values/function_parameter_controller.cpp +++ b/apps/graph/values/function_parameter_controller.cpp @@ -86,10 +86,10 @@ int FunctionParameterController::numberOfRows() { return k_totalNumberOfCell; }; -View * FunctionParameterController::reusableCell(int index) { +TableViewCell * FunctionParameterController::reusableCell(int index) { assert(index >= 0); assert(index < k_totalNumberOfCell); - View * cells[] = {&m_displayDerivativeColumn, &m_copyColumn}; + TableViewCell * cells[] = {&m_displayDerivativeColumn, &m_copyColumn}; return cells[index]; } @@ -101,7 +101,7 @@ KDCoordinate FunctionParameterController::cellHeight() { return 35; } -void FunctionParameterController::willDisplayCellForIndex(View * cell, int index) { +void FunctionParameterController::willDisplayCellForIndex(TableViewCell * cell, int index) { if (cell == &m_displayDerivativeColumn) { SwitchView * switchView = (SwitchView *)m_displayDerivativeColumn.contentView(); switchView->setState(m_function->displayDerivative()); diff --git a/apps/graph/values/function_parameter_controller.h b/apps/graph/values/function_parameter_controller.h index 65759c568..30571e2a0 100644 --- a/apps/graph/values/function_parameter_controller.h +++ b/apps/graph/values/function_parameter_controller.h @@ -17,9 +17,9 @@ public: void setActiveCell(int index); int numberOfRows() override; KDCoordinate cellHeight() override; - View * reusableCell(int index) override; + TableViewCell * reusableCell(int index) override; int reusableCellCount() override; - void willDisplayCellForIndex(View * cell, int index) override; + void willDisplayCellForIndex(TableViewCell * cell, int index) override; void setFunction(Function * function); private: diff --git a/apps/graph/values/values_controller.cpp b/apps/graph/values/values_controller.cpp index d887b948d..6f7a2b7d2 100644 --- a/apps/graph/values/values_controller.cpp +++ b/apps/graph/values/values_controller.cpp @@ -341,7 +341,7 @@ int ValuesController::typeAtLocation(int i, int j) { return 2; } -View * ValuesController::reusableCell(int index, int type) { +TableViewCell * ValuesController::reusableCell(int index, int type) { assert(index >= 0); switch (type) { case 0: @@ -373,7 +373,7 @@ int ValuesController::reusableCellCount(int type) { } } -void ValuesController::willDisplayCellAtLocation(View * cell, int i, int j) { +void ValuesController::willDisplayCellAtLocation(TableViewCell * cell, int i, int j) { EvenOddCell * myCell = (EvenOddCell *)cell; myCell->setEven(j%2 == 0); // The cell is a title cell: diff --git a/apps/graph/values/values_controller.h b/apps/graph/values/values_controller.h index c4b90c8b3..8a111cfaf 100644 --- a/apps/graph/values/values_controller.h +++ b/apps/graph/values/values_controller.h @@ -35,14 +35,14 @@ public: int numberOfRows() override; int numberOfColumns() override; - void willDisplayCellAtLocation(View * cell, int i, int j) override; + void willDisplayCellAtLocation(TableViewCell * cell, int i, int j) override; 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; - View * reusableCell(int index, int type) override; + TableViewCell * reusableCell(int index, int type) override; int reusableCellCount(int type) override; int typeAtLocation(int i, int j) override; diff --git a/apps/graph/values/values_parameter_controller.cpp b/apps/graph/values/values_parameter_controller.cpp index 4981cff77..5ec1eda2d 100644 --- a/apps/graph/values/values_parameter_controller.cpp +++ b/apps/graph/values/values_parameter_controller.cpp @@ -36,7 +36,7 @@ int ValuesParameterController::activeCell() { return m_activeCell; } -void ValuesParameterController::willDisplayCellForIndex(View * cell, int index) { +void ValuesParameterController::willDisplayCellForIndex(TableViewCell * cell, int index) { TextListViewCell * myCell = (TextListViewCell *) cell; char buffer[14]; switch (index) { @@ -142,10 +142,10 @@ int ValuesParameterController::numberOfRows() { return k_totalNumberOfCell; }; -View * ValuesParameterController::reusableCell(int index) { +TableViewCell * ValuesParameterController::reusableCell(int index) { assert(index >= 0); assert(index < k_totalNumberOfCell); - View * cells[] = {&m_intervalStartCell, &m_intervalEndCell, &m_intervalStepCell}; + TableViewCell * cells[] = {&m_intervalStartCell, &m_intervalEndCell, &m_intervalStepCell}; return cells[index]; } diff --git a/apps/graph/values/values_parameter_controller.h b/apps/graph/values/values_parameter_controller.h index d02f3d10a..d8c4e9baf 100644 --- a/apps/graph/values/values_parameter_controller.h +++ b/apps/graph/values/values_parameter_controller.h @@ -21,9 +21,9 @@ public: void setActiveCell(int index); int numberOfRows() override; KDCoordinate cellHeight() override; - View * reusableCell(int index) override; + TableViewCell * reusableCell(int index) override; int reusableCellCount() override; - void willDisplayCellForIndex(View * cell, int index) override; + void willDisplayCellForIndex(TableViewCell * cell, int index) override; private: constexpr static int k_totalNumberOfCell = 3; Interval * m_interval; diff --git a/apps/home/app_cell.cpp b/apps/home/app_cell.cpp index 76342fec5..c02ac0f11 100644 --- a/apps/home/app_cell.cpp +++ b/apps/home/app_cell.cpp @@ -4,9 +4,8 @@ namespace Home { AppCell::AppCell() : - View(), - m_visible(true), - m_active(false) + TableViewCell(), + m_visible(true) { } @@ -38,13 +37,9 @@ void AppCell::setVisible(bool visible) { } } -void AppCell::setActive(bool active) { - if (m_active != active) { - m_active = active; - m_nameView.setBackgroundColor(m_active ? KDColorRed : KDColorWhite); - - markRectAsDirty(bounds()); - } +void AppCell::reloadCell() { + TableViewCell::reloadCell(); + m_nameView.setBackgroundColor(isHighlighted() ? KDColorRed : KDColorWhite); } } diff --git a/apps/home/app_cell.h b/apps/home/app_cell.h index 8800c7727..c8b1da3e6 100644 --- a/apps/home/app_cell.h +++ b/apps/home/app_cell.h @@ -5,7 +5,7 @@ namespace Home { -class AppCell : public View { +class AppCell : public TableViewCell { public: AppCell(); @@ -14,14 +14,13 @@ public: void layoutSubviews() override; void setVisible(bool visible); - void setActive(bool active); + void reloadCell() override; void setApp(::App * app); private: static constexpr KDCoordinate k_iconSize = 32; ImageView m_iconView; PointerTextView m_nameView; bool m_visible; - bool m_active; }; } diff --git a/apps/home/controller.cpp b/apps/home/controller.cpp index 672f5d209..4b8a568b5 100644 --- a/apps/home/controller.cpp +++ b/apps/home/controller.cpp @@ -69,7 +69,7 @@ KDCoordinate Controller::cellWidth() { return 50; } -View * Controller::reusableCell(int index) { +TableViewCell * Controller::reusableCell(int index) { return &m_cells[index]; } @@ -77,7 +77,7 @@ int Controller::reusableCellCount() { return k_maxNumberOfCells; } -void Controller::willDisplayCellAtLocation(View * cell, int i, int j) { +void Controller::willDisplayCellAtLocation(TableViewCell * cell, int i, int j) { AppCell * appCell = (AppCell *)cell; int appIndex = (j*k_numberOfColumns+i)+1; if (appIndex >= m_container->numberOfApps()) { @@ -102,14 +102,14 @@ void Controller::setActiveIndex(int index) { int j = m_activeIndex/k_numberOfColumns; int i = m_activeIndex-j*k_numberOfColumns; // Avoid modulo AppCell * previousCell = (AppCell *)m_tableView.cellAtLocation(i, j); - previousCell->setActive(false); + previousCell->setHighlighted(false); m_activeIndex = index; j = m_activeIndex/k_numberOfColumns; i = m_activeIndex-j*k_numberOfColumns; // Avoid modulo AppCell * nextCell = (AppCell *)m_tableView.cellAtLocation(i, j); - nextCell->setActive(true); + nextCell->setHighlighted(true); } diff --git a/apps/home/controller.h b/apps/home/controller.h index 20670318c..2c868a523 100644 --- a/apps/home/controller.h +++ b/apps/home/controller.h @@ -21,9 +21,9 @@ public: virtual int numberOfColumns() override; virtual KDCoordinate cellHeight() override; virtual KDCoordinate cellWidth() override; - virtual View * reusableCell(int index) override; + virtual TableViewCell * reusableCell(int index) override; virtual int reusableCellCount() override; - void willDisplayCellAtLocation(View * cell, int i, int j) override; + void willDisplayCellAtLocation(TableViewCell * cell, int i, int j) override; private: int numberOfIcons(); void setActiveIndex(int index); diff --git a/apps/probability/law/law_controller.cpp b/apps/probability/law/law_controller.cpp index b5a26d9eb..f3374e940 100644 --- a/apps/probability/law/law_controller.cpp +++ b/apps/probability/law/law_controller.cpp @@ -66,7 +66,7 @@ int Probability::LawController::numberOfRows() { return k_totalNumberOfModels; }; -View * Probability::LawController::reusableCell(int index) { +TableViewCell * Probability::LawController::reusableCell(int index) { assert(index >= 0); assert(index < k_maxNumberOfCells); return &m_cells[index]; @@ -76,7 +76,7 @@ int Probability::LawController::reusableCellCount() { return k_maxNumberOfCells; } -void Probability::LawController::willDisplayCellForIndex(View * cell, int index) { +void Probability::LawController::willDisplayCellForIndex(TableViewCell * cell, int index) { ListViewCell * myCell = (ListViewCell *)cell; myCell->textView()->setText(m_messages[index]); if (m_activeCell == index) { diff --git a/apps/probability/law/law_controller.h b/apps/probability/law/law_controller.h index 6ee06c5c0..e08b61081 100644 --- a/apps/probability/law/law_controller.h +++ b/apps/probability/law/law_controller.h @@ -17,9 +17,9 @@ public: void didBecomeFirstResponder() override; int numberOfRows() override; - void willDisplayCellForIndex(View * cell, int index) override; + void willDisplayCellForIndex(TableViewCell * cell, int index) override; KDCoordinate cellHeight() override; - View * reusableCell(int index) override; + TableViewCell * reusableCell(int index) override; int reusableCellCount() override; private: constexpr static int k_totalNumberOfModels = 7; diff --git a/escher/Makefile b/escher/Makefile index b6a44662c..7bae469b0 100644 --- a/escher/Makefile +++ b/escher/Makefile @@ -28,6 +28,7 @@ objs += $(addprefix escher/src/,\ tab_view_cell.o\ tab_view_controller.o\ table_view.o\ + table_view_cell.o\ list_view_cell.o\ table_view_data_source.o\ text_field.o\ diff --git a/escher/include/escher.h b/escher/include/escher.h index 3d5b138a9..37c7a2f36 100644 --- a/escher/include/escher.h +++ b/escher/include/escher.h @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -29,7 +30,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/escher/include/escher/list_view_cell.h b/escher/include/escher/list_view_cell.h index 01c0c88b1..5fcda321b 100644 --- a/escher/include/escher/list_view_cell.h +++ b/escher/include/escher/list_view_cell.h @@ -5,23 +5,20 @@ #include #include #include +#include - -class ListViewCell : public View { +class ListViewCell : public TableViewCell { public: ListViewCell(char * label = nullptr); PointerTextView * textView(); virtual View * contentView() const; - bool isHighlighted() const; - void setHighlighted(bool highlight); void drawRect(KDContext * ctx, KDRect rect) const override; - + void reloadCell() override; int numberOfSubviews() const override; View * subviewAtIndex(int index) override; void layoutSubviews() override; private: constexpr static KDCoordinate k_separatorThickness = 1; - bool m_highlighted; PointerTextView m_pointerTextView; }; diff --git a/escher/include/escher/list_view_data_source.h b/escher/include/escher/list_view_data_source.h index 3a1f68bef..7ddb9388b 100644 --- a/escher/include/escher/list_view_data_source.h +++ b/escher/include/escher/list_view_data_source.h @@ -2,16 +2,17 @@ #define ESCHER_LIST_VIEW_DATA_SOURCE_H #include +#include class ListViewDataSource : public TableViewDataSource { public: KDCoordinate cellWidth(); KDCoordinate columnWidth(int i) override; int numberOfColumns() override; - void willDisplayCellAtLocation(View * cell, int x, int y) override; + void willDisplayCellAtLocation(TableViewCell * cell, int x, int y) override; int indexFromCumulatedWidth(KDCoordinate offsetX) override; KDCoordinate cumulatedWidthFromIndex(int i) override; - virtual void willDisplayCellForIndex(View * cell, int index); + virtual void willDisplayCellForIndex(TableViewCell * cell, int index); }; #endif \ No newline at end of file diff --git a/escher/include/escher/simple_list_view_data_source.h b/escher/include/escher/simple_list_view_data_source.h index e7ecbb164..11f3b3a17 100644 --- a/escher/include/escher/simple_list_view_data_source.h +++ b/escher/include/escher/simple_list_view_data_source.h @@ -2,6 +2,7 @@ #define ESCHER_SIMPLE_LIST_VIEW_DATA_SOURCE_H #include +#include class SimpleListViewDataSource : public ListViewDataSource { public: @@ -9,9 +10,9 @@ public: KDCoordinate rowHeight(int j) override; KDCoordinate cumulatedHeightFromIndex(int j) override; int indexFromCumulatedHeight(KDCoordinate offsetY) override; - virtual View * reusableCell(int index) = 0; + virtual TableViewCell * reusableCell(int index) = 0; virtual int reusableCellCount() = 0; - View * reusableCell(int index, int type) override; + TableViewCell * reusableCell(int index, int type) override; int reusableCellCount(int type) override; int typeAtLocation(int i, int j) override; }; diff --git a/escher/include/escher/simple_table_view_data_source.h b/escher/include/escher/simple_table_view_data_source.h index ae9257183..932dd3b4b 100644 --- a/escher/include/escher/simple_table_view_data_source.h +++ b/escher/include/escher/simple_table_view_data_source.h @@ -2,6 +2,7 @@ #define ESCHER_SIMPLE_TABLE_VIEW_DATA_SOURCE_H #include +#include class SimpleTableViewDataSource : public TableViewDataSource { public: @@ -13,9 +14,9 @@ public: KDCoordinate cumulatedHeightFromIndex(int j) override; int indexFromCumulatedWidth(KDCoordinate offsetX) override; int indexFromCumulatedHeight(KDCoordinate offsetY) override; - virtual View * reusableCell(int index) = 0; + virtual TableViewCell * reusableCell(int index) = 0; virtual int reusableCellCount() = 0; - View * reusableCell(int index, int type) override; + TableViewCell * reusableCell(int index, int type) override; int reusableCellCount(int type) override; int typeAtLocation(int i, int j) override; }; diff --git a/escher/include/escher/table_view.h b/escher/include/escher/table_view.h index 7d7114035..23573abac 100644 --- a/escher/include/escher/table_view.h +++ b/escher/include/escher/table_view.h @@ -2,6 +2,7 @@ #define ESCHER_TABLE_VIEW_H #include +#include #include class TableView : public ScrollView { @@ -10,7 +11,7 @@ public: KDCoordinate rightMargin = 0, KDCoordinate bottomMargin = 0, KDCoordinate leftMargin = 0); void scrollToCell(int i, int j); - View * cellAtLocation(int i, int j); + TableViewCell * cellAtLocation(int i, int j); void reloadData(); protected: #if ESCHER_VIEW_LOGGING @@ -22,7 +23,7 @@ private: ContentView(TableView * tableView, TableViewDataSource * dataSource); void scrollToCell(int i, int j) const; - View * cellAtLocation(int i, int j); + TableViewCell * cellAtLocation(int i, int j); void resizeToFitContent(); protected: #if ESCHER_VIEW_LOGGING diff --git a/escher/include/escher/table_view_cell.h b/escher/include/escher/table_view_cell.h new file mode 100644 index 000000000..a78f3f948 --- /dev/null +++ b/escher/include/escher/table_view_cell.h @@ -0,0 +1,16 @@ +#ifndef ESCHER_TABLE_VIEW_CELL_H +#define ESCHER_TABLE_VIEW_CELL_H + +#include + +class TableViewCell : public View { +public: + TableViewCell(); + void setHighlighted(bool highlight); + bool isHighlighted() const; + virtual void reloadCell(); +private: + bool m_highlighted; +}; + +#endif diff --git a/escher/include/escher/table_view_data_source.h b/escher/include/escher/table_view_data_source.h index 62dcffc2a..4ae620a27 100644 --- a/escher/include/escher/table_view_data_source.h +++ b/escher/include/escher/table_view_data_source.h @@ -2,12 +2,13 @@ #define ESCHER_TABLE_VIEW_DATA_SOURCE_H #include +#include class TableViewDataSource { public: virtual int numberOfRows() = 0; virtual int numberOfColumns() = 0; - virtual void willDisplayCellAtLocation(View * cell, int i, int j); + virtual void willDisplayCellAtLocation(TableViewCell * 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 @@ -20,7 +21,7 @@ public: * returns n-1. */ virtual int indexFromCumulatedWidth(KDCoordinate offsetX) = 0; virtual int indexFromCumulatedHeight(KDCoordinate offsetY) = 0; - virtual View * reusableCell(int index, int type) = 0; + virtual TableViewCell * reusableCell(int index, int type) = 0; virtual int reusableCellCount(int type) = 0; virtual int typeAtLocation(int i, int j) = 0; }; diff --git a/escher/src/list_view_cell.cpp b/escher/src/list_view_cell.cpp index b7dce4064..372eb1178 100644 --- a/escher/src/list_view_cell.cpp +++ b/escher/src/list_view_cell.cpp @@ -4,8 +4,7 @@ constexpr KDCoordinate ListViewCell::k_separatorThickness; ListViewCell::ListViewCell(char * label) : - View(), - m_highlighted(false), + TableViewCell(), m_pointerTextView(PointerTextView(label, 0, 0.5, KDColorBlack, Palette::CellBackgroundColor)) { } @@ -36,6 +35,12 @@ void ListViewCell::layoutSubviews() { } } +void ListViewCell::reloadCell() { + TableViewCell::reloadCell(); + KDColor backgroundColor = isHighlighted()? Palette::FocusCellBackgroundColor : Palette::CellBackgroundColor; + m_pointerTextView.setBackgroundColor(backgroundColor); +} + PointerTextView * ListViewCell::textView() { return &m_pointerTextView; } @@ -44,21 +49,10 @@ View * ListViewCell::contentView() const { return nullptr; } -bool ListViewCell::isHighlighted() const { - return m_highlighted; -} - -void ListViewCell::setHighlighted(bool highlight) { - m_highlighted = highlight; - KDColor backgroundColor = highlight? Palette::FocusCellBackgroundColor : Palette::CellBackgroundColor; - m_pointerTextView.setBackgroundColor(backgroundColor); - markRectAsDirty(bounds()); -} - void ListViewCell::drawRect(KDContext * ctx, KDRect rect) const { KDCoordinate width = bounds().width(); KDCoordinate height = bounds().height(); - KDColor backgroundColor = (m_highlighted ? Palette::FocusCellBackgroundColor : Palette::CellBackgroundColor); + KDColor backgroundColor = isHighlighted() ? Palette::FocusCellBackgroundColor : Palette::CellBackgroundColor; ctx->fillRect(KDRect(k_separatorThickness, k_separatorThickness, width-2*k_separatorThickness, height-k_separatorThickness), backgroundColor); ctx->fillRect(KDRect(0, 0, width, k_separatorThickness), Palette::LineColor); diff --git a/escher/src/list_view_data_source.cpp b/escher/src/list_view_data_source.cpp index 486b15534..62fea532d 100644 --- a/escher/src/list_view_data_source.cpp +++ b/escher/src/list_view_data_source.cpp @@ -12,11 +12,11 @@ int ListViewDataSource::numberOfColumns() { return 1; } -void ListViewDataSource::willDisplayCellAtLocation(View * cell, int x, int y) { +void ListViewDataSource::willDisplayCellAtLocation(TableViewCell * cell, int x, int y) { willDisplayCellForIndex(cell, y); } -void ListViewDataSource::willDisplayCellForIndex(View * cell, int index) { +void ListViewDataSource::willDisplayCellForIndex(TableViewCell * cell, int index) { } KDCoordinate ListViewDataSource::cumulatedWidthFromIndex(int i) { diff --git a/escher/src/simple_list_view_data_source.cpp b/escher/src/simple_list_view_data_source.cpp index cdf51e813..365de19c7 100644 --- a/escher/src/simple_list_view_data_source.cpp +++ b/escher/src/simple_list_view_data_source.cpp @@ -17,7 +17,7 @@ int SimpleListViewDataSource::indexFromCumulatedHeight(KDCoordinate offsetY) { return (offsetY - 1) / height; } -View * SimpleListViewDataSource::reusableCell(int index, int type) { +TableViewCell * SimpleListViewDataSource::reusableCell(int index, int type) { assert(type == 0); return reusableCell(index); } diff --git a/escher/src/simple_table_view_data_source.cpp b/escher/src/simple_table_view_data_source.cpp index d7a8f33e3..0c6b820cb 100644 --- a/escher/src/simple_table_view_data_source.cpp +++ b/escher/src/simple_table_view_data_source.cpp @@ -37,7 +37,7 @@ int SimpleTableViewDataSource::indexFromCumulatedHeight(KDCoordinate offsetY) { return (offsetY - 1) / height; } -View * SimpleTableViewDataSource::reusableCell(int index, int type) { +TableViewCell * SimpleTableViewDataSource::reusableCell(int index, int type) { assert(type == 0); return reusableCell(index); } diff --git a/escher/src/table_view.cpp b/escher/src/table_view.cpp index 907a337b7..204d4f65c 100644 --- a/escher/src/table_view.cpp +++ b/escher/src/table_view.cpp @@ -20,7 +20,7 @@ void TableView::scrollToCell(int i, int j) { m_contentView.scrollToCell(i, j); } -View * TableView::cellAtLocation(int i, int j) { +TableViewCell * TableView::cellAtLocation(int i, int j) { return m_contentView.cellAtLocation(i, j); } @@ -112,7 +112,7 @@ int TableView::ContentView::typeIndexFromSubviewIndex(int index, int type) const return typeIndex; } -View * TableView::ContentView::cellAtLocation(int x, int y) { +TableViewCell * TableView::ContentView::cellAtLocation(int x, int y) { int relativeX = x-columnsScrollingOffset(); int relativeY = y-rowsScrollingOffset(); int type = m_dataSource->typeAtLocation(x, y); @@ -168,7 +168,7 @@ void TableView::ContentView::layoutSubviews() { cell->setFrame(cellFrame); - m_dataSource->willDisplayCellAtLocation(cell, i, j); + m_dataSource->willDisplayCellAtLocation((TableViewCell *)cell, i, j); } } diff --git a/escher/src/table_view_cell.cpp b/escher/src/table_view_cell.cpp new file mode 100644 index 000000000..e3d54edfe --- /dev/null +++ b/escher/src/table_view_cell.cpp @@ -0,0 +1,20 @@ +#include + +TableViewCell::TableViewCell() : + View(), + m_highlighted(false) +{ +} + +void TableViewCell::setHighlighted(bool highlight) { + m_highlighted = highlight; + reloadCell(); +} + +bool TableViewCell::isHighlighted() const { + return m_highlighted; +} + +void TableViewCell::reloadCell() { + markRectAsDirty(bounds()); +} diff --git a/escher/src/table_view_data_source.cpp b/escher/src/table_view_data_source.cpp index eb728bff9..c38f1a960 100644 --- a/escher/src/table_view_data_source.cpp +++ b/escher/src/table_view_data_source.cpp @@ -1,4 +1,4 @@ #include -void TableViewDataSource::willDisplayCellAtLocation(View * cell, int i, int j) { +void TableViewDataSource::willDisplayCellAtLocation(TableViewCell * cell, int i, int j) { }