From bc4d2768d0c4243bc1da341feeb352462e45e2f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Fri, 24 Nov 2017 15:46:58 +0100 Subject: [PATCH] [escher/code] Cleaned Toolbox rowHeight(). Now it is set in escher/toolbox.h, with value 40 and no differentiation Node/Leaf. Change-Id: I0809d87a5df5b8bffe201c9faf72ff901430cbe5 --- apps/code/toolbox.cpp | 9 +++------ apps/code/toolbox.h | 2 -- apps/math_toolbox.cpp | 7 ------- apps/math_toolbox.h | 3 --- apps/sequence/list/sequence_toolbox.cpp | 7 ------- apps/sequence/list/sequence_toolbox.h | 2 -- escher/include/escher/toolbox.h | 2 ++ escher/src/toolbox.cpp | 4 ++++ 8 files changed, 9 insertions(+), 27 deletions(-) diff --git a/apps/code/toolbox.cpp b/apps/code/toolbox.cpp index 1520a538d..d56b5c76f 100644 --- a/apps/code/toolbox.cpp +++ b/apps/code/toolbox.cpp @@ -247,8 +247,7 @@ bool Toolbox::handleEvent(Ion::Events::Event event) { } KDCoordinate Toolbox::rowHeight(int j) { - if (typeAtLocation(0, j) == ::Toolbox::LeafCellType) { - if (m_messageTreeModel->label() != I18n::Message::IfStatementMenu) { + if (typeAtLocation(0, j) == ::Toolbox::LeafCellType && m_messageTreeModel->label() == I18n::Message::IfStatementMenu) { /* To get the exact height needed for each cell, we have to compute its * text size, which means scan the text char by char to look for '\n' * chars. This is very costly and ruins the speed performance when @@ -258,12 +257,10 @@ KDCoordinate Toolbox::rowHeight(int j) { * We thus decided to compute the real height only for the ifStatement * children of the toolbox, which is the only menu that has special height * rows. */ - return k_leafRowHeight; - } const ToolboxMessageTree * messageTree = static_cast(m_messageTreeModel->children(j)); - return KDText::stringSize(I18n::translate(messageTree->label()), k_fontSize).height() + 2*Metric::TableCellLabelTopMargin + (messageTree->text() == I18n::Message::Default ? 0 : k_leafRowHeight); + return KDText::stringSize(I18n::translate(messageTree->label()), k_fontSize).height() + 2*Metric::TableCellLabelTopMargin + (messageTree->text() == I18n::Message::Default ? 0 : ::Toolbox::rowHeight(j)); } - return k_nodeRowHeight; + return ::Toolbox::rowHeight(j); } bool Toolbox::selectLeaf(ToolboxMessageTree * selectedMessageTree) { diff --git a/apps/code/toolbox.h b/apps/code/toolbox.h index 79ca84569..05b563b5e 100644 --- a/apps/code/toolbox.h +++ b/apps/code/toolbox.h @@ -27,8 +27,6 @@ protected: // 13 = minimal string height size // 3 = vertical margins private: - constexpr static KDCoordinate k_nodeRowHeight = 40; - constexpr static KDCoordinate k_leafRowHeight = 40; constexpr static KDText::FontSize k_fontSize = KDText::FontSize::Small; void scrollToLetter(char letter); void scrollToAndSelectChild(int i); diff --git a/apps/math_toolbox.cpp b/apps/math_toolbox.cpp index d4e0a59c0..caa25e6dc 100644 --- a/apps/math_toolbox.cpp +++ b/apps/math_toolbox.cpp @@ -102,13 +102,6 @@ MathToolbox::MathToolbox() : Toolbox(nullptr, I18n::translate(rootModel()->label { } -KDCoordinate MathToolbox::rowHeight(int j) { - if (typeAtLocation(0, j) == Toolbox::LeafCellType) { - return k_leafRowHeight; - } - return k_nodeRowHeight; -} - TextField * MathToolbox::sender() { return (TextField *)Toolbox::sender(); } diff --git a/apps/math_toolbox.h b/apps/math_toolbox.h index 1d0171652..0579969de 100644 --- a/apps/math_toolbox.h +++ b/apps/math_toolbox.h @@ -9,7 +9,6 @@ class MathToolbox : public Toolbox { public: MathToolbox(); protected: - KDCoordinate rowHeight(int j) override; TextField * sender() override; bool selectLeaf(ToolboxMessageTree * selectedMessageTree) override; const ToolboxMessageTree * rootModel() override; @@ -18,8 +17,6 @@ protected: int maxNumberOfDisplayedRows() override; constexpr static int k_maxNumberOfDisplayedRows = 6; // = 240/40 private: - constexpr static KDCoordinate k_nodeRowHeight = 40; - constexpr static KDCoordinate k_leafRowHeight = 40; MessageTableCellWithMessage m_leafCells[k_maxNumberOfDisplayedRows]; MessageTableCellWithChevron m_nodeCells[k_maxNumberOfDisplayedRows]; }; diff --git a/apps/sequence/list/sequence_toolbox.cpp b/apps/sequence/list/sequence_toolbox.cpp index a4546c765..24f062a25 100644 --- a/apps/sequence/list/sequence_toolbox.cpp +++ b/apps/sequence/list/sequence_toolbox.cpp @@ -60,13 +60,6 @@ void SequenceToolbox::willDisplayCellForIndex(HighlightCell * cell, int index) { } } -KDCoordinate SequenceToolbox::rowHeight(int j) { - if (typeAtLocation(0, j) == 2) { - return k_addedRowHeight; - } - return MathToolbox::rowHeight(mathToolboxIndex(j)); -} - int SequenceToolbox::typeAtLocation(int i, int j) { if (stackDepth() == 0 && j < m_numberOfAddedCells) { return 2; diff --git a/apps/sequence/list/sequence_toolbox.h b/apps/sequence/list/sequence_toolbox.h index 87ef26ff4..84b6ee4ae 100644 --- a/apps/sequence/list/sequence_toolbox.h +++ b/apps/sequence/list/sequence_toolbox.h @@ -17,13 +17,11 @@ public: int numberOfRows() override; HighlightCell * reusableCell(int index, int type) override; void willDisplayCellForIndex(HighlightCell * cell, int index) override; - KDCoordinate rowHeight(int j) override; int typeAtLocation(int i, int j) override; void setExtraCells(const char * sequenceName, int recurrenceDepth); private: bool selectAddedCell(int selectedRow); int mathToolboxIndex(int index); - constexpr static KDCoordinate k_addedRowHeight = 20; ExpressionTableCell m_addedCells[k_maxNumberOfDisplayedRows]; Poincare::ExpressionLayout * m_addedCellLayout[k_maxNumberOfDisplayedRows]; int m_numberOfAddedCells; diff --git a/escher/include/escher/toolbox.h b/escher/include/escher/toolbox.h index 59d985030..ca8fdecca 100644 --- a/escher/include/escher/toolbox.h +++ b/escher/include/escher/toolbox.h @@ -21,6 +21,7 @@ public: void viewDidDisappear() override; //ListViewDataSource + virtual KDCoordinate rowHeight(int j) override; int numberOfRows() override; HighlightCell * reusableCell(int index, int type) override; int reusableCellCount(int type) override; @@ -67,6 +68,7 @@ protected: static constexpr int LeafCellType = 0; static constexpr int NodeCellType = 1; + static constexpr KDCoordinate sToolboxRowHeight = 40; int stackDepth(); bool handleEventForRow(Ion::Events::Event event, int selectedRow); bool selectSubMenu(ToolboxMessageTree * selectedMessageTree); diff --git a/escher/src/toolbox.cpp b/escher/src/toolbox.cpp index a4b3ed7c4..511420643 100644 --- a/escher/src/toolbox.cpp +++ b/escher/src/toolbox.cpp @@ -118,6 +118,10 @@ void Toolbox::viewDidDisappear() { m_selectableTableView.deselectTable(); } +KDCoordinate Toolbox::rowHeight(int j) { + return sToolboxRowHeight; +} + int Toolbox::numberOfRows() { if (m_messageTreeModel == nullptr) { m_messageTreeModel = (ToolboxMessageTree *)rootModel();