diff --git a/apps/Makefile b/apps/Makefile index b3447cef6..cd94ef936 100644 --- a/apps/Makefile +++ b/apps/Makefile @@ -13,8 +13,10 @@ app_objs += $(addprefix apps/,\ node_list_view_controller.o\ node_navigation_controller.o\ toolbox_controller.o\ + toolbox_leaf_cell.o\ toolbox_node.o\ variable_box_controller.o\ + variable_box_leaf_cell.o\ variable_box_node.o\ ) diff --git a/apps/graph/list/function_expression_view.cpp b/apps/graph/list/function_expression_view.cpp index fda097910..aab6de58c 100644 --- a/apps/graph/list/function_expression_view.cpp +++ b/apps/graph/list/function_expression_view.cpp @@ -22,7 +22,7 @@ void FunctionExpressionView::reloadCell() { m_expressionView.setBackgroundColor(backgroundColor()); if (m_function) { bool active = m_function->isActive(); - KDColor textColor = active ? KDColorBlack : Palette::k_desactiveTextColor; + KDColor textColor = active ? KDColorBlack : Palette::DesactiveTextColor; m_expressionView.setTextColor(textColor); } } diff --git a/apps/graph/list/list_controller.cpp b/apps/graph/list/list_controller.cpp index 6c193bfb9..48fc067ca 100644 --- a/apps/graph/list/list_controller.cpp +++ b/apps/graph/list/list_controller.cpp @@ -225,7 +225,7 @@ void ListController::willDisplayCellAtLocation(TableViewCell * cell, int i, int char bufferName[5] = "*(x)"; bufferName[0] = *function->name(); myFunctionCell->setText(bufferName); - KDColor functionNameColor = function->isActive() ? function->color() : Palette::k_desactiveTextColor; + KDColor functionNameColor = function->isActive() ? function->color() : Palette::DesactiveTextColor; myFunctionCell->setColor(functionNameColor); myFunctionCell->setOrientation(FunctionTitleCell::Orientation::VerticalIndicator); } else { diff --git a/apps/node.cpp b/apps/node.cpp index cd26dc8d9..332d87e14 100644 --- a/apps/node.cpp +++ b/apps/node.cpp @@ -1,6 +1,6 @@ #include "node.h" -int Node::numberOfChildren() { +int Node::numberOfChildren() const { return m_numberOfChildren; } @@ -8,6 +8,6 @@ const char * Node::label() const { return m_label; } -bool Node::isNull() { +bool Node::isNull() const { return (m_label == nullptr); } diff --git a/apps/node.h b/apps/node.h index d604de226..0c6394c3b 100644 --- a/apps/node.h +++ b/apps/node.h @@ -10,8 +10,8 @@ public: }; virtual const Node * children(int index) const = 0; const char * label() const; - int numberOfChildren(); - bool isNull(); + int numberOfChildren() const; + bool isNull() const; protected: const char * m_label; int m_numberOfChildren; diff --git a/apps/node_list_view_controller.cpp b/apps/node_list_view_controller.cpp index 6637d89e9..c147a1933 100644 --- a/apps/node_list_view_controller.cpp +++ b/apps/node_list_view_controller.cpp @@ -3,8 +3,9 @@ #include #include -NodeListViewController::NodeListViewController(Responder * parentResponder) : - ViewController(parentResponder), +NodeListViewController::NodeListViewController(NodeNavigationController * parent) : + ViewController(parent), + m_nodeNavigationController(parent), m_selectableTableView(SelectableTableView(this, this)), m_nodeModel(nullptr), m_firstSelectedRow(0) @@ -63,9 +64,9 @@ TableViewCell * NodeListViewController::reusableCell(int index, int type) { assert(index >= 0); assert(index < k_maxNumberOfDisplayedRows); if (type == 0) { - return &m_commandCells[index]; + return m_nodeNavigationController->leafCellAtIndex(index); } - return &m_menuCells[index]; + return m_nodeNavigationController->nodeCellAtIndex(index); } int NodeListViewController::reusableCellCount(int type) { @@ -74,8 +75,7 @@ int NodeListViewController::reusableCellCount(int type) { } void NodeListViewController::willDisplayCellForIndex(TableViewCell * cell, int index) { - MenuListCell * myCell = (MenuListCell *)cell; - myCell->setText(m_nodeModel->children(index)->label()); + m_nodeNavigationController->willDisplayCellForIndex(cell, index); } KDCoordinate NodeListViewController::rowHeight(int j) { diff --git a/apps/node_list_view_controller.h b/apps/node_list_view_controller.h index 6d1e2820b..98818e647 100644 --- a/apps/node_list_view_controller.h +++ b/apps/node_list_view_controller.h @@ -8,9 +8,11 @@ * where we are located. It enables to know which rows are leaves and which are * subtrees. */ +class NodeNavigationController; + class NodeListViewController : public ViewController, public ListViewDataSource { public: - NodeListViewController(Responder * parentResponder); + NodeListViewController(NodeNavigationController * parent); View * view() override; const char * title() const override; void didBecomeFirstResponder() override; @@ -31,12 +33,11 @@ public: void setVerticalScroll(KDCoordinate verticalScroll); KDCoordinate verticalScroll(); void deselectTable(); -private: constexpr static int k_maxNumberOfDisplayedRows = 6; //240/40 +private: constexpr static KDCoordinate k_leafRowHeight = 50; constexpr static KDCoordinate k_nodeRowHeight = 40; - MenuListCell m_commandCells[k_maxNumberOfDisplayedRows]; - ChevronMenuListCell m_menuCells[k_maxNumberOfDisplayedRows]; + NodeNavigationController * m_nodeNavigationController; SelectableTableView m_selectableTableView; Node * m_nodeModel; int m_firstSelectedRow; diff --git a/apps/node_navigation_controller.cpp b/apps/node_navigation_controller.cpp index 8e98d6548..0b08f38f4 100644 --- a/apps/node_navigation_controller.cpp +++ b/apps/node_navigation_controller.cpp @@ -65,7 +65,7 @@ void NodeNavigationController::Stack::resetStack() { /* NodeNavigationController */ NodeNavigationController::NodeNavigationController() : - StackViewController(nullptr, &m_listViewController, true), + StackViewController(nullptr, &m_listViewController, true, KDColorWhite, Palette::BoxTitleBackgroundColor, Palette::BoxTitleBackgroundColor), m_listViewController(NodeListViewController(this)) { } @@ -131,3 +131,6 @@ void NodeNavigationController::didBecomeFirstResponder() { void NodeNavigationController::setTextFieldCaller(TextField * textField) { m_textFieldCaller = textField; } + +void NodeNavigationController::willDisplayCellForIndex(TableViewCell * cell, int index) { +} diff --git a/apps/node_navigation_controller.h b/apps/node_navigation_controller.h index ba96e9447..fb3d020c6 100644 --- a/apps/node_navigation_controller.h +++ b/apps/node_navigation_controller.h @@ -12,6 +12,9 @@ public: bool handleEvent(Ion::Events::Event event) override; void didBecomeFirstResponder() override; void setTextFieldCaller(TextField * textField); + virtual TableViewCell * leafCellAtIndex(int index) = 0; + virtual TableViewCell * nodeCellAtIndex(int index) = 0; + virtual void willDisplayCellForIndex(TableViewCell * cell, int index); protected: TextField * m_textFieldCaller; NodeListViewController m_listViewController; diff --git a/apps/toolbox_controller.cpp b/apps/toolbox_controller.cpp index 5e18f1c7d..68e314505 100644 --- a/apps/toolbox_controller.cpp +++ b/apps/toolbox_controller.cpp @@ -6,16 +6,16 @@ * and the text which would be edited by clicking on the row. When the node is a * subtree, the edited text is set at nullptr. */ -const ToolboxNode calculChildren[4] = {ToolboxNode("Nombre derivee", "diff(,)"), ToolboxNode("Integrale", "Int(,,)"), ToolboxNode("Somme", "sum(,,)"), ToolboxNode("Produit", "Product(,,)")}; -const ToolboxNode complexChildren[5] = {ToolboxNode("Module", "abs()"), ToolboxNode("Argument", "arg()"), ToolboxNode("Partie reelle", "re()"), ToolboxNode("Partie imaginaire", "im()"), ToolboxNode("Conjugue", "conj()")}; -const ToolboxNode probabilityChildren[4] = {ToolboxNode("Combinaison", "binomial()"), ToolboxNode("Arrangement", "permute(,)"), ToolboxNode("Nombre aleatoire", "random(,)"), ToolboxNode("Fonction gamma", "gamma()")}; -const ToolboxNode arithmeticChildren[4] = {ToolboxNode("PGCD", "gcd()"), ToolboxNode("PPCM","lcm()"), ToolboxNode("Reste division euclidienne", "rem()"), ToolboxNode("Quotien division euclidienne", "quo()")}; -const ToolboxNode matricesChildren[5] = {ToolboxNode("Inverse", "inverse()"), ToolboxNode("Determinant", "det()"), ToolboxNode("Transposee", "transpose()"), ToolboxNode("Trace", "trace()"), ToolboxNode("Taille", "dim()")}; -const ToolboxNode listesChildren[5] = {ToolboxNode("Tri croissant", "sort<()"), ToolboxNode("Tri decroissant", "sort>()"), ToolboxNode("Maximum", "max()"), ToolboxNode("Minimum", "min()"), ToolboxNode("Taille", "dim()")}; -const ToolboxNode approximationChildren[4] = {ToolboxNode("Partie entiere", "floor()"), ToolboxNode("Partie fractionnaire", "frac()"), ToolboxNode("Plafond", "ceil()"), ToolboxNode("Arrondi", "round(,)")}; -const ToolboxNode trigonometryChildren[6] = {ToolboxNode("cosh", "cosh()"), ToolboxNode("sinh", "sinh()"), ToolboxNode("tanh", "tanh()"), ToolboxNode("acosh", "acosh()"), ToolboxNode("asinh", "asinh()"), ToolboxNode("atanh", "atanh()")}; +const ToolboxNode calculChildren[4] = {ToolboxNode("diff(,)", "Nombre derivee"), ToolboxNode("Int(,,)", "Integrale"), ToolboxNode("sum(,,)", "Somme"), ToolboxNode("Product(,,)", "Produit")}; +const ToolboxNode complexChildren[5] = {ToolboxNode("abs()", "Module"), ToolboxNode("arg()", "Argument"), ToolboxNode("re()", "Partie reelle"), ToolboxNode("im()", "Partie imaginaire"), ToolboxNode("conj()", "Conjugue")}; +const ToolboxNode probabilityChildren[4] = {ToolboxNode("binomial()", "Combinaison"), ToolboxNode("permute(,)", "Arrangement"), ToolboxNode("random(,)", "Nombre aleatoire"), ToolboxNode("gamma()", "Fonction gamma")}; +const ToolboxNode arithmeticChildren[4] = {ToolboxNode("gcd()", "PGCD"), ToolboxNode("lcm()", "PPCM"), ToolboxNode("rem()", "Reste division euclidienne"), ToolboxNode("quo()","Quotien division euclidienne")}; +const ToolboxNode matricesChildren[5] = {ToolboxNode("inverse()", "Inverse"), ToolboxNode("det()", "Determinant"), ToolboxNode("transpose()", "Transposee"), ToolboxNode("trace()", "Trace"), ToolboxNode("dim()", "Taille")}; +const ToolboxNode listesChildren[5] = {ToolboxNode("sort<()", "Tri croissant"), ToolboxNode("sort>()", "Tri decroissant"), ToolboxNode("max()", "Maximum"), ToolboxNode("min()", "Minimum"), ToolboxNode("dim()", "Taille")}; +const ToolboxNode approximationChildren[4] = {ToolboxNode("floor()", "Partie entiere"), ToolboxNode("frac()", "Partie fractionnaire"), ToolboxNode("ceil()", "Plafond"), ToolboxNode("round(,)", "Arrondi")}; +const ToolboxNode trigonometryChildren[6] = {ToolboxNode("cosh()", "cosh"), ToolboxNode("sinh()", "sinh"), ToolboxNode("tanh()", "tanh"), ToolboxNode("acosh()", "acosh"), ToolboxNode("asinh()", "asinh"), ToolboxNode("atanh()", "atanh")}; -const ToolboxNode menu[11] = {ToolboxNode("|x|", "abs()"), ToolboxNode("root(x)", "root(,)"), ToolboxNode("log(x)", "log(,)"), +const ToolboxNode menu[11] = {ToolboxNode("abs()", "Valeur absolue"), ToolboxNode("root(,)", "Nombre derivee"), ToolboxNode("log(,)", "Logarithme base a"), ToolboxNode("Calcul", nullptr, calculChildren, 4), ToolboxNode("Nombre complexe", nullptr, complexChildren, 5), ToolboxNode("Probabilite", nullptr, probabilityChildren, 4), ToolboxNode("Arithmetique", nullptr, arithmeticChildren, 4), ToolboxNode("Matrice", nullptr, matricesChildren, 5), ToolboxNode("Liste", nullptr, listesChildren, 5), @@ -26,6 +26,26 @@ const char * ToolboxController::title() const { return "ToolboxController"; } +TableViewCell * ToolboxController::leafCellAtIndex(int index) { + return &m_leafCells[index]; +} + +TableViewCell * ToolboxController::nodeCellAtIndex(int index) { + return & m_nodeCells[index]; +} + +void ToolboxController::willDisplayCellForIndex(TableViewCell * cell, int index) { + ToolboxNode * node = (ToolboxNode *)m_listViewController.nodeModel()->children(index); + if (node->numberOfChildren() == 0) { + ToolboxLeafCell * myCell = (ToolboxLeafCell *)cell; + myCell->setLabel(node->label()); + myCell->setSubtitle(node->text()); + return; + } + MenuListCell * myCell = (MenuListCell *)cell; + myCell->setText(node->label()); +} + Node * ToolboxController::nodeModel() { return (Node *)&toolboxModel; } @@ -33,7 +53,7 @@ Node * ToolboxController::nodeModel() { bool ToolboxController::selectLeaf(Node * selectedNode){ m_listViewController.deselectTable(); ToolboxNode * node = (ToolboxNode *)selectedNode; - const char * editedText = node->text(); + const char * editedText = node->label(); m_textFieldCaller->appendText(editedText); int cursorPosition = 0; int editedTextLength = strlen(editedText); diff --git a/apps/toolbox_controller.h b/apps/toolbox_controller.h index a891fb571..2a36fcf13 100644 --- a/apps/toolbox_controller.h +++ b/apps/toolbox_controller.h @@ -3,11 +3,17 @@ #include #include "node_navigation_controller.h" +#include "toolbox_leaf_cell.h" class ToolboxController : public NodeNavigationController { public: const char * title() const override; + TableViewCell * leafCellAtIndex(int index) override; + TableViewCell * nodeCellAtIndex(int index) override; + void willDisplayCellForIndex(TableViewCell * cell, int index) override; private: + ToolboxLeafCell m_leafCells[NodeListViewController::k_maxNumberOfDisplayedRows]; + ChevronMenuListCell m_nodeCells[NodeListViewController::k_maxNumberOfDisplayedRows]; Node * nodeModel() override; bool selectLeaf(Node * selectedNode) override; }; diff --git a/apps/toolbox_leaf_cell.cpp b/apps/toolbox_leaf_cell.cpp new file mode 100644 index 000000000..8d0a069b3 --- /dev/null +++ b/apps/toolbox_leaf_cell.cpp @@ -0,0 +1,53 @@ +#include "toolbox_leaf_cell.h" +#include + +ToolboxLeafCell::ToolboxLeafCell() : + TableViewCell(), + m_labelView(PointerTextView(nullptr, 0, 0.5, KDColorBlack, Palette::CellBackgroundColor)), + m_subtitleView(PointerTextView(nullptr, 0, 0.5, Palette::DesactiveTextColor, Palette::CellBackgroundColor)) +{ +} + +int ToolboxLeafCell::numberOfSubviews() const { + return 2; +} + +View * ToolboxLeafCell::subviewAtIndex(int index) { + assert(index == 0 || index == 1); + if (index == 0) { + return &m_labelView; + } + return &m_subtitleView; +} + +void ToolboxLeafCell::layoutSubviews() { + KDCoordinate width = bounds().width(); + KDCoordinate height = bounds().height(); + m_labelView.setFrame(KDRect(1, 1, width-2, height/2 - 1)); + m_subtitleView.setFrame(KDRect(1, height/2, width-2, height/2 - 1)); +} + +void ToolboxLeafCell::reloadCell() { + TableViewCell::reloadCell(); + KDColor backgroundColor = isHighlighted()? Palette::FocusCellBackgroundColor : Palette::CellBackgroundColor; + m_labelView.setBackgroundColor(backgroundColor); + m_subtitleView.setBackgroundColor(backgroundColor); +} + +void ToolboxLeafCell::setLabel(const char * text) { + m_labelView.setText(text); +} + +void ToolboxLeafCell::setSubtitle(const char * text) { + m_subtitleView.setText(text); +} + +void ToolboxLeafCell::drawRect(KDContext * ctx, KDRect rect) const { + KDCoordinate width = bounds().width(); + KDCoordinate height = bounds().height(); + KDColor backgroundColor = isHighlighted() ? Palette::FocusCellBackgroundColor : Palette::CellBackgroundColor; + ctx->fillRect(KDRect(1, 0, width-2, height-1), backgroundColor); + ctx->fillRect(KDRect(0, height-1, width, 1), Palette::LineColor); + ctx->fillRect(KDRect(0, 0, 1, height-1), Palette::LineColor); + ctx->fillRect(KDRect(width-1, 0, 1, height-1), Palette::LineColor); + } diff --git a/apps/toolbox_leaf_cell.h b/apps/toolbox_leaf_cell.h new file mode 100644 index 000000000..7c8e891d6 --- /dev/null +++ b/apps/toolbox_leaf_cell.h @@ -0,0 +1,21 @@ +#ifndef APPS_TOOLBOX_LEAF_CELL_H +#define APPS_TOOLBOX_LEAF_CELL_H + +#include + +class ToolboxLeafCell : public TableViewCell { +public: + ToolboxLeafCell(); + void reloadCell() override; + void setLabel(const char * text); + void setSubtitle(const char * text); + void drawRect(KDContext * ctx, KDRect rect) const override; +private: + int numberOfSubviews() const override; + View * subviewAtIndex(int index) override; + void layoutSubviews() override; + PointerTextView m_labelView; + PointerTextView m_subtitleView; +}; + +#endif diff --git a/apps/variable_box_controller.cpp b/apps/variable_box_controller.cpp index 9f122e5a3..7bca2682f 100644 --- a/apps/variable_box_controller.cpp +++ b/apps/variable_box_controller.cpp @@ -19,6 +19,19 @@ const char * VariableBoxController::title() const { return "VariableBoxController"; } +TableViewCell * VariableBoxController::leafCellAtIndex(int index) { + return &m_leafCells[index]; +} + +TableViewCell * VariableBoxController::nodeCellAtIndex(int index) { + return &m_nodeCells[index]; +} + +void VariableBoxController::willDisplayCellForIndex(TableViewCell * cell, int index) { + MenuListCell * myCell = (MenuListCell *)cell; + myCell->setText(m_listViewController.nodeModel()->children(index)->label()); +} + Node * VariableBoxController::nodeModel() { return (Node *)&variableBoxModel; } diff --git a/apps/variable_box_controller.h b/apps/variable_box_controller.h index cc42c7274..181550206 100644 --- a/apps/variable_box_controller.h +++ b/apps/variable_box_controller.h @@ -7,7 +7,12 @@ class VariableBoxController : public NodeNavigationController { public: 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]; + ChevronMenuListCell m_nodeCells[NodeListViewController::k_maxNumberOfDisplayedRows]; Node * nodeModel() override; bool selectLeaf(Node * selectedNode) override; }; diff --git a/apps/variable_box_leaf_cell.cpp b/apps/variable_box_leaf_cell.cpp new file mode 100644 index 000000000..4a0ff0bae --- /dev/null +++ b/apps/variable_box_leaf_cell.cpp @@ -0,0 +1,70 @@ +#include "variable_box_leaf_cell.h" +#include + +VariableBoxLeafCell::VariableBoxLeafCell() : + TableViewCell(), + m_labelView(PointerTextView(nullptr, 0, 0.5, KDColorBlack, Palette::CellBackgroundColor)), + m_subtitleView(BufferTextView(0, 0.5, Palette::DesactiveTextColor, Palette::CellBackgroundColor)) +{ +} + +int VariableBoxLeafCell::numberOfSubviews() const { + if (strlen(m_subtitleView.text()) > 0) { + return 3; + } + return 2; +} + +View * VariableBoxLeafCell::subviewAtIndex(int index) { + if (index == 0) { + return &m_labelView; + } + if (index == 1) { + return &m_expressionView; + } + assert(numberOfSubviews() == 3 && index == 2); + return &m_subtitleView; +} + +void VariableBoxLeafCell::layoutSubviews() { + KDCoordinate width = bounds().width(); + KDCoordinate height = bounds().height(); + m_expressionView.setFrame(KDRect(width/2, 1, width/2-1, height-2)); + if (numberOfSubviews() == 3) { + m_labelView.setFrame(KDRect(1, 1, width/2-1, height/2 - 1)); + m_subtitleView.setFrame(KDRect(1, height/2, width/2-1, height/2 - 1)); + return; + } + m_labelView.setFrame(KDRect(1, 1, width/2-1, height-2)); +} + +void VariableBoxLeafCell::reloadCell() { + TableViewCell::reloadCell(); + KDColor backgroundColor = isHighlighted()? Palette::FocusCellBackgroundColor : Palette::CellBackgroundColor; + m_labelView.setBackgroundColor(backgroundColor); + m_subtitleView.setBackgroundColor(backgroundColor); + m_expressionView.setBackgroundColor(backgroundColor); +} + +void VariableBoxLeafCell::setLabel(const char * text) { + m_labelView.setText(text); +} + +void VariableBoxLeafCell::setSubtitle(const char * text) { + m_subtitleView.setText(text); + layoutSubviews(); +} + +void VariableBoxLeafCell::setExpression(ExpressionLayout * expressionLayout) { + m_expressionView.setExpression(expressionLayout); +} + +void VariableBoxLeafCell::drawRect(KDContext * ctx, KDRect rect) const { + KDCoordinate width = bounds().width(); + KDCoordinate height = bounds().height(); + KDColor backgroundColor = isHighlighted() ? Palette::FocusCellBackgroundColor : Palette::CellBackgroundColor; + ctx->fillRect(KDRect(1, 0, width-2, height-1), backgroundColor); + ctx->fillRect(KDRect(0, height-1, width, 1), Palette::LineColor); + ctx->fillRect(KDRect(0, 0, 1, height-1), Palette::LineColor); + ctx->fillRect(KDRect(width-1, 0, 1, height-1), Palette::LineColor); + } diff --git a/apps/variable_box_leaf_cell.h b/apps/variable_box_leaf_cell.h new file mode 100644 index 000000000..d84528487 --- /dev/null +++ b/apps/variable_box_leaf_cell.h @@ -0,0 +1,23 @@ +#ifndef APPS_VARIABLE_BOX_LEAF_CELL_H +#define APPS_VARIABLE_BOX_LEAF_CELL_H + +#include + +class VariableBoxLeafCell : public TableViewCell { +public: + VariableBoxLeafCell(); + void reloadCell() override; + void setLabel(const char * text); + void setSubtitle(const char * text); + void setExpression(ExpressionLayout * expressionLayout); + void drawRect(KDContext * ctx, KDRect rect) const override; +private: + int numberOfSubviews() const override; + View * subviewAtIndex(int index) override; + void layoutSubviews() override; + PointerTextView m_labelView; + BufferTextView m_subtitleView; + ExpressionView m_expressionView; +}; + +#endif diff --git a/escher/include/escher/palette.h b/escher/include/escher/palette.h index 50e18627a..7158205f9 100644 --- a/escher/include/escher/palette.h +++ b/escher/include/escher/palette.h @@ -9,7 +9,8 @@ public: constexpr static KDColor BackgroundColor = KDColor(0xF0F3F5); constexpr static KDColor CellBackgroundColor = KDColor(0xFCFCFC); constexpr static KDColor FocusCellBackgroundColor = KDColor(0xBFD3EB); - constexpr static KDColor k_desactiveTextColor = KDColor(0x646464); + constexpr static KDColor DesactiveTextColor = KDColor(0x646464); + constexpr static KDColor BoxTitleBackgroundColor = KDColor(0x656976); }; #endif \ No newline at end of file diff --git a/escher/include/escher/stack_view.h b/escher/include/escher/stack_view.h index fa4201107..f13951a91 100644 --- a/escher/include/escher/stack_view.h +++ b/escher/include/escher/stack_view.h @@ -2,19 +2,28 @@ #define ESCHER_STACK_VIEW_H #include +#include class StackView : public View { public: StackView(); void drawRect(KDContext * ctx, KDRect rect) const override; void setName(const char * name); + void setTextColor(KDColor textColor); + void setBackgroundColor(KDColor backgroundColor); + void setSeparatorColor(KDColor separatorColor); protected: #if ESCHER_VIEW_LOGGING const char * className() const override; void logAttributes(std::ostream &os) const override; #endif private: - const char * m_name; + KDColor m_backgroundColor; + KDColor m_separatorColor; + int numberOfSubviews() const override; + View * subviewAtIndex(int index) override; + void layoutSubviews() override; + PointerTextView m_textView; }; #endif diff --git a/escher/include/escher/stack_view_controller.h b/escher/include/escher/stack_view_controller.h index bfa53facf..5c8439075 100644 --- a/escher/include/escher/stack_view_controller.h +++ b/escher/include/escher/stack_view_controller.h @@ -3,12 +3,14 @@ #include #include +#include constexpr uint8_t kMaxNumberOfStacks = 4; class StackViewController : public ViewController { public: - StackViewController(Responder * parentResponder, ViewController * rootViewController, bool displayFirstStackHeader = false); + StackViewController(Responder * parentResponder, ViewController * rootViewController, bool displayFirstStackHeader = false, + KDColor textColor = Palette::DesactiveTextColor, KDColor backgroundColor = KDColorWhite, KDColor separatorColor = Palette::LineColor); /* Push creates a new StackView and adds it */ void push(ViewController * vc); @@ -22,7 +24,7 @@ public: private: class ControllerView : public View { public: - ControllerView(bool displayFirstStackHeader); + ControllerView(bool displayFirstStackHeader, KDColor textColor, KDColor backgroundColor, KDColor separatorColor); void setContentView(View * view); void pushStack(const char * name); void popStack(); @@ -39,6 +41,9 @@ private: View * m_contentView; int8_t m_numberOfStacks; bool m_displayFirstStackHeader; + KDColor m_textColor; + KDColor m_backgroundColor; + KDColor m_separatorColor; }; ControllerView m_view; diff --git a/escher/include/escher/text_menu_list_cell.h b/escher/include/escher/text_menu_list_cell.h index 88e3a33d8..dea51dacf 100644 --- a/escher/include/escher/text_menu_list_cell.h +++ b/escher/include/escher/text_menu_list_cell.h @@ -6,7 +6,7 @@ class TextMenuListCell : public MenuListCell { public: - TextMenuListCell(char * label); + TextMenuListCell(char * label = nullptr); void reloadCell() override; View * accessoryView() const override; void setHighlighted(bool highlight); diff --git a/escher/src/palette.cpp b/escher/src/palette.cpp index 84e87ee6e..56e3c6868 100644 --- a/escher/src/palette.cpp +++ b/escher/src/palette.cpp @@ -4,4 +4,5 @@ constexpr KDColor Palette::LineColor; constexpr KDColor Palette::BackgroundColor; constexpr KDColor Palette::CellBackgroundColor; constexpr KDColor Palette::FocusCellBackgroundColor; -constexpr KDColor Palette::k_desactiveTextColor; +constexpr KDColor Palette::DesactiveTextColor; +constexpr KDColor Palette::BoxTitleBackgroundColor; diff --git a/escher/src/stack_view.cpp b/escher/src/stack_view.cpp index f9d963d61..94904e933 100644 --- a/escher/src/stack_view.cpp +++ b/escher/src/stack_view.cpp @@ -5,18 +5,46 @@ extern "C" { StackView::StackView() : View(), - m_name(nullptr) + m_textView(PointerTextView(nullptr, 0.5f, 0.5f)) { } +void StackView::setTextColor(KDColor textColor) { + m_textView.setTextColor(textColor); +} + +void StackView::setBackgroundColor(KDColor backgroundColor) { + m_textView.setBackgroundColor(backgroundColor); + m_backgroundColor = backgroundColor; +} + +void StackView::setSeparatorColor(KDColor separatorColor) { + m_separatorColor = separatorColor; +} + +int StackView::numberOfSubviews() const { + return 1; +} + +View * StackView::subviewAtIndex(int index) { + assert(index == 0); + return &m_textView; +} + +void StackView::layoutSubviews() { + m_textView.setFrame(bounds()); +} + void StackView::setName(const char * name) { - m_name = name; - markRectAsDirty(bounds()); + m_textView.setText(name); } void StackView::drawRect(KDContext * ctx, KDRect rect) const { - ctx->fillRect(rect, KDColor(0xFFCD50)); - ctx->drawString(m_name, KDPointZero); + KDCoordinate height = bounds().height(); + KDCoordinate width = bounds().width(); + ctx->fillRect(KDRect(0, 0, width, 1), m_separatorColor); + ctx->fillRect(KDRect(0, 1, width, height-2), m_backgroundColor); + ctx->fillRect(KDRect(0, height-1, width, 1), m_separatorColor); } #if ESCHER_VIEW_LOGGING diff --git a/escher/src/stack_view_controller.cpp b/escher/src/stack_view_controller.cpp index 819c61c7d..11481e2c7 100644 --- a/escher/src/stack_view_controller.cpp +++ b/escher/src/stack_view_controller.cpp @@ -4,11 +4,14 @@ extern "C" { #include #include -StackViewController::ControllerView::ControllerView(bool displayFirstStackHeader) : +StackViewController::ControllerView::ControllerView(bool displayFirstStackHeader, KDColor textColor, KDColor backgroundColor, KDColor separatorColor) : View(), m_contentView(nullptr), m_numberOfStacks(0), - m_displayFirstStackHeader(displayFirstStackHeader) + m_displayFirstStackHeader(displayFirstStackHeader), + m_textColor(textColor), + m_backgroundColor(backgroundColor), + m_separatorColor(separatorColor) { } @@ -20,6 +23,9 @@ void StackViewController::ControllerView::setContentView(View * view) { void StackViewController::ControllerView::pushStack(const char * name) { m_stackViews[m_numberOfStacks].setName(name); + m_stackViews[m_numberOfStacks].setTextColor(m_textColor); + m_stackViews[m_numberOfStacks].setBackgroundColor(m_backgroundColor); + m_stackViews[m_numberOfStacks].setSeparatorColor(m_separatorColor); m_numberOfStacks++; } @@ -33,10 +39,11 @@ void StackViewController::ControllerView::layoutSubviews() { KDCoordinate width = m_frame.width(); int indexFirstHeader = m_displayFirstStackHeader ? 0 : 1; for (int i=indexFirstHeader; i 1); + KDRect contentViewFrame = KDRect( 0, (m_numberOfStacks-indexFirstHeader)*stackHeight + separatorHeight, width, m_frame.height() - (m_numberOfStacks-indexFirstHeader)*stackHeight); m_contentView->setFrame(contentViewFrame); } @@ -62,9 +69,9 @@ const char * StackViewController::ControllerView::className() const { } #endif -StackViewController::StackViewController(Responder * parentResponder, ViewController * rootViewController, bool displayFirstStackHeader) : +StackViewController::StackViewController(Responder * parentResponder, ViewController * rootViewController, bool displayFirstStackHeader, KDColor textColor, KDColor backgroundColor, KDColor separatorColor) : ViewController(parentResponder), - m_view(ControllerView(displayFirstStackHeader)), + m_view(ControllerView(displayFirstStackHeader, textColor, backgroundColor, separatorColor)), m_numberOfChildren(0), m_rootViewController(rootViewController) { diff --git a/escher/src/text_field.cpp b/escher/src/text_field.cpp index 5c76859ff..98d50fb20 100644 --- a/escher/src/text_field.cpp +++ b/escher/src/text_field.cpp @@ -99,7 +99,7 @@ void TextField::appendText(const char * text) { if (m_currentTextLength + textSize > m_textBufferSize) { return; } - for (int k = m_currentTextLength; k > m_currentCursorPosition - 1; k--) { + for (int k = m_currentTextLength; k >= m_currentCursorPosition && k >= 0; k--) { m_textBuffer[k+textSize] = m_textBuffer[k]; } strlcpy(&m_textBuffer[m_currentCursorPosition], text, textSize);