From c93e02104503aba0c38480913e0752207aa3e07d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Tue, 12 Mar 2019 13:31:13 +0100 Subject: [PATCH] [apps/graph][apps/sequence] ListParameterController is a ListViewDataSource instead of a SimpleListViewDataSource (indeed, each cell has a specific type) --- apps/graph/list/list_parameter_controller.cpp | 8 +-- apps/graph/list/list_parameter_controller.h | 3 +- .../list/list_parameter_controller.cpp | 64 +++++++++---------- .../sequence/list/list_parameter_controller.h | 6 +- apps/shared/list_parameter_controller.cpp | 18 +++++- apps/shared/list_parameter_controller.h | 13 ++-- 6 files changed, 66 insertions(+), 46 deletions(-) diff --git a/apps/graph/list/list_parameter_controller.cpp b/apps/graph/list/list_parameter_controller.cpp index 29e1bf442..411fcff3d 100644 --- a/apps/graph/list/list_parameter_controller.cpp +++ b/apps/graph/list/list_parameter_controller.cpp @@ -6,11 +6,11 @@ using namespace Shared; namespace Graph { -HighlightCell * ListParameterController::reusableCell(int index) { - if (index == 0) { +HighlightCell * ListParameterController::reusableCell(int index, int type) { + if (type == 0) { return &m_renameCell; } - return ListParameterController::reusableCell(index -1); + return Shared::ListParameterController::reusableCell(index, type - 1); } bool ListParameterController::handleEnterOnRow(int rowIndex) { @@ -18,7 +18,7 @@ bool ListParameterController::handleEnterOnRow(int rowIndex) { renameFunction(); return true; } - return ListParameterController::handleEnterOnRow(rowIndex-1); + return Shared::ListParameterController::handleEnterOnRow(rowIndex-1); } void ListParameterController::renameFunction() { diff --git a/apps/graph/list/list_parameter_controller.h b/apps/graph/list/list_parameter_controller.h index ac127169f..21d41e376 100644 --- a/apps/graph/list/list_parameter_controller.h +++ b/apps/graph/list/list_parameter_controller.h @@ -14,7 +14,8 @@ public: m_listController(listController), m_renameCell(I18n::Message::Rename) {} - HighlightCell * reusableCell(int index) override; + // ListViewDataSource + HighlightCell * reusableCell(int index, int type) override; protected: bool handleEnterOnRow(int rowIndex) override; private: diff --git a/apps/sequence/list/list_parameter_controller.cpp b/apps/sequence/list/list_parameter_controller.cpp index b8b927402..cc0f25fcf 100644 --- a/apps/sequence/list/list_parameter_controller.cpp +++ b/apps/sequence/list/list_parameter_controller.cpp @@ -64,38 +64,6 @@ bool ListParameterController::handleEvent(Ion::Events::Event event) { return false; } -HighlightCell * ListParameterController::reusableCell(int index) { - switch (index) { - /*case 0: - return Shared::ListParameterController::reusableCell(index);*/ - case 0://1: - return &m_typeCell; - case 1: - if (hasInitialRankRow()) { - return &m_initialRankCell; - } - default: - return Shared::ListParameterController::reusableCell(index-1-hasInitialRankRow()); - } -} - -void ListParameterController::willDisplayCellForIndex(HighlightCell * cell, int index) { - cell->setHighlighted(index == selectedRow()); // See FIXME in SelectableTableView::reloadData() - Shared::ListParameterController::willDisplayCellForIndex(cell, index); - if (cell == &m_typeCell && !m_record.isNull()) { - m_typeCell.setLayout(sequence()->definitionName()); - } - if (cell == &m_initialRankCell && !m_record.isNull()) { - MessageTableCellWithEditableText * myCell = (MessageTableCellWithEditableText *) cell; - if (myCell->isEditing()) { - return; - } - char buffer[Sequence::k_initialRankNumberOfDigits+1]; - Poincare::Integer(sequence()->initialRank()).serialize(buffer, Sequence::k_initialRankNumberOfDigits+1); - myCell->setAccessoryText(buffer); - } -} - bool ListParameterController::textFieldShouldFinishEditing(TextField * textField, Ion::Events::Event event) { return event == Ion::Events::Down || event == Ion::Events::Up || TextFieldDelegate::textFieldShouldFinishEditing(textField, event); } @@ -152,6 +120,38 @@ void ListParameterController::tableViewDidChangeSelection(SelectableTableView * } } +HighlightCell * ListParameterController::reusableCell(int index, int type) { + switch (type) { + /*case 0: + return Shared::ListParameterController::reusableCell(index);*/ + case 0://1: + return &m_typeCell; + case 1: + if (hasInitialRankRow()) { + return &m_initialRankCell; + } + default: + return Shared::ListParameterController::reusableCell(index, type-1-hasInitialRankRow()); + } +} + +void ListParameterController::willDisplayCellForIndex(HighlightCell * cell, int index) { + cell->setHighlighted(index == selectedRow()); // See FIXME in SelectableTableView::reloadData() + Shared::ListParameterController::willDisplayCellForIndex(cell, index); + if (cell == &m_typeCell && !m_record.isNull()) { + m_typeCell.setLayout(sequence()->definitionName()); + } + if (cell == &m_initialRankCell && !m_record.isNull()) { + MessageTableCellWithEditableText * myCell = (MessageTableCellWithEditableText *) cell; + if (myCell->isEditing()) { + return; + } + char buffer[Sequence::k_initialRankNumberOfDigits+1]; + Poincare::Integer(sequence()->initialRank()).serialize(buffer, Sequence::k_initialRankNumberOfDigits+1); + myCell->setAccessoryText(buffer); + } +} + TextFieldDelegateApp * ListParameterController::textFieldDelegateApp() { return (TextFieldDelegateApp *)app(); } diff --git a/apps/sequence/list/list_parameter_controller.h b/apps/sequence/list/list_parameter_controller.h index f7a7d5eaa..09ff8c4cd 100644 --- a/apps/sequence/list/list_parameter_controller.h +++ b/apps/sequence/list/list_parameter_controller.h @@ -16,13 +16,15 @@ public: ListParameterController(::InputEventHandlerDelegate * inputEventHandlerDelegate, ListController * list); const char * title() override; bool handleEvent(Ion::Events::Event event) override; - HighlightCell * reusableCell(int index) override; - void willDisplayCellForIndex(HighlightCell * cell, int index) override; bool textFieldShouldFinishEditing(TextField * textField, Ion::Events::Event event) override; bool textFieldDidFinishEditing(TextField * textField, const char * text, Ion::Events::Event event) override; void tableViewDidChangeSelection(SelectableTableView * t, int previousSelectedCellX, int previousSelectedCellY) override; Shared::TextFieldDelegateApp * textFieldDelegateApp() override; + + // ListViewDataSource + HighlightCell * reusableCell(int index, int type) override; + void willDisplayCellForIndex(HighlightCell * cell, int index) override; private: #if FUNCTION_COLOR_CHOICE constexpr static int k_totalNumberOfCell = 5; diff --git a/apps/shared/list_parameter_controller.cpp b/apps/shared/list_parameter_controller.cpp index 62f988d50..a968b0ce2 100644 --- a/apps/shared/list_parameter_controller.cpp +++ b/apps/shared/list_parameter_controller.cpp @@ -53,15 +53,27 @@ bool ListParameterController::handleEvent(Ion::Events::Event event) { return false; } -HighlightCell * ListParameterController::reusableCell(int index) { - assert(index >= 0); +KDCoordinate ListParameterController::cumulatedHeightFromIndex(int j) { + return Metric::ParameterCellHeight * j; +} + +int ListParameterController::indexFromCumulatedHeight(KDCoordinate offsetY) { + return (offsetY - 1) / Metric::ParameterCellHeight; +} + +HighlightCell * ListParameterController::reusableCell(int index, int type) { + assert(index == 0); assert(index < totalNumberOfCells()); #if FUNCTION_COLOR_CHOICE HighlightCell * cells[] = {&m_colorCell, &m_enableCell, &m_deleteCell}; #else HighlightCell * cells[] = {&m_enableCell, &m_deleteCell}; #endif - return cells[index]; + return cells[type]; +} + +int ListParameterController::typeAtLocation(int i, int j) { + return j; } bool ListParameterController::handleEnterOnRow(int rowIndex) { diff --git a/apps/shared/list_parameter_controller.h b/apps/shared/list_parameter_controller.h index ea2992089..5202e8cff 100644 --- a/apps/shared/list_parameter_controller.h +++ b/apps/shared/list_parameter_controller.h @@ -7,7 +7,7 @@ namespace Shared { -class ListParameterController : public ViewController, public SimpleListViewDataSource, public SelectableTableViewDataSource { +class ListParameterController : public ViewController, public ListViewDataSource, public SelectableTableViewDataSource { public: ListParameterController(Responder * parentResponder, I18n::Message functionColorMessage, I18n::Message deleteFunctionMessage, SelectableTableViewDelegate * tableDelegate = nullptr); @@ -18,9 +18,14 @@ public: void didBecomeFirstResponder() override; void viewWillAppear() override; int numberOfRows() override { return totalNumberOfCells(); } - KDCoordinate cellHeight() override { return Metric::ParameterCellHeight; } - HighlightCell * reusableCell(int index) override; - int reusableCellCount() override { return totalNumberOfCells(); } + + // ListViewDataSource + KDCoordinate rowHeight(int j) override { return Metric::ParameterCellHeight; } + KDCoordinate cumulatedHeightFromIndex(int j) override; + int indexFromCumulatedHeight(KDCoordinate offsetY) override; + HighlightCell * reusableCell(int index, int type) override; + int reusableCellCount(int type) override { return 1; } + int typeAtLocation(int i, int j) override; void willDisplayCellForIndex(HighlightCell * cell, int index) override; protected: virtual bool handleEnterOnRow(int rowIndex);