diff --git a/apps/graph/values/values_controller.cpp b/apps/graph/values/values_controller.cpp index f9364f4eb..4b48c1e56 100644 --- a/apps/graph/values/values_controller.cpp +++ b/apps/graph/values/values_controller.cpp @@ -16,6 +16,10 @@ ValuesController::ValuesController(Responder * parentResponder, CartesianFunctio m_intervalParameterController(this, m_interval), m_derivativeParameterController(this) { + for (int i = 0; i < k_maxNumberOfFunctions; i++) { + m_functionTitleCells[i].setOrientation(FunctionTitleCell::Orientation::HorizontalIndicator); + m_functionTitleCells[i].setFontSize(KDText::FontSize::Small); + } } bool ValuesController::handleEvent(Ion::Events::Event event) { @@ -124,12 +128,12 @@ int ValuesController::maxNumberOfFunctions() { Shared::BufferFunctionTitleCell * ValuesController::functionTitleCells(int j) { assert(j >= 0 && j < k_maxNumberOfFunctions); - return m_functionTitleCells[j]; + return &m_functionTitleCells[j]; } EvenOddBufferTextCell * ValuesController::floatCells(int j) { assert(j >= 0 && j < k_maxNumberOfCells); - return m_floatCells[j]; + return &m_floatCells[j]; } CartesianFunctionStore * ValuesController::functionStore() const { @@ -149,28 +153,6 @@ double ValuesController::evaluationOfAbscissaAtColumn(double abscissa, int colum return function->evaluateAtAbscissa(abscissa, myApp->localContext()); } -View * ValuesController::loadView() { - for (int i = 0; i < k_maxNumberOfFunctions; i++) { - m_functionTitleCells[i] = new Shared::BufferFunctionTitleCell(FunctionTitleCell::Orientation::HorizontalIndicator, KDText::FontSize::Small); - } - for (int i = 0; i < k_maxNumberOfCells; i++) { - m_floatCells[i] = new EvenOddBufferTextCell(); - } - return Shared::ValuesController::loadView(); -} - -void ValuesController::unloadView(View * view) { - for (int i = 0; i < k_maxNumberOfCells; i++) { - delete m_floatCells[i]; - m_floatCells[i] = nullptr; - } - for (int i = 0; i < k_maxNumberOfFunctions; i++) { - delete m_functionTitleCells[i]; - m_functionTitleCells[i] = nullptr; - } - Shared::ValuesController::unloadView(view); -} - void ValuesController::updateNumberOfColumns() { int result = 1; for (int i = 0; i < m_functionStore->numberOfActiveFunctions(); i++) { diff --git a/apps/graph/values/values_controller.h b/apps/graph/values/values_controller.h index b12507ec6..89747d732 100644 --- a/apps/graph/values/values_controller.h +++ b/apps/graph/values/values_controller.h @@ -27,16 +27,14 @@ private: double evaluationOfAbscissaAtColumn(double abscissa, int columnIndex) override; constexpr static int k_maxNumberOfCells = 50; constexpr static int k_maxNumberOfFunctions = 5; - Shared::BufferFunctionTitleCell * m_functionTitleCells[k_maxNumberOfFunctions]; + Shared::BufferFunctionTitleCell m_functionTitleCells[k_maxNumberOfFunctions]; Shared::BufferFunctionTitleCell * functionTitleCells(int j) override; - EvenOddBufferTextCell * m_floatCells[k_maxNumberOfCells]; + EvenOddBufferTextCell m_floatCells[k_maxNumberOfCells]; EvenOddBufferTextCell * floatCells(int j) override; CartesianFunctionStore * m_functionStore; CartesianFunctionStore * functionStore() const override; FunctionParameterController m_functionParameterController; FunctionParameterController * functionParameterController() override; - View * loadView() override; - void unloadView(View * view) override; Shared::IntervalParameterController m_intervalParameterController; DerivativeParameterController m_derivativeParameterController; }; diff --git a/apps/regression/calculation_controller.cpp b/apps/regression/calculation_controller.cpp index 0fd5145b2..fd71c2ac8 100644 --- a/apps/regression/calculation_controller.cpp +++ b/apps/regression/calculation_controller.cpp @@ -14,17 +14,33 @@ namespace Regression { static inline int max(int x, int y) { return (x>y ? x : y); } CalculationController::CalculationController(Responder * parentResponder, ButtonRowController * header, Store * store) : - TabTableController(parentResponder, this), + TabTableController(parentResponder), ButtonRowDelegate(header, nullptr), + m_selectableTableView(this, this, this, this), m_titleCells{}, - m_r2TitleCell(nullptr), + m_r2TitleCell(), m_columnTitleCells{}, m_doubleCalculationCells{}, m_calculationCells{}, - m_hideableCell(nullptr), + m_hideableCell(), m_store(store) { m_r2Layout = HorizontalLayoutRef(CharLayoutRef('r', KDText::FontSize::Small), VerticalOffsetLayoutRef(CharLayoutRef('2', KDText::FontSize::Small), VerticalOffsetLayoutNode::Type::Superscript)); + m_selectableTableView.setVerticalCellOverlap(0); + m_selectableTableView.setBackgroundColor(Palette::WallScreenDark); + m_selectableTableView.setMargins(k_margin, k_scrollBarMargin, k_scrollBarMargin, k_margin); + m_r2TitleCell.setAlignment(1.0f, 0.5f); + for (int i = 0; i < Store::k_numberOfSeries; i++) { + m_columnTitleCells[i].setParentResponder(&m_selectableTableView); + } + for (int i = 0; i < k_numberOfDoubleCalculationCells; i++) { + m_doubleCalculationCells[i].setTextColor(Palette::GreyDark); + m_doubleCalculationCells[i].setParentResponder(&m_selectableTableView); + } + for (int i = 0; i < k_numberOfCalculationCells;i++) { + m_calculationCells[i].setTextColor(Palette::GreyDark); + } + m_hideableCell.setHide(true); } const char * CalculationController::title() { @@ -250,28 +266,25 @@ int CalculationController::indexFromCumulatedHeight(KDCoordinate offsetY) { HighlightCell * CalculationController::reusableCell(int index, int type) { if (type == k_standardCalculationTitleCellType) { assert(index >= 0 && index < k_maxNumberOfDisplayableRows); - assert(m_titleCells[index] != nullptr); - return m_titleCells[index]; + return &m_titleCells[index]; } if (type == k_r2CellType) { assert(index == 0); - return m_r2TitleCell; + return &m_r2TitleCell; } if (type == k_columnTitleCellType) { assert(index >= 0 && index < Store::k_numberOfSeries); - return m_columnTitleCells[index]; + return &m_columnTitleCells[index]; } if (type == k_doubleBufferCalculationCellType) { assert(index >= 0 && index < k_numberOfDoubleCalculationCells); - assert(m_doubleCalculationCells[index] != nullptr); - return m_doubleCalculationCells[index]; + return &m_doubleCalculationCells[index]; } if (type == k_hideableCellType) { - return m_hideableCell; + return &m_hideableCell; } assert(index >= 0 && index < k_numberOfCalculationCells); - assert(m_calculationCells[index] != nullptr); - return m_calculationCells[index]; + return &m_calculationCells[index]; } int CalculationController::reusableCellCount(int type) { @@ -319,57 +332,6 @@ Responder * CalculationController::tabController() const { return (parentResponder()->parentResponder()->parentResponder()); } -View * CalculationController::loadView() { - SelectableTableView * tableView = new SelectableTableView(this, this, this, this); - tableView->setVerticalCellOverlap(0); - tableView->setBackgroundColor(Palette::WallScreenDark); - tableView->setMargins(k_margin, k_scrollBarMargin, k_scrollBarMargin, k_margin); - m_r2TitleCell = new EvenOddExpressionCell(1.0f, 0.5f); - m_r2TitleCell->setRightMargin(k_r2CellMargin); - for (int i = 0; i < Store::k_numberOfSeries; i++) { - m_columnTitleCells[i] = new ColumnTitleCell(tableView); - } - for (int i = 0; i < k_maxNumberOfDisplayableRows; i++) { - m_titleCells[i] = new MarginEvenOddMessageTextCell(KDText::FontSize::Small); - } - for (int i = 0; i < k_numberOfDoubleCalculationCells; i++) { - m_doubleCalculationCells[i] = new EvenOddDoubleBufferTextCellWithSeparator(); - m_doubleCalculationCells[i]->setTextColor(Palette::GreyDark); - m_doubleCalculationCells[i]->setParentResponder(tableView); - } - for (int i = 0; i < k_numberOfCalculationCells;i++) { - m_calculationCells[i] = new SeparatorEvenOddBufferTextCell(KDText::FontSize::Small); - m_calculationCells[i]->setTextColor(Palette::GreyDark); - } - m_hideableCell = new HideableEvenOddCell(); - m_hideableCell->setHide(true); - return tableView; -} - -void CalculationController::unloadView(View * view) { - delete m_r2TitleCell; - m_r2TitleCell = nullptr; - for (int i = 0; i < Store::k_numberOfSeries; i++) { - delete m_columnTitleCells[i]; - m_columnTitleCells[i] = nullptr; - } - for (int i = 0; i < k_numberOfDoubleCalculationCells; i++) { - delete m_doubleCalculationCells[i]; - m_doubleCalculationCells[i] = nullptr; - } - for (int i = 0; i < k_numberOfCalculationCells;i++) { - delete m_calculationCells[i]; - m_calculationCells[i] = nullptr; - } - for (int i = 0; i < k_maxNumberOfDisplayableRows; i++) { - delete m_titleCells[i]; - m_titleCells[i] = nullptr; - } - delete m_hideableCell; - m_hideableCell = nullptr; - TabTableController::unloadView(view); -} - bool CalculationController::hasLinearRegression() const { int numberOfDefinedSeries = m_store->numberOfNonEmptySeries(); for (int i = 0; i < numberOfDefinedSeries; i++) { diff --git a/apps/regression/calculation_controller.h b/apps/regression/calculation_controller.h index 1f829fa11..0164f76d9 100644 --- a/apps/regression/calculation_controller.h +++ b/apps/regression/calculation_controller.h @@ -65,19 +65,18 @@ private: static constexpr KDCoordinate k_margin = 8; static constexpr KDCoordinate k_r2CellMargin = 2; static constexpr KDCoordinate k_scrollBarMargin = Metric::CommonRightMargin; - Responder * tabController() const override; - View * loadView() override; - void unloadView(View * view) override; + SelectableTableView * selectableTableView() override { return &m_selectableTableView; } bool hasLinearRegression() const; int maxNumberOfCoefficients() const; - Shared::MarginEvenOddMessageTextCell * m_titleCells[k_maxNumberOfDisplayableRows]; - EvenOddExpressionCell * m_r2TitleCell; Poincare::LayoutReference m_r2Layout; - ColumnTitleCell * m_columnTitleCells[Store::k_numberOfSeries]; - EvenOddDoubleBufferTextCellWithSeparator * m_doubleCalculationCells[k_numberOfDoubleCalculationCells]; - Shared::SeparatorEvenOddBufferTextCell * m_calculationCells[k_numberOfCalculationCells]; - Shared::HideableEvenOddCell * m_hideableCell; + SelectableTableView m_selectableTableView; + Shared::MarginEvenOddMessageTextCell m_titleCells[k_maxNumberOfDisplayableRows]; + EvenOddExpressionCell m_r2TitleCell; + ColumnTitleCell m_columnTitleCells[Store::k_numberOfSeries]; + EvenOddDoubleBufferTextCellWithSeparator m_doubleCalculationCells[k_numberOfDoubleCalculationCells]; + Shared::SeparatorEvenOddBufferTextCell m_calculationCells[k_numberOfCalculationCells]; + Shared::HideableEvenOddCell m_hideableCell; Store * m_store; }; diff --git a/apps/regression/store_controller.cpp b/apps/regression/store_controller.cpp index bbcdf6c97..0bc72bae4 100644 --- a/apps/regression/store_controller.cpp +++ b/apps/regression/store_controller.cpp @@ -50,22 +50,7 @@ void StoreController::willDisplayCellAtLocation(HighlightCell * cell, int i, int HighlightCell * StoreController::titleCells(int index) { assert(index >= 0 && index < k_numberOfTitleCells); - return m_titleCells[index]; -} - -View * StoreController::loadView() { - for (int i = 0; i < k_numberOfTitleCells; i++) { - m_titleCells[i] = new Shared::StoreTitleCell(); - } - return Shared::StoreController::loadView(); -} - -void StoreController::unloadView(View * view) { - for (int i = 0; i < k_numberOfTitleCells; i++) { - delete m_titleCells[i]; - m_titleCells[i] = nullptr; - } - Shared::StoreController::unloadView(view); + return &m_titleCells[index]; } } diff --git a/apps/regression/store_controller.h b/apps/regression/store_controller.h index 0620270e6..d05aadd9b 100644 --- a/apps/regression/store_controller.h +++ b/apps/regression/store_controller.h @@ -19,10 +19,8 @@ public: void willDisplayCellAtLocation(HighlightCell * cell, int i, int j) override; private: HighlightCell * titleCells(int index) override; - View * loadView() override; - void unloadView(View * view) override; Shared::StoreParameterController * storeParameterController() override { return &m_storeParameterController; } - Shared::StoreTitleCell * m_titleCells[k_numberOfTitleCells]; + Shared::StoreTitleCell m_titleCells[k_numberOfTitleCells]; RegressionContext m_regressionContext; StoreParameterController m_storeParameterController; }; diff --git a/apps/sequence/values/values_controller.cpp b/apps/sequence/values/values_controller.cpp index c664c8e16..fb79a5711 100644 --- a/apps/sequence/values/values_controller.cpp +++ b/apps/sequence/values/values_controller.cpp @@ -16,6 +16,9 @@ ValuesController::ValuesController(Responder * parentResponder, SequenceStore * #endif m_intervalParameterController(this, m_interval) { + for (int i = 0; i < k_maxNumberOfSequences; i++) { + m_sequenceTitleCells[i].setOrientation(FunctionTitleCell::Orientation::HorizontalIndicator); + } } void ValuesController::willDisplayCellAtLocation(HighlightCell * cell, int i, int j) { @@ -63,12 +66,12 @@ int ValuesController::maxNumberOfFunctions() { SequenceTitleCell * ValuesController::functionTitleCells(int j) { assert(j >= 0 && j < k_maxNumberOfSequences); - return m_sequenceTitleCells[j]; + return &m_sequenceTitleCells[j]; } EvenOddBufferTextCell * ValuesController::floatCells(int j) { assert(j >= 0 && j < k_maxNumberOfCells); - return m_floatCells[j]; + return &m_floatCells[j]; } SequenceStore * ValuesController::functionStore() const { @@ -83,27 +86,4 @@ Shared::ValuesFunctionParameterController * ValuesController::functionParameterC #endif } -View * ValuesController::loadView() { - for (int i = 0; i < k_maxNumberOfSequences; i++) { - m_sequenceTitleCells[i] = new SequenceTitleCell(); - m_sequenceTitleCells[i]->setOrientation(FunctionTitleCell::Orientation::HorizontalIndicator); - } - for (int i = 0; i < k_maxNumberOfCells; i++) { - m_floatCells[i] = new EvenOddBufferTextCell(); - } - return Shared::ValuesController::loadView(); -} - -void ValuesController::unloadView(View * view) { - for (int i = 0; i < k_maxNumberOfCells; i++) { - delete m_floatCells[i]; - m_floatCells[i] = nullptr; - } - for (int i = 0; i < k_maxNumberOfSequences; i++) { - delete m_sequenceTitleCells[i]; - m_sequenceTitleCells[i] = nullptr; - } - Shared::ValuesController::unloadView(view); -} - } diff --git a/apps/sequence/values/values_controller.h b/apps/sequence/values/values_controller.h index fb455d928..aecc13159 100644 --- a/apps/sequence/values/values_controller.h +++ b/apps/sequence/values/values_controller.h @@ -20,14 +20,12 @@ private: int maxNumberOfFunctions() override; constexpr static int k_maxNumberOfCells = 30; constexpr static int k_maxNumberOfSequences = 3; - SequenceTitleCell * m_sequenceTitleCells[k_maxNumberOfSequences]; + SequenceTitleCell m_sequenceTitleCells[k_maxNumberOfSequences]; SequenceTitleCell * functionTitleCells(int j) override; - EvenOddBufferTextCell * m_floatCells[k_maxNumberOfCells]; + EvenOddBufferTextCell m_floatCells[k_maxNumberOfCells]; EvenOddBufferTextCell * floatCells(int j) override; SequenceStore * m_sequenceStore; SequenceStore * functionStore() const override; - View * loadView() override; - void unloadView(View * view) override; #if COPY_COLUMN Shared::ValuesFunctionParameterController m_sequenceParameterController; #endif diff --git a/apps/shared/buffer_function_title_cell.h b/apps/shared/buffer_function_title_cell.h index 6ff49d5e7..548fefdf8 100644 --- a/apps/shared/buffer_function_title_cell.h +++ b/apps/shared/buffer_function_title_cell.h @@ -12,6 +12,7 @@ public: void setHighlighted(bool highlight) override; void setColor(KDColor color) override; void setText(const char * textContent); + void setFontSize(KDText::FontSize size) { m_bufferTextView.setFontSize(size); } const char * text() const override { return m_bufferTextView.text(); } diff --git a/apps/shared/editable_cell_table_view_controller.cpp b/apps/shared/editable_cell_table_view_controller.cpp index e6a4a3883..b9a5af534 100644 --- a/apps/shared/editable_cell_table_view_controller.cpp +++ b/apps/shared/editable_cell_table_view_controller.cpp @@ -11,7 +11,7 @@ using namespace Poincare; namespace Shared { EditableCellTableViewController::EditableCellTableViewController(Responder * parentResponder) : - TabTableController(parentResponder, this) + TabTableController(parentResponder) { } diff --git a/apps/shared/store_controller.cpp b/apps/shared/store_controller.cpp index f8074d99c..8602c5b0e 100644 --- a/apps/shared/store_controller.cpp +++ b/apps/shared/store_controller.cpp @@ -53,33 +53,39 @@ StoreController::StoreController(Responder * parentResponder, DoublePairStore * EditableCellTableViewController(parentResponder), ButtonRowDelegate(header, nullptr), m_editableCells{}, - m_store(store) + m_store(store), + m_contentView(m_store, this, this, this, this) { + for (int i = 0; i < k_maxNumberOfEditableCells; i++) { + m_editableCells[i].setParentResponder(m_contentView.dataView()); + m_editableCells[i].editableTextCell()->textField()->setDelegate(this); + m_editableCells[i].editableTextCell()->textField()->setDraftTextBuffer(m_draftTextBuffer); + } } void StoreController::displayFormulaInput() { setFormulaLabel(); - contentView()->displayFormulaInput(true); + m_contentView.displayFormulaInput(true); } bool StoreController::textFieldShouldFinishEditing(TextField * textField, Ion::Events::Event event) { - if (textField == contentView()->formulaInputView()->textField()) { + if (textField == m_contentView.formulaInputView()->textField()) { return event == Ion::Events::OK || event == Ion::Events::EXE; } return EditableCellTableViewController::textFieldShouldFinishEditing(textField, event); } bool StoreController::textFieldDidFinishEditing(TextField * textField, const char * text, Ion::Events::Event event) { - if (textField == contentView()->formulaInputView()->textField()) { + if (textField == m_contentView.formulaInputView()->textField()) { // Handle formula input Expression expression = Expression::parse(textField->text()); if (expression.isUninitialized()) { app()->displayWarning(I18n::Message::SyntaxError); return false; } - contentView()->displayFormulaInput(false); + m_contentView.displayFormulaInput(false); if (fillColumnWithFormula(expression)) { - app()->setFirstResponder(contentView()); + app()->setFirstResponder(&m_contentView); } return true; } @@ -105,9 +111,9 @@ bool StoreController::textFieldDidFinishEditing(TextField * textField, const cha } bool StoreController::textFieldDidAbortEditing(TextField * textField) { - if (textField == contentView()->formulaInputView()->textField()) { - contentView()->displayFormulaInput(false); - app()->setFirstResponder(contentView()); + if (textField == m_contentView.formulaInputView()->textField()) { + m_contentView.displayFormulaInput(false); + app()->setFirstResponder(&m_contentView); return true; } return EditableCellTableViewController::textFieldDidAbortEditing(textField); @@ -138,7 +144,7 @@ HighlightCell * StoreController::reusableCell(int index, int type) { return titleCells(index); case k_editableCellType: assert(index < k_maxNumberOfEditableCells); - return m_editableCells[index]; + return &m_editableCells[index]; default: assert(false); return nullptr; @@ -213,7 +219,7 @@ void StoreController::didBecomeFirstResponder() { selectCellAtLocation(0, 0); } EditableCellTableViewController::didBecomeFirstResponder(); - app()->setFirstResponder(contentView()); + app()->setFirstResponder(&m_contentView); } Responder * StoreController::tabController() const { @@ -221,7 +227,7 @@ Responder * StoreController::tabController() const { } SelectableTableView * StoreController::selectableTableView() { - return contentView()->dataView(); + return m_contentView.dataView(); } bool StoreController::cellAtLocationIsEditable(int columnIndex, int rowIndex) { @@ -252,22 +258,6 @@ int StoreController::maxNumberOfElements() const { return DoublePairStore::k_maxNumberOfPairs; } -View * StoreController::loadView() { - ContentView * contentView = new ContentView(m_store, this, this, this, this); - for (int i = 0; i < k_maxNumberOfEditableCells; i++) { - m_editableCells[i] = new StoreCell(contentView->dataView(), this, m_draftTextBuffer); - } - return contentView; -} - -void StoreController::unloadView(View * view) { - for (int i = 0; i < k_maxNumberOfEditableCells; i++) { - delete m_editableCells[i]; - m_editableCells[i] = nullptr; - } - delete view; -} - bool StoreController::privateFillColumnWithFormula(Expression formula, ExpressionNode::isVariableTest isVariable) { int currentColumn = selectedColumn(); // Fetch the series used in the formula to compute the size of the filled in series diff --git a/apps/shared/store_controller.h b/apps/shared/store_controller.h index 9e2c551dd..450348b19 100644 --- a/apps/shared/store_controller.h +++ b/apps/shared/store_controller.h @@ -75,8 +75,6 @@ protected: Responder * tabController() const override; SelectableTableView * selectableTableView() override; - View * loadView() override; - void unloadView(View * view) override; bool cellAtLocationIsEditable(int columnIndex, int rowIndex) override; bool setDataAtLocation(double floatBody, int columnIndex, int rowIndex) override; double dataAtLocation(int columnIndex, int rowIndex) override; @@ -87,11 +85,11 @@ protected: int seriesAtColumn(int column) const { return column / DoublePairStore::k_numberOfColumnsPerSeries; } bool privateFillColumnWithFormula(Poincare::Expression formula, Poincare::ExpressionNode::isVariableTest isVariable); virtual StoreParameterController * storeParameterController() = 0; - StoreCell * m_editableCells[k_maxNumberOfEditableCells]; + StoreCell m_editableCells[k_maxNumberOfEditableCells]; DoublePairStore * m_store; private: bool cellShouldBeTransparent(int i, int j); - ContentView * contentView() { return static_cast(view()); } + ContentView m_contentView; }; } diff --git a/apps/shared/tab_table_controller.cpp b/apps/shared/tab_table_controller.cpp index 824018371..e32cfadea 100644 --- a/apps/shared/tab_table_controller.cpp +++ b/apps/shared/tab_table_controller.cpp @@ -2,9 +2,8 @@ namespace Shared { -TabTableController::TabTableController(Responder * parentResponder, TableViewDataSource * dataSource) : - DynamicViewController(parentResponder), - m_dataSource(dataSource) +TabTableController::TabTableController(Responder * parentResponder) : + ViewController(parentResponder) { } @@ -13,7 +12,6 @@ void TabTableController::didBecomeFirstResponder() { } void TabTableController::viewWillAppear() { - DynamicViewController::viewWillAppear(); selectableTableView()->reloadData(); } @@ -28,16 +26,4 @@ SelectableTableView * TabTableController::selectableTableView() { return static_cast(view()); } -View * TabTableController::loadView() { - SelectableTableView * selectableTableView = new SelectableTableView(this, m_dataSource, this); - selectableTableView->setBackgroundColor(Palette::WallScreenDark); - selectableTableView->setVerticalCellOverlap(0); - return selectableTableView; } - -void TabTableController::unloadView(View * view) { - delete view; -} - -} - diff --git a/apps/shared/tab_table_controller.h b/apps/shared/tab_table_controller.h index f00dcd22a..6aecbe10e 100644 --- a/apps/shared/tab_table_controller.h +++ b/apps/shared/tab_table_controller.h @@ -8,19 +8,16 @@ namespace Shared { /* Tab table controller is a controller whose view is a selectable table view * and whose one ancestor is a tab */ -class TabTableController : public DynamicViewController, public SelectableTableViewDataSource { +class TabTableController : public ViewController, public SelectableTableViewDataSource { public: - TabTableController(Responder * parentResponder, TableViewDataSource * dataSource); + TabTableController(Responder * parentResponder); + View * view() override { return selectableTableView(); } void didBecomeFirstResponder() override; void viewWillAppear() override; void willExitResponderChain(Responder * nextFirstResponder) override; protected: - virtual SelectableTableView * selectableTableView(); - virtual View * loadView() override; - void unloadView(View * view) override; + virtual SelectableTableView * selectableTableView() = 0; virtual Responder * tabController() const = 0; -private: - TableViewDataSource * m_dataSource; }; } diff --git a/apps/shared/values_controller.cpp b/apps/shared/values_controller.cpp index 1b767f870..2222d3384 100644 --- a/apps/shared/values_controller.cpp +++ b/apps/shared/values_controller.cpp @@ -15,7 +15,8 @@ ValuesController::ValuesController(Responder * parentResponder, ButtonRowControl m_interval(interval), m_numberOfColumns(0), m_numberOfColumnsNeedUpdate(true), - m_abscissaTitleCell(nullptr), + m_selectableTableView(this), + m_abscissaTitleCell(), m_abscissaCells{}, m_abscissaParameterController(this, intervalParameterController, parameterTitle), m_setIntervalButton(this, I18n::Message::IntervalSet, Invocation([](void * context, void * sender) { @@ -24,6 +25,20 @@ ValuesController::ValuesController(Responder * parentResponder, ButtonRowControl stack->push(valuesController->intervalParameterController()); }, this), KDText::FontSize::Small) { + m_selectableTableView.setVerticalCellOverlap(0); + m_selectableTableView.setTopMargin(k_topMargin); + m_selectableTableView.setRightMargin(k_rightMargin); + m_selectableTableView.setBottomMargin(k_bottomMargin); + m_selectableTableView.setLeftMargin(k_leftMargin); + m_selectableTableView.setBackgroundColor(Palette::WallScreenDark); + m_selectableTableView.setIndicatorThickness(13); + m_abscissaTitleCell.setMessageFontSize(KDText::FontSize::Small); + for (int i = 0; i < k_maxNumberOfAbscissaCells; i++) { + m_abscissaCells[i].setParentResponder(&m_selectableTableView); + m_abscissaCells[i].editableTextCell()->textField()->setDelegate(this); + m_abscissaCells[i].editableTextCell()->textField()->setDraftTextBuffer(m_draftTextBuffer); + m_abscissaCells[i].editableTextCell()->textField()->setFontSize(KDText::FontSize::Small); + } } const char * ValuesController::title() { @@ -173,12 +188,12 @@ HighlightCell * ValuesController::reusableCell(int index, int type) { switch (type) { case 0: assert(index == 0); - return m_abscissaTitleCell; + return &m_abscissaTitleCell; case 1: return functionTitleCells(index); case 2: assert(index < k_maxNumberOfAbscissaCells); - return m_abscissaCells[index]; + return &m_abscissaCells[index]; case 3: return floatCells(index); default: @@ -299,33 +314,6 @@ double ValuesController::evaluationOfAbscissaAtColumn(double abscissa, int colum return function->evaluateAtAbscissa(abscissa, myApp->localContext()); } -View * ValuesController::loadView() { - SelectableTableView * tableView = new SelectableTableView(this); - tableView->setVerticalCellOverlap(0); - tableView->setTopMargin(k_topMargin); - tableView->setRightMargin(k_rightMargin); - tableView->setBottomMargin(k_bottomMargin); - tableView->setLeftMargin(k_leftMargin); - tableView->setBackgroundColor(Palette::WallScreenDark); - tableView->setIndicatorThickness(13); - - m_abscissaTitleCell = new EvenOddMessageTextCell(KDText::FontSize::Small); - for (int i = 0; i < k_maxNumberOfAbscissaCells; i++) { - m_abscissaCells[i] = new EvenOddEditableTextCell(tableView, this, m_draftTextBuffer, KDText::FontSize::Small); - } - return tableView; -} - -void ValuesController::unloadView(View * view) { - delete m_abscissaTitleCell; - m_abscissaTitleCell = nullptr; - for (int i = 0; i < k_maxNumberOfAbscissaCells; i++) { - delete m_abscissaCells[i]; - m_abscissaCells[i] = nullptr; - } - EditableCellTableViewController::unloadView(view); -} - void ValuesController::updateNumberOfColumns() { m_numberOfColumns = 1+functionStore()->numberOfActiveFunctions(); } diff --git a/apps/shared/values_controller.h b/apps/shared/values_controller.h index 3a6429451..0c32ecb25 100644 --- a/apps/shared/values_controller.h +++ b/apps/shared/values_controller.h @@ -45,8 +45,6 @@ public: protected: StackViewController * stackController() const; bool setDataAtLocation(double floatBody, int columnIndex, int rowIndex) override; - View * loadView() override; - void unloadView(View * view) override; virtual void updateNumberOfColumns(); Interval * m_interval; int m_numberOfColumns; @@ -54,6 +52,7 @@ protected: private: virtual Function * functionAtColumn(int i); Responder * tabController() const override; + SelectableTableView * selectableTableView() override { return &m_selectableTableView; } void configureAbscissa(); void configureFunction(); bool cellAtLocationIsEditable(int columnIndex, int rowIndex) override; @@ -64,11 +63,12 @@ private: constexpr static int k_maxNumberOfAbscissaCells = 10; virtual int maxNumberOfCells() = 0; virtual int maxNumberOfFunctions() = 0; - EvenOddMessageTextCell * m_abscissaTitleCell; + SelectableTableView m_selectableTableView; + EvenOddMessageTextCell m_abscissaTitleCell; virtual FunctionTitleCell * functionTitleCells(int j) = 0; virtual EvenOddBufferTextCell * floatCells(int j) = 0; char m_draftTextBuffer[TextField::maxBufferSize()]; - EvenOddEditableTextCell * m_abscissaCells[k_maxNumberOfAbscissaCells]; + EvenOddEditableTextCell m_abscissaCells[k_maxNumberOfAbscissaCells]; virtual FunctionStore * functionStore() const = 0; virtual ValuesFunctionParameterController * functionParameterController() = 0; ValuesParameterController m_abscissaParameterController; diff --git a/apps/statistics/calculation_controller.cpp b/apps/statistics/calculation_controller.cpp index a1a1fb707..207bceb7e 100644 --- a/apps/statistics/calculation_controller.cpp +++ b/apps/statistics/calculation_controller.cpp @@ -1,6 +1,4 @@ #include "calculation_controller.h" -#include "app.h" -#include "calculation_selectable_table_view.h" #include "../constant.h" #include "../apps_container.h" #include "../shared/poincare_helpers.h" @@ -13,14 +11,28 @@ using namespace Poincare; namespace Statistics { CalculationController::CalculationController(Responder * parentResponder, ButtonRowController * header, Store * store) : - TabTableController(parentResponder, this), + TabTableController(parentResponder), ButtonRowDelegate(header, nullptr), + m_selectableTableView(this, this, this), m_seriesTitleCells{}, m_calculationTitleCells{}, m_calculationCells{}, - m_hideableCell(nullptr), + m_hideableCell(), m_store(store) { + m_selectableTableView.setBackgroundColor(Palette::WallScreenDark); + m_selectableTableView.setVerticalCellOverlap(0); + m_selectableTableView.setMargins(k_margin, k_scrollBarMargin, k_scrollBarMargin, k_margin); + for (int i = 0; i < k_numberOfSeriesTitleCells; i++) { + m_seriesTitleCells[i].setSeparatorLeft(true); + } + for (int i = 0; i < k_numberOfCalculationTitleCells; i++) { + m_calculationTitleCells[i].setAlignment(1.0f, 0.5f); + } + for (int i = 0; i < k_numberOfCalculationCells; i++) { + m_calculationCells[i].setTextColor(Palette::GreyDark); + } + m_hideableCell.setHide(true); } // AlternateEmptyViewDelegate @@ -107,16 +119,16 @@ int CalculationController::indexFromCumulatedHeight(KDCoordinate offsetY) { HighlightCell * CalculationController::reusableCell(int index, int type) { assert(index >= 0 && index < reusableCellCount(type)); if (type == k_hideableCellType) { - return m_hideableCell; + return &m_hideableCell; } if (type == k_calculationTitleCellType) { - return static_cast(m_calculationTitleCells[index]); + return &m_calculationTitleCells[index]; } if (type == k_seriesTitleCellType) { - return static_cast(m_seriesTitleCells[index]); + return &m_seriesTitleCells[index]; } assert(type == k_calculationCellType); - return static_cast(m_calculationCells[index]); + return &m_calculationCells[index]; } int CalculationController::reusableCellCount(int type) { @@ -178,47 +190,5 @@ Responder * CalculationController::tabController() const { return (parentResponder()->parentResponder()->parentResponder()); } -View * CalculationController::loadView() { - for (int i = 0; i < k_numberOfSeriesTitleCells; i++) { - m_seriesTitleCells[i] = new StoreTitleCell(); - m_seriesTitleCells[i]->setSeparatorLeft(true); - } - for (int i = 0; i < k_numberOfCalculationTitleCells; i++) { - m_calculationTitleCells[i] = new MarginEvenOddMessageTextCell(KDText::FontSize::Small); - m_calculationTitleCells[i]->setAlignment(1.0f, 0.5f); - } - for (int i = 0; i < k_numberOfCalculationCells; i++) { - m_calculationCells[i] = new SeparatorEvenOddBufferTextCell(KDText::FontSize::Small); - m_calculationCells[i]->setTextColor(Palette::GreyDark); - } - m_hideableCell = new HideableEvenOddCell(); - m_hideableCell->setHide(true); - - CalculationSelectableTableView * selectableTableView = new CalculationSelectableTableView(this, this, this); - selectableTableView->setBackgroundColor(Palette::WallScreenDark); - selectableTableView->setVerticalCellOverlap(0); - selectableTableView->setMargins(k_margin, k_scrollBarMargin, k_scrollBarMargin, k_margin); - return selectableTableView; -} - - -void CalculationController::unloadView(View * view) { - for (int i = 0; i < k_numberOfSeriesTitleCells; i++) { - delete m_seriesTitleCells[i]; - m_seriesTitleCells[i] = nullptr; - } - for (int i = 0; i < k_numberOfCalculationTitleCells; i++) { - delete m_calculationTitleCells[i]; - m_calculationTitleCells[i] = nullptr; - } - for (int i = 0; i < k_numberOfCalculationCells; i++) { - delete m_calculationCells[i]; - m_calculationCells[i] = nullptr; - } - delete m_hideableCell; - m_hideableCell = nullptr; - TabTableController::unloadView(view); -} - } diff --git a/apps/statistics/calculation_controller.h b/apps/statistics/calculation_controller.h index 5210be2b6..4fa9edb82 100644 --- a/apps/statistics/calculation_controller.h +++ b/apps/statistics/calculation_controller.h @@ -3,6 +3,7 @@ #include #include "store.h" +#include "calculation_selectable_table_view.h" #include "../shared/hideable_even_odd_cell.h" #include "../shared/margin_even_odd_message_text_cell.h" #include "../shared/separator_even_odd_buffer_text_cell.h" @@ -57,13 +58,12 @@ private: static constexpr KDCoordinate k_scrollBarMargin = Metric::CommonRightMargin; Responder * tabController() const override; - View * loadView() override; - void unloadView(View * view) override; - - Shared::StoreTitleCell * m_seriesTitleCells[k_numberOfSeriesTitleCells]; - Shared::MarginEvenOddMessageTextCell * m_calculationTitleCells[k_numberOfCalculationTitleCells]; - Shared::SeparatorEvenOddBufferTextCell * m_calculationCells[k_numberOfCalculationCells]; - Shared::HideableEvenOddCell * m_hideableCell; + SelectableTableView * selectableTableView() override { return &m_selectableTableView; } + CalculationSelectableTableView m_selectableTableView; + Shared::StoreTitleCell m_seriesTitleCells[k_numberOfSeriesTitleCells]; + Shared::MarginEvenOddMessageTextCell m_calculationTitleCells[k_numberOfCalculationTitleCells]; + Shared::SeparatorEvenOddBufferTextCell m_calculationCells[k_numberOfCalculationCells]; + Shared::HideableEvenOddCell m_hideableCell; Store * m_store; }; diff --git a/apps/statistics/store_controller.cpp b/apps/statistics/store_controller.cpp index 627f9262f..c4a96a316 100644 --- a/apps/statistics/store_controller.cpp +++ b/apps/statistics/store_controller.cpp @@ -59,7 +59,7 @@ void StoreController::willDisplayCellAtLocation(HighlightCell * cell, int i, int HighlightCell * StoreController::titleCells(int index) { assert(index >= 0 && index < k_numberOfTitleCells); - return m_titleCells[index]; + return &m_titleCells[index]; } bool StoreController::setDataAtLocation(double floatBody, int columnIndex, int rowIndex) { @@ -74,19 +74,4 @@ bool StoreController::setDataAtLocation(double floatBody, int columnIndex, int r return Shared::StoreController::setDataAtLocation(floatBody, columnIndex, rowIndex); } -View * StoreController::loadView() { - for (int i = 0; i < k_numberOfTitleCells; i++) { - m_titleCells[i] = new Shared::StoreTitleCell(); - } - return Shared::StoreController::loadView(); -} - -void StoreController::unloadView(View * view) { - for (int i = 0; i < k_numberOfTitleCells; i++) { - delete m_titleCells[i]; - m_titleCells[i] = nullptr; - } - Shared::StoreController::unloadView(view); -} - } diff --git a/apps/statistics/store_controller.h b/apps/statistics/store_controller.h index ba61ceb89..398bbe6c5 100644 --- a/apps/statistics/store_controller.h +++ b/apps/statistics/store_controller.h @@ -19,10 +19,8 @@ public: private: bool setDataAtLocation(double floatBody, int columnIndex, int rowIndex) override; HighlightCell * titleCells(int index) override; - View * loadView() override; - void unloadView(View * view) override; Shared::StoreParameterController * storeParameterController() override { return &m_storeParameterController; } - Shared::StoreTitleCell * m_titleCells[k_numberOfTitleCells]; + Shared::StoreTitleCell m_titleCells[k_numberOfTitleCells]; Store * m_store; StatisticsContext m_statisticsContext; Shared::StoreParameterController m_storeParameterController; diff --git a/escher/include/escher/even_odd_expression_cell.h b/escher/include/escher/even_odd_expression_cell.h index de197b70d..e2e224369 100644 --- a/escher/include/escher/even_odd_expression_cell.h +++ b/escher/include/escher/even_odd_expression_cell.h @@ -14,7 +14,7 @@ public: void setBackgroundColor(KDColor backgroundColor); void setTextColor(KDColor textColor); KDSize minimalSizeForOptimalDisplay() const override; - void setAlignment(float horizontalAlignment, float verticalAlignment); + void setAlignment(float horizontalAlignment, float verticalAlignment) { m_expressionView.setAlignment(horizontalAlignment, verticalAlignment); } void setLeftMargin(KDCoordinate margin); void setRightMargin(KDCoordinate margin); Poincare::LayoutRef layoutRef() const override { return m_expressionView.layoutRef(); } diff --git a/escher/include/escher/even_odd_message_text_cell.h b/escher/include/escher/even_odd_message_text_cell.h index 86233611c..ef76ce2ba 100644 --- a/escher/include/escher/even_odd_message_text_cell.h +++ b/escher/include/escher/even_odd_message_text_cell.h @@ -12,6 +12,7 @@ public: void setHighlighted(bool highlight) override; void setMessage(I18n::Message textContent, KDColor textColor = KDColorBlack); void setAlignment(float horizontalAlignment, float verticalAlignment); + void setMessageFontSize(KDText::FontSize size) { m_messageTextView.setFontSize(size); } protected: int numberOfSubviews() const override; View * subviewAtIndex(int index) override; diff --git a/escher/include/escher/text_input.h b/escher/include/escher/text_input.h index 703265986..55dde64ed 100644 --- a/escher/include/escher/text_input.h +++ b/escher/include/escher/text_input.h @@ -10,6 +10,7 @@ class TextInput : public ScrollableView, public ScrollViewDataSource { public: TextInput(Responder * parentResponder, View * contentView); + void setFontSize(KDText::FontSize size) { contentView()->setFontSize(size); } Toolbox * toolbox() override; const char * text() const { return nonEditableContentView()->text(); } bool removeChar(); @@ -20,6 +21,7 @@ protected: class ContentView : public View { public: ContentView(KDText::FontSize size); + void setFontSize(KDText::FontSize size); size_t cursorLocation() const { return m_cursorIndex; } void setCursorLocation(int cursorLocation); virtual const char * text() const = 0; diff --git a/escher/src/text_input.cpp b/escher/src/text_input.cpp index cab8d5ee5..b0db0c3c0 100644 --- a/escher/src/text_input.cpp +++ b/escher/src/text_input.cpp @@ -18,6 +18,11 @@ void TextInput::ContentView::setCursorLocation(int location) { layoutSubviews(); } +void TextInput::ContentView::setFontSize(KDText::FontSize size) { + m_fontSize = size; + markRectAsDirty(bounds()); +} + KDRect TextInput::ContentView::cursorRect() { return characterFrameAtIndex(m_cursorIndex); }