From aa60dfff39670baef191acbe30c94307d8945137 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Thu, 10 Nov 2016 17:37:21 +0100 Subject: [PATCH 01/11] [escher] add default constructor for text menu list cell Change-Id: Idadb4934d3c5db03418fd2bba2e8fa29a7d5d70b --- escher/include/escher/text_menu_list_cell.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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); From 6d880a0c4cfd87f18b908932e5a4043ae8abeb87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Thu, 10 Nov 2016 18:02:35 +0100 Subject: [PATCH 02/11] [escher] improve stack view drawing Change-Id: I76ec35c21c9d877c209ee51a4c843dbed7b773b0 --- escher/include/escher/stack_view.h | 6 +++++- escher/src/stack_view.cpp | 26 +++++++++++++++++++++----- escher/src/stack_view_controller.cpp | 5 +++-- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/escher/include/escher/stack_view.h b/escher/include/escher/stack_view.h index fa4201107..9059c3bf4 100644 --- a/escher/include/escher/stack_view.h +++ b/escher/include/escher/stack_view.h @@ -2,6 +2,7 @@ #define ESCHER_STACK_VIEW_H #include +#include class StackView : public View { public: @@ -14,7 +15,10 @@ protected: void logAttributes(std::ostream &os) const override; #endif private: - const char * m_name; + int numberOfSubviews() const override; + View * subviewAtIndex(int index) override; + void layoutSubviews() override; + PointerTextView m_textView; }; #endif diff --git a/escher/src/stack_view.cpp b/escher/src/stack_view.cpp index f9d963d61..0b56a6c3b 100644 --- a/escher/src/stack_view.cpp +++ b/escher/src/stack_view.cpp @@ -1,22 +1,38 @@ #include +#include extern "C" { #include } StackView::StackView() : View(), - m_name(nullptr) + m_textView(PointerTextView(nullptr, 0.5f, 0.5f, Palette::k_desactiveTextColor)) { } +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), Palette::LineColor); + ctx->fillRect(KDRect(0, 1, width, height-2), KDColorWhite); + ctx->fillRect(KDRect(0, height-1, width, 1), Palette::LineColor); } #if ESCHER_VIEW_LOGGING diff --git a/escher/src/stack_view_controller.cpp b/escher/src/stack_view_controller.cpp index 819c61c7d..37adfabea 100644 --- a/escher/src/stack_view_controller.cpp +++ b/escher/src/stack_view_controller.cpp @@ -33,10 +33,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); } From 9e9302b6020aa51ec6e3966fa0ccc45fe632326f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Mon, 14 Nov 2016 09:55:16 +0100 Subject: [PATCH 03/11] [escher] Correct int comparison issue in text field Change-Id: Ie70f6e9f0986909e28206747e1d7445f54b30397 --- escher/src/text_field.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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); From 41f8d0c75cd5e38be7dd6a1033f23c57fbaac55f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Mon, 14 Nov 2016 10:48:56 +0100 Subject: [PATCH 04/11] [apps] enable node navigation controller to use different cell types (implemented by its subclasses) Change-Id: I44ef187c0142f049c710a4515c3dc0edf5573927 --- apps/node_list_view_controller.cpp | 12 ++++++------ apps/node_list_view_controller.h | 9 +++++---- apps/node_navigation_controller.cpp | 3 +++ apps/node_navigation_controller.h | 3 +++ apps/toolbox_controller.cpp | 13 +++++++++++++ apps/toolbox_controller.h | 5 +++++ apps/variable_box_controller.cpp | 13 +++++++++++++ apps/variable_box_controller.h | 5 +++++ 8 files changed, 53 insertions(+), 10 deletions(-) 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..cfcefd50e 100644 --- a/apps/node_navigation_controller.cpp +++ b/apps/node_navigation_controller.cpp @@ -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..9fa26e182 100644 --- a/apps/toolbox_controller.cpp +++ b/apps/toolbox_controller.cpp @@ -26,6 +26,19 @@ 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) { + MenuListCell * myCell = (MenuListCell *)cell; + myCell->setText(m_listViewController.nodeModel()->children(index)->label()); +} + Node * ToolboxController::nodeModel() { return (Node *)&toolboxModel; } diff --git a/apps/toolbox_controller.h b/apps/toolbox_controller.h index a891fb571..8ebe7e860 100644 --- a/apps/toolbox_controller.h +++ b/apps/toolbox_controller.h @@ -7,7 +7,12 @@ 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: + 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_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; }; From c34498b15d126f3123c5b1c3dbffe26304da83bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Mon, 14 Nov 2016 11:17:06 +0100 Subject: [PATCH 05/11] [escher] Change palette names to make them consistant Change-Id: If5381b7f970e106bea1196ef40e36ea12f846dad --- apps/graph/list/function_expression_view.cpp | 2 +- apps/graph/list/list_controller.cpp | 2 +- escher/include/escher/palette.h | 2 +- escher/src/palette.cpp | 2 +- escher/src/stack_view.cpp | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) 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/escher/include/escher/palette.h b/escher/include/escher/palette.h index 50e18627a..ff49f8966 100644 --- a/escher/include/escher/palette.h +++ b/escher/include/escher/palette.h @@ -9,7 +9,7 @@ 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); }; #endif \ No newline at end of file diff --git a/escher/src/palette.cpp b/escher/src/palette.cpp index 84e87ee6e..e37babeb8 100644 --- a/escher/src/palette.cpp +++ b/escher/src/palette.cpp @@ -4,4 +4,4 @@ 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; diff --git a/escher/src/stack_view.cpp b/escher/src/stack_view.cpp index 0b56a6c3b..aaafdaf2f 100644 --- a/escher/src/stack_view.cpp +++ b/escher/src/stack_view.cpp @@ -6,7 +6,7 @@ extern "C" { StackView::StackView() : View(), - m_textView(PointerTextView(nullptr, 0.5f, 0.5f, Palette::k_desactiveTextColor)) + m_textView(PointerTextView(nullptr, 0.5f, 0.5f, Palette::DesactiveTextColor)) { } From 5b0ad58ae3f6b8353047b94dd20f42f798195d48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Mon, 14 Nov 2016 11:18:19 +0100 Subject: [PATCH 06/11] [escher] enable stack view controller to have different stack view colors Change-Id: Iea0d68fa3686c85587d35740b5c2f281c0ca3a99 --- escher/include/escher/stack_view.h | 5 +++++ escher/include/escher/stack_view_controller.h | 9 ++++++-- escher/src/stack_view.cpp | 22 ++++++++++++++----- escher/src/stack_view_controller.cpp | 14 ++++++++---- 4 files changed, 39 insertions(+), 11 deletions(-) diff --git a/escher/include/escher/stack_view.h b/escher/include/escher/stack_view.h index 9059c3bf4..f13951a91 100644 --- a/escher/include/escher/stack_view.h +++ b/escher/include/escher/stack_view.h @@ -9,12 +9,17 @@ 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: + KDColor m_backgroundColor; + KDColor m_separatorColor; int numberOfSubviews() const override; View * subviewAtIndex(int index) override; void layoutSubviews() override; 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/src/stack_view.cpp b/escher/src/stack_view.cpp index aaafdaf2f..94904e933 100644 --- a/escher/src/stack_view.cpp +++ b/escher/src/stack_view.cpp @@ -1,15 +1,27 @@ #include -#include extern "C" { #include } StackView::StackView() : View(), - m_textView(PointerTextView(nullptr, 0.5f, 0.5f, Palette::DesactiveTextColor)) + 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; } @@ -30,9 +42,9 @@ void StackView::setName(const char * name) { void StackView::drawRect(KDContext * ctx, KDRect rect) const { KDCoordinate height = bounds().height(); KDCoordinate width = bounds().width(); - ctx->fillRect(KDRect(0, 0, width, 1), Palette::LineColor); - ctx->fillRect(KDRect(0, 1, width, height-2), KDColorWhite); - ctx->fillRect(KDRect(0, height-1, width, 1), Palette::LineColor); + 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 37adfabea..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++; } @@ -63,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) { From e4cf865ddeb04d0bc880024a9f1fffbc2cf081b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Mon, 14 Nov 2016 11:19:00 +0100 Subject: [PATCH 07/11] [apps] Improve the drawing of boxes (variable and toolbox) Change-Id: If5cc51c33e994b09cea9c873502e238c28a43608 --- apps/node_navigation_controller.cpp | 2 +- escher/include/escher/palette.h | 1 + escher/src/palette.cpp | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/node_navigation_controller.cpp b/apps/node_navigation_controller.cpp index cfcefd50e..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)) { } diff --git a/escher/include/escher/palette.h b/escher/include/escher/palette.h index ff49f8966..7158205f9 100644 --- a/escher/include/escher/palette.h +++ b/escher/include/escher/palette.h @@ -10,6 +10,7 @@ public: constexpr static KDColor CellBackgroundColor = KDColor(0xFCFCFC); constexpr static KDColor FocusCellBackgroundColor = KDColor(0xBFD3EB); constexpr static KDColor DesactiveTextColor = KDColor(0x646464); + constexpr static KDColor BoxTitleBackgroundColor = KDColor(0x656976); }; #endif \ No newline at end of file diff --git a/escher/src/palette.cpp b/escher/src/palette.cpp index e37babeb8..56e3c6868 100644 --- a/escher/src/palette.cpp +++ b/escher/src/palette.cpp @@ -5,3 +5,4 @@ constexpr KDColor Palette::BackgroundColor; constexpr KDColor Palette::CellBackgroundColor; constexpr KDColor Palette::FocusCellBackgroundColor; constexpr KDColor Palette::DesactiveTextColor; +constexpr KDColor Palette::BoxTitleBackgroundColor; From 0df7d64dcec433598df689a060872063f33bc260 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Mon, 14 Nov 2016 12:12:56 +0100 Subject: [PATCH 08/11] [apps] create a class toolbox leaf cell Change-Id: Iee2efaab85646329700078ebd83079a82e5a31f6 --- apps/Makefile | 1 + apps/toolbox_leaf_cell.cpp | 53 ++++++++++++++++++++++++++++++++++++++ apps/toolbox_leaf_cell.h | 21 +++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 apps/toolbox_leaf_cell.cpp create mode 100644 apps/toolbox_leaf_cell.h diff --git a/apps/Makefile b/apps/Makefile index 391198b36..684bcc105 100644 --- a/apps/Makefile +++ b/apps/Makefile @@ -13,6 +13,7 @@ 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_node.o\ 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 From 139158557ca7d765a75867d1ae414e62a990877d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Mon, 14 Nov 2016 12:13:23 +0100 Subject: [PATCH 09/11] [apps] use toolbox leaf cell in the toolbox controller Change-Id: Iac52d3777761f6d5183391608db4fe7df3c1fbd4 --- apps/toolbox_controller.cpp | 29 ++++++++++++++++++----------- apps/toolbox_controller.h | 3 ++- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/apps/toolbox_controller.cpp b/apps/toolbox_controller.cpp index 9fa26e182..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), @@ -35,8 +35,15 @@ TableViewCell * ToolboxController::nodeCellAtIndex(int 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(m_listViewController.nodeModel()->children(index)->label()); + myCell->setText(node->label()); } Node * ToolboxController::nodeModel() { @@ -46,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 8ebe7e860..2a36fcf13 100644 --- a/apps/toolbox_controller.h +++ b/apps/toolbox_controller.h @@ -3,6 +3,7 @@ #include #include "node_navigation_controller.h" +#include "toolbox_leaf_cell.h" class ToolboxController : public NodeNavigationController { public: @@ -11,7 +12,7 @@ public: TableViewCell * nodeCellAtIndex(int index) override; void willDisplayCellForIndex(TableViewCell * cell, int index) override; private: - MenuListCell m_leafCells[NodeListViewController::k_maxNumberOfDisplayedRows]; + ToolboxLeafCell m_leafCells[NodeListViewController::k_maxNumberOfDisplayedRows]; ChevronMenuListCell m_nodeCells[NodeListViewController::k_maxNumberOfDisplayedRows]; Node * nodeModel() override; bool selectLeaf(Node * selectedNode) override; From 68eae7f010a2232a91a6db21669f63e0960716a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Mon, 14 Nov 2016 12:20:45 +0100 Subject: [PATCH 10/11] [apps] Ensure const methods when needed in node class Change-Id: Ib1ca31d4eeaaf1a05cc2e25e408b382111fa3648 --- apps/node.cpp | 4 ++-- apps/node.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) 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; From 1dcd102e99aff2ee811ce4e64372bf9ae46365ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Mon, 14 Nov 2016 14:42:09 +0100 Subject: [PATCH 11/11] [apps] create a class variable box lead cell Change-Id: Iab0d283d4472a40a5c628d770d829dc84979791b --- apps/Makefile | 1 + apps/variable_box_leaf_cell.cpp | 70 +++++++++++++++++++++++++++++++++ apps/variable_box_leaf_cell.h | 23 +++++++++++ 3 files changed, 94 insertions(+) create mode 100644 apps/variable_box_leaf_cell.cpp create mode 100644 apps/variable_box_leaf_cell.h diff --git a/apps/Makefile b/apps/Makefile index 684bcc105..e9fce929f 100644 --- a/apps/Makefile +++ b/apps/Makefile @@ -16,6 +16,7 @@ app_objs += $(addprefix apps/,\ toolbox_leaf_cell.o\ toolbox_node.o\ variable_box_controller.o\ + variable_box_leaf_cell.o\ variable_box_node.o\ ) 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