diff --git a/apps/apps_container.cpp b/apps/apps_container.cpp index 8e9bab85f..0b014d8ca 100644 --- a/apps/apps_container.cpp +++ b/apps/apps_container.cpp @@ -9,7 +9,8 @@ AppsContainer::AppsContainer() : m_graphApp(this, &m_context), m_probabilityApp(this), m_calculationApp(this, &m_context), - m_context(Context()) + m_context(Context()), + m_variableBoxController(&m_context) { } diff --git a/apps/variable_box_controller.cpp b/apps/variable_box_controller.cpp index 7bca2682f..e4c3b21de 100644 --- a/apps/variable_box_controller.cpp +++ b/apps/variable_box_controller.cpp @@ -1,4 +1,5 @@ #include "variable_box_controller.h" +#include "constant.h" #include "variable_box_node.h" const VariableBoxNode numberChildren[10] = {VariableBoxNode("A"), VariableBoxNode("B"), VariableBoxNode("C"), @@ -14,6 +15,10 @@ const VariableBoxNode menu[3] = {VariableBoxNode("Nombres", numberChildren, 10), VariableBoxNode("Matrices", matriceChildren, 10)}; const VariableBoxNode variableBoxModel = VariableBoxNode("Variables", menu, 3); +VariableBoxController::VariableBoxController(Context * context) : + m_context(context) +{ +} const char * VariableBoxController::title() const { return "VariableBoxController"; @@ -28,8 +33,40 @@ TableViewCell * VariableBoxController::nodeCellAtIndex(int index) { } void VariableBoxController::willDisplayCellForIndex(TableViewCell * cell, int index) { - MenuListCell * myCell = (MenuListCell *)cell; - myCell->setText(m_listViewController.nodeModel()->children(index)->label()); + const Node * node = m_listViewController.nodeModel()->children(index); + const char * label = node->label(); + if (node->numberOfChildren() > 0) { + MenuListCell * myCell = (MenuListCell *)cell; + myCell->setText(label); + return; + } + const char * parentNodeLabel = m_listViewController.nodeModel()->label(); + VariableBoxLeafCell * myCell = (VariableBoxLeafCell *)cell; + myCell->setLabel(label); + const Expression * expression = m_context->scalarExpressionForIndex(index); + if (strcmp(parentNodeLabel, "Matrices") == 0) { + //expression = m_context->matrixExpressionForIndex(index); + } + if (strcmp(parentNodeLabel, "Listes") == 0) { + //expression = m_context->listExpressionForIndex(index); + } + if (expression) { + myCell->setExpression(expression->createLayout()); + } + if (strcmp(parentNodeLabel, "Nombres") == 0) { + myCell->setSubtitle(""); + } else { + if (expression == nullptr) { + myCell->setSubtitle("Vide"); + } + // TODO: display the dimension of the list/matrice + /* char buffer[4]; + * buffer[0] = (Matrice *)expression->dim(0); + * buffer[1] = 'x'; + * buffer[2] = (Matrice *)expression->dim(1) + * buffer[3] = 0; + * myCell->setSubtitle(buffer);*/ + } } Node * VariableBoxController::nodeModel() { diff --git a/apps/variable_box_controller.h b/apps/variable_box_controller.h index 181550206..ebbd03785 100644 --- a/apps/variable_box_controller.h +++ b/apps/variable_box_controller.h @@ -2,16 +2,20 @@ #define APPS_VARIABLE_BOX_CONTROLLER_H #include +#include #include "node_navigation_controller.h" +#include "variable_box_leaf_cell.h" class VariableBoxController : public NodeNavigationController { public: + VariableBoxController(Context * context); const char * title() const override; TableViewCell * leafCellAtIndex(int index) override; TableViewCell * nodeCellAtIndex(int index) override; void willDisplayCellForIndex(TableViewCell * cell, int index) override; private: - MenuListCell m_leafCells[NodeListViewController::k_maxNumberOfDisplayedRows]; + Context * m_context; + VariableBoxLeafCell m_leafCells[NodeListViewController::k_maxNumberOfDisplayedRows]; ChevronMenuListCell m_nodeCells[NodeListViewController::k_maxNumberOfDisplayedRows]; Node * nodeModel() override; bool selectLeaf(Node * selectedNode) override;