diff --git a/apps/sequence/Makefile b/apps/sequence/Makefile index 11a7a5d4a..86cfb96e7 100644 --- a/apps/sequence/Makefile +++ b/apps/sequence/Makefile @@ -1,6 +1,7 @@ app_objs += $(addprefix apps/sequence/,\ app.o\ list/list_controller.o\ + list/list_parameter_controller.o\ list/type_parameter_controller.o\ list/sequence_cell.o\ list/sequence_expression_cell.o\ diff --git a/apps/sequence/list/list_parameter_controller.cpp b/apps/sequence/list/list_parameter_controller.cpp new file mode 100644 index 000000000..72212a60a --- /dev/null +++ b/apps/sequence/list/list_parameter_controller.cpp @@ -0,0 +1,69 @@ +#include "list_parameter_controller.h" +#include "../../../poincare/src/layout/baseline_relative_layout.h" +#include "../../../poincare/src/layout/string_layout.h" + +using namespace Poincare; +using namespace Shared; + +namespace Sequence { + +ListParameterController::ListParameterController(Responder * parentResponder, SequenceStore * sequenceStore) : + Shared::ListParameterController(parentResponder, sequenceStore), + m_typeCell(ChevronExpressionMenuListCell((char *)"Type de suite")), + m_sequence(nullptr) +{ +} + +ListParameterController::~ListParameterController() { + if (m_typeLayout) { + delete m_typeLayout; + } +} +const char * ListParameterController::title() const { + return "Options de la suite"; +} + +void ListParameterController::setSequence(Sequence * sequence) { + setFunction(sequence); + m_sequence = sequence; + if (m_typeLayout != nullptr) { + delete m_typeLayout; + } + if (m_sequence->type() == Sequence::Type::Explicite) { + m_typeLayout = new BaselineRelativeLayout(new StringLayout(m_sequence->name(), 1), new StringLayout("n", 1, KDText::FontSize::Small), BaselineRelativeLayout::Type::Subscript); + } + if (m_sequence->type() == Sequence::Type::SingleRecurrence) { + m_typeLayout = new BaselineRelativeLayout(new StringLayout(m_sequence->name(), 1), new StringLayout("n+1", 3, KDText::FontSize::Small), BaselineRelativeLayout::Type::Subscript); + } + if (m_sequence->type() == Sequence::Type::DoubleRecurrence) { + m_typeLayout = new BaselineRelativeLayout(new StringLayout(m_sequence->name(), 1), new StringLayout("n+2", 3, KDText::FontSize::Small), BaselineRelativeLayout::Type::Subscript); + } + m_typeCell.setExpression(m_typeLayout); +} + +bool ListParameterController::handleEvent(Ion::Events::Event event) { + if (Shared::ListParameterController::handleEvent(event)) { + return true; + } + if (event == Ion::Events::OK && m_selectableTableView.selectedRow() == 4) { + return false; + } + return false; +} + +int ListParameterController::numberOfRows() { + return k_totalNumberOfCell; +}; + +TableViewCell * ListParameterController::reusableCell(int index) { + if (index == 3) { + return &m_typeCell; + } + return Shared::ListParameterController::reusableCell(index); +} + +int ListParameterController::reusableCellCount() { + return k_totalNumberOfCell; +} + +} diff --git a/apps/sequence/list/list_parameter_controller.h b/apps/sequence/list/list_parameter_controller.h new file mode 100644 index 000000000..bf3f543b8 --- /dev/null +++ b/apps/sequence/list/list_parameter_controller.h @@ -0,0 +1,29 @@ +#ifndef SEQUENCE_LIST_PARAM_CONTROLLER_H +#define SEQUENCE_LIST_PARAM_CONTROLLER_H + +#include "../../shared/list_parameter_controller.h" +#include "../sequence.h" +#include "../sequence_store.h" + +namespace Sequence { + +class ListParameterController : public Shared::ListParameterController { +public: + ListParameterController(Responder * parentResponder, SequenceStore * sequenceStore); + ~ListParameterController(); + const char * title() const override; + bool handleEvent(Ion::Events::Event event) override; + void setSequence(Sequence * sequence); + int numberOfRows() override; + TableViewCell * reusableCell(int index) override; + int reusableCellCount() override; +private: + constexpr static int k_totalNumberOfCell = 4; + ChevronExpressionMenuListCell m_typeCell; + Poincare::ExpressionLayout * m_typeLayout; + Sequence * m_sequence; +}; + +} + +#endif diff --git a/apps/shared/list_parameter_controller.cpp b/apps/shared/list_parameter_controller.cpp index 37a767fc7..df84a2612 100644 --- a/apps/shared/list_parameter_controller.cpp +++ b/apps/shared/list_parameter_controller.cpp @@ -5,11 +5,11 @@ namespace Shared { ListParameterController::ListParameterController(Responder * parentResponder, FunctionStore * functionStore) : ViewController(parentResponder), + m_selectableTableView(SelectableTableView(this, this, Metric::TopMargin, Metric::RightMargin, + Metric::BottomMargin, Metric::LeftMargin)), m_colorCell(ChevronMenuListCell((char*)"Couleur de la fonction")), m_enableCell(SwitchMenuListCell((char*)"Activer/Desactiver")), m_deleteCell(MenuListCell((char*)"Supprimer la fonction")), - m_selectableTableView(SelectableTableView(this, this, Metric::TopMargin, Metric::RightMargin, - Metric::BottomMargin, Metric::LeftMargin)), m_functionStore(functionStore) { } diff --git a/apps/shared/list_parameter_controller.h b/apps/shared/list_parameter_controller.h index f8413c1e0..831d630c1 100644 --- a/apps/shared/list_parameter_controller.h +++ b/apps/shared/list_parameter_controller.h @@ -21,12 +21,13 @@ public: TableViewCell * reusableCell(int index) override; int reusableCellCount() override; void willDisplayCellForIndex(TableViewCell * cell, int index) override; +protected: + SelectableTableView m_selectableTableView; private: constexpr static int k_totalNumberOfCell = 3; ChevronMenuListCell m_colorCell; SwitchMenuListCell m_enableCell; MenuListCell m_deleteCell; - SelectableTableView m_selectableTableView; Function * m_function; FunctionStore * m_functionStore; };