From eef5f8dacb46bb53373740640a3b4a82e1bf9069 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Fri, 24 Feb 2017 16:58:22 +0100 Subject: [PATCH] [apps/sequence] Create a values tab Change-Id: I37ffc57bdce85c74f46d9966a4ba4db8233e6053 --- apps/graph/values/values_controller.cpp | 2 +- apps/sequence/sequence.cpp | 16 +++- apps/sequence/sequence.h | 2 + apps/sequence/values/values_controller.cpp | 85 +++++++++++++-------- apps/sequence/values/values_controller.h | 26 ++++--- apps/shared/values_controller.cpp | 4 +- apps/shared/values_controller.h | 2 +- apps/shared/values_parameter_controller.cpp | 11 ++- apps/shared/values_parameter_controller.h | 4 +- 9 files changed, 101 insertions(+), 51 deletions(-) diff --git a/apps/graph/values/values_controller.cpp b/apps/graph/values/values_controller.cpp index 5ab83ba6c..7fd051ee9 100644 --- a/apps/graph/values/values_controller.cpp +++ b/apps/graph/values/values_controller.cpp @@ -6,7 +6,7 @@ using namespace Shared; namespace Graph { ValuesController::ValuesController(Responder * parentResponder, CartesianFunctionStore * functionStore, HeaderViewController * header) : - Shared::ValuesController(parentResponder, header), + Shared::ValuesController(parentResponder, header, 'x'), m_functionTitleCells{FunctionTitleCell(FunctionTitleCell::Orientation::HorizontalIndicator, KDText::FontSize::Small), FunctionTitleCell(FunctionTitleCell::Orientation::HorizontalIndicator, KDText::FontSize::Small), FunctionTitleCell(FunctionTitleCell::Orientation::HorizontalIndicator, KDText::FontSize::Small), FunctionTitleCell(FunctionTitleCell::Orientation::HorizontalIndicator, KDText::FontSize::Small), FunctionTitleCell(FunctionTitleCell::Orientation::HorizontalIndicator, KDText::FontSize::Small)}, m_functionStore(functionStore), diff --git a/apps/sequence/sequence.cpp b/apps/sequence/sequence.cpp index 2c2cc51fa..641c7fe0e 100644 --- a/apps/sequence/sequence.cpp +++ b/apps/sequence/sequence.cpp @@ -1,7 +1,7 @@ #include "sequence.h" #include "local_context.h" -#include "../../poincare/src/layout/baseline_relative_layout.h" #include "../../poincare/src/layout/string_layout.h" +#include "../../poincare/src/layout/baseline_relative_layout.h" #include using namespace Shared; @@ -18,6 +18,7 @@ Sequence::Sequence(const char * text, KDColor color) : m_secondInitialConditionExpression(nullptr), m_firstInitialConditionLayout(nullptr), m_secondInitialConditionLayout(nullptr), + m_nameLayout(nullptr), m_definitionName(nullptr), m_firstInitialConditionName(nullptr), m_secondInitialConditionName(nullptr) @@ -42,6 +43,10 @@ Sequence::~Sequence() { delete m_secondInitialConditionExpression; m_secondInitialConditionExpression = nullptr; } + if (m_nameLayout != nullptr) { + delete m_nameLayout; + m_nameLayout = nullptr; + } if (m_definitionName != nullptr) { delete m_definitionName; m_definitionName = nullptr; @@ -70,6 +75,10 @@ Sequence::Type Sequence::type() { void Sequence::setType(Type type) { m_type = type; + if (m_nameLayout != nullptr) { + delete m_nameLayout; + m_nameLayout = nullptr; + } if (m_definitionName != nullptr) { delete m_definitionName; m_definitionName = nullptr; @@ -82,6 +91,7 @@ void Sequence::setType(Type type) { delete m_secondInitialConditionName; m_secondInitialConditionName = nullptr; } + m_nameLayout = new BaselineRelativeLayout(new StringLayout(name(), 1), new StringLayout("n", 1, KDText::FontSize::Small), BaselineRelativeLayout::Type::Subscript); if (m_type == Type::Explicite) { m_definitionName = new BaselineRelativeLayout(new StringLayout(name(), 1), new StringLayout("n", 1, KDText::FontSize::Small), BaselineRelativeLayout::Type::Subscript); } @@ -150,6 +160,10 @@ int Sequence::numberOfElements() { return (int)m_type + 1; } +Poincare::ExpressionLayout * Sequence::nameLayout() { + return m_nameLayout; +} + Poincare::ExpressionLayout * Sequence::definitionName() { return m_definitionName; } diff --git a/apps/sequence/sequence.h b/apps/sequence/sequence.h index 95caa4ca1..55610f0f2 100644 --- a/apps/sequence/sequence.h +++ b/apps/sequence/sequence.h @@ -25,6 +25,7 @@ public: void setFirstInitialConditionContent(const char * c); void setSecondInitialConditionContent(const char * c); int numberOfElements(); + Poincare::ExpressionLayout * nameLayout(); Poincare::ExpressionLayout * definitionName(); Poincare::ExpressionLayout * firstInitialConditionName(); Poincare::ExpressionLayout * secondInitialConditionName(); @@ -40,6 +41,7 @@ private: Poincare::Expression * m_secondInitialConditionExpression; Poincare::ExpressionLayout * m_firstInitialConditionLayout; Poincare::ExpressionLayout * m_secondInitialConditionLayout; + Poincare::ExpressionLayout * m_nameLayout; Poincare::ExpressionLayout * m_definitionName; Poincare::ExpressionLayout * m_firstInitialConditionName; Poincare::ExpressionLayout * m_secondInitialConditionName; diff --git a/apps/sequence/values/values_controller.cpp b/apps/sequence/values/values_controller.cpp index 508e7ea78..010c69040 100644 --- a/apps/sequence/values/values_controller.cpp +++ b/apps/sequence/values/values_controller.cpp @@ -1,52 +1,71 @@ #include "values_controller.h" +#include + +using namespace Shared; namespace Sequence { -ValuesController::ValuesController(Responder * parentResponder, SequenceStore * sequenceStore, - HeaderViewController * header) : - ViewController(parentResponder), - HeaderViewDelegate(header), - m_view(SolidColorView(KDColorRed)), - m_sequenceStore(sequenceStore) +ValuesController::ValuesController(Responder * parentResponder, SequenceStore * sequenceStore, HeaderViewController * header) : + Shared::ValuesController(parentResponder, header, 'n'), + m_sequenceTitleCells{SequenceTitleCell(FunctionTitleCell::Orientation::HorizontalIndicator), SequenceTitleCell(FunctionTitleCell::Orientation::HorizontalIndicator), + SequenceTitleCell(FunctionTitleCell::Orientation::HorizontalIndicator)}, + m_sequenceStore(sequenceStore), + m_sequenceParameterController(Shared::ValuesFunctionParameterController('n')) { } - -const char * ValuesController::title() const { - return "Valeurs"; + +int ValuesController::numberOfColumns() { + return m_sequenceStore->numberOfActiveFunctions()+1; } -View * ValuesController::view() { - return &m_view; -} - -void ValuesController::didBecomeFirstResponder() { - headerViewController()->setSelectedButton(-1); -} - -int ValuesController::numberOfButtons() const { - return 0; -} - -Button * ValuesController::buttonAtIndex(int index) { - return nullptr; -} - -bool ValuesController::isEmpty() const { - if (m_sequenceStore->numberOfActiveFunctions() == 0) { - return true; +void ValuesController::willDisplayCellAtLocation(HighlightCell * cell, int i, int j) { + Shared::ValuesController::willDisplayCellAtLocation(cell, i, j); + // The cell is the abscissa title cell: + if (j == 0 && i == 0) { + EvenOddPointerTextCell * mytitleCell = (EvenOddPointerTextCell *)cell; + mytitleCell->setText("n"); + return; + } + // The cell is a function title cell: + if (j == 0 && i > 0) { + SequenceTitleCell * myCell = (SequenceTitleCell *)cell; + Sequence * sequence = m_sequenceStore->activeFunctionAtIndex(i-1); + myCell->setExpression(sequence->nameLayout()); + myCell->setColor(sequence->color()); } - return false; } const char * ValuesController::emptyMessage() { if (m_sequenceStore->numberOfDefinedFunctions() == 0) { - return "Aucune fonction"; + return "Aucune suite"; } - return "Aucune fonction selectionnee"; + return "Aucune suite selectionnee"; } -Responder * ValuesController::defaultController() { - return (parentResponder()->parentResponder()->parentResponder()->parentResponder()); +int ValuesController::maxNumberOfCells() { + return k_maxNumberOfCells; +} + +int ValuesController::maxNumberOfFunctions() { + return k_maxNumberOfSequences; +} + +SequenceTitleCell * ValuesController::functionTitleCells(int j) { + assert(j >= 0 && j < k_maxNumberOfSequences); + return &m_sequenceTitleCells[j]; +} + +EvenOddBufferTextCell * ValuesController::floatCells(int j) { + assert(j >= 0 && j < k_maxNumberOfCells); + return &m_floatCells[j]; +} + +SequenceStore * ValuesController::functionStore() const { + return m_sequenceStore; +} + +Shared::ValuesFunctionParameterController * ValuesController::functionParameterController() { + return &m_sequenceParameterController; } } diff --git a/apps/sequence/values/values_controller.h b/apps/sequence/values/values_controller.h index 8951eee5b..8936856fb 100644 --- a/apps/sequence/values/values_controller.h +++ b/apps/sequence/values/values_controller.h @@ -1,25 +1,31 @@ #ifndef SEQUENCE_VALUES_CONTROLLER_H #define SEQUENCE_VALUES_CONTROLLER_H -#include #include "../sequence_store.h" +#include "../sequence_title_cell.h" +#include "../../shared/values_controller.h" namespace Sequence { -class ValuesController : public ViewController, public HeaderViewDelegate, public AlternateEmptyViewDelegate { +class ValuesController : public Shared::ValuesController { public: ValuesController(Responder * parentResponder, SequenceStore * sequenceStore, HeaderViewController * header); - const char * title() const override; - View * view() override; - void didBecomeFirstResponder() override; - int numberOfButtons() const override; - Button * buttonAtIndex(int index) override; - bool isEmpty() const override; + int numberOfColumns() override; + void willDisplayCellAtLocation(HighlightCell * cell, int i, int j) override; const char * emptyMessage() override; - Responder * defaultController() override; private: - SolidColorView m_view; + int maxNumberOfCells() override; + int maxNumberOfFunctions() override; + constexpr static int k_maxNumberOfCells = 30; + constexpr static int k_maxNumberOfSequences = 3; + SequenceTitleCell m_sequenceTitleCells[k_maxNumberOfSequences]; + SequenceTitleCell * functionTitleCells(int j) override; + EvenOddBufferTextCell m_floatCells[k_maxNumberOfCells]; + EvenOddBufferTextCell * floatCells(int j) override; SequenceStore * m_sequenceStore; + SequenceStore * functionStore() const override; + Shared::ValuesFunctionParameterController m_sequenceParameterController; + Shared::ValuesFunctionParameterController * functionParameterController() override; }; } diff --git a/apps/shared/values_controller.cpp b/apps/shared/values_controller.cpp index e4a38e556..8a9e481de 100644 --- a/apps/shared/values_controller.cpp +++ b/apps/shared/values_controller.cpp @@ -8,7 +8,7 @@ using namespace Poincare; namespace Shared { -ValuesController::ValuesController(Responder * parentResponder, HeaderViewController * header) : +ValuesController::ValuesController(Responder * parentResponder, HeaderViewController * header, char symbol) : EditableCellTableViewController(parentResponder, k_topMargin, k_rightMargin, k_bottomMargin, k_leftMargin), HeaderViewDelegate(header), m_abscissaTitleCell(EvenOddPointerTextCell(KDText::FontSize::Small)), @@ -16,7 +16,7 @@ ValuesController::ValuesController(Responder * parentResponder, HeaderViewContro EvenOddEditableTextCell(&m_selectableTableView, this, m_draftTextBuffer, KDText::FontSize::Small), EvenOddEditableTextCell(&m_selectableTableView, this, m_draftTextBuffer, KDText::FontSize::Small), EvenOddEditableTextCell(&m_selectableTableView, this, m_draftTextBuffer, KDText::FontSize::Small), EvenOddEditableTextCell(&m_selectableTableView, this, m_draftTextBuffer, KDText::FontSize::Small), EvenOddEditableTextCell(&m_selectableTableView, this, m_draftTextBuffer, KDText::FontSize::Small), EvenOddEditableTextCell(&m_selectableTableView, this, m_draftTextBuffer, KDText::FontSize::Small)}, m_intervalParameterController(IntervalParameterController(this, &m_interval)), - m_abscissaParameterController(ValuesParameterController(this, &m_intervalParameterController)), + m_abscissaParameterController(ValuesParameterController(this, &m_intervalParameterController, symbol)), m_setIntervalButton(Button(this, "Regler l'intervalle",Invocation([](void * context, void * sender) { ValuesController * valuesController = (ValuesController *) context; StackViewController * stack = ((StackViewController *)valuesController->stackController()); diff --git a/apps/shared/values_controller.h b/apps/shared/values_controller.h index 6b139fb55..f3339f0ac 100644 --- a/apps/shared/values_controller.h +++ b/apps/shared/values_controller.h @@ -14,7 +14,7 @@ namespace Shared { class ValuesController : public EditableCellTableViewController, public HeaderViewDelegate, public AlternateEmptyViewDelegate { public: - ValuesController(Responder * parentResponder, HeaderViewController * header); + ValuesController(Responder * parentResponder, HeaderViewController * header, char symbol); const char * title() const override; Interval * interval(); virtual bool handleEvent(Ion::Events::Event event) override; diff --git a/apps/shared/values_parameter_controller.cpp b/apps/shared/values_parameter_controller.cpp index e811955ce..4aace8041 100644 --- a/apps/shared/values_parameter_controller.cpp +++ b/apps/shared/values_parameter_controller.cpp @@ -3,8 +3,9 @@ namespace Shared { -ValuesParameterController::ValuesParameterController(Responder * parentResponder, IntervalParameterController * intervalParameterController) : +ValuesParameterController::ValuesParameterController(Responder * parentResponder, IntervalParameterController * intervalParameterController, char symbol) : ViewController(parentResponder), + m_pageTitle("Colonne 0"), m_deleteColumn(PointerTableCell((char*)"Effacer la colonne")), m_copyColumn(PointerTableCellWithChevron((char*)"Copier la colonne dans une liste")), m_setInterval(PointerTableCellWithChevron((char*)"Regler l'intervalle")), @@ -12,10 +13,16 @@ ValuesParameterController::ValuesParameterController(Responder * parentResponder Metric::CommonBottomMargin, Metric::CommonLeftMargin)), m_intervalParameterController(intervalParameterController) { + for (int currentChar = 0; currentChar < k_maxNumberOfCharsInTitle; currentChar++) { + if (m_pageTitle[currentChar] == ' ') { + m_pageTitle[currentChar+1] = symbol; + return; + } + } } const char * ValuesParameterController::title() const { - return "Colonne x"; + return m_pageTitle; } View * ValuesParameterController::view() { diff --git a/apps/shared/values_parameter_controller.h b/apps/shared/values_parameter_controller.h index 7ba831b58..45148814e 100644 --- a/apps/shared/values_parameter_controller.h +++ b/apps/shared/values_parameter_controller.h @@ -7,7 +7,7 @@ namespace Shared { class ValuesParameterController : public ViewController, public SimpleListViewDataSource { public: - ValuesParameterController(Responder * parentResponder, IntervalParameterController * intervalParameterController); + ValuesParameterController(Responder * parentResponder, IntervalParameterController * intervalParameterController, char symbol); View * view() override; const char * title() const override; @@ -19,6 +19,8 @@ public: int reusableCellCount() override; private: constexpr static int k_totalNumberOfCell = 3; + constexpr static int k_maxNumberOfCharsInTitle = 10; + char m_pageTitle[10]; PointerTableCell m_deleteColumn; PointerTableCellWithChevron m_copyColumn; PointerTableCellWithChevron m_setInterval;