diff --git a/apps/code/script_node.h b/apps/code/script_node.h index a788d3457..01864091d 100644 --- a/apps/code/script_node.h +++ b/apps/code/script_node.h @@ -8,6 +8,7 @@ namespace Code { class ScriptNode { public: + constexpr static uint16_t CurrentScriptIndex = -1; enum class Type : bool { Function, Variable @@ -15,7 +16,7 @@ public: ScriptNode(Type type = Type::Variable, const char * name = nullptr, int nameLength = 0, uint16_t scriptIndex = 0) : m_type(type), m_name(name), - m_scriptIndex(scriptIndex), + m_scriptIndex(-1), m_nameLength(nameLength) {} Type type() const { return m_type; } diff --git a/apps/code/script_node_cell.cpp b/apps/code/script_node_cell.cpp index 312978e2a..a56e69966 100644 --- a/apps/code/script_node_cell.cpp +++ b/apps/code/script_node_cell.cpp @@ -8,12 +8,22 @@ constexpr char ScriptNodeCell::k_parentheses[]; constexpr char ScriptNodeCell::k_parenthesesWithEmpty[]; void ScriptNodeCell::ScriptNodeView::drawRect(KDContext * ctx, KDRect rect) const { - ctx->drawString(m_scriptNode->name(), KDPoint(0, Metric::TableCellVerticalMargin), k_font, KDColorBlack, isHighlighted()? Palette::Select : KDColorWhite, m_scriptNode->nameLength()); - KDSize nameSize = k_font->stringSize(m_scriptNode->name(), m_scriptNode->nameLength()); + const KDColor backgroundColor = isHighlighted()? Palette::Select : KDColorWhite; + + // Draw the node name + const char * nodeName = m_scriptNode->name(); + const int nodeNameLength = m_scriptNode->nameLength(); + const KDSize nameSize = k_font->stringSize(nodeName, nodeNameLength); + const KDCoordinate nodeNameY = (rect.height() - nameSize.height()) / 2; + ctx->drawString(nodeName, KDPoint(0, nodeNameY), k_font, KDColorBlack, backgroundColor, nodeNameLength); + + // If it is a function, draw the parentheses if (m_scriptNode->type() == ScriptNode::Type::Function) { - ctx->drawString(ScriptNodeCell::k_parentheses, KDPoint(nameSize.width(), Metric::TableCellVerticalMargin), k_font, KDColorBlack, isHighlighted()? Palette::Select : KDColorWhite); + ctx->drawString(ScriptNodeCell::k_parentheses, KDPoint(nameSize.width(), nodeNameY), k_font, KDColorBlack, backgroundColor); + } + if (m_scriptNode->scriptIndex() != ScriptNode::CurrentScriptIndex) { + ctx->drawString(m_scriptStore->scriptAtIndex(m_scriptNode->scriptIndex()).fullName(), KDPoint(0, Metric::TableCellVerticalMargin + nameSize.height() + k_verticalMargin), k_font, Palette::GreyDark, backgroundColor); } - ctx->drawString(m_scriptStore->scriptAtIndex(m_scriptNode->scriptIndex()).fullName(), KDPoint(0, Metric::TableCellVerticalMargin + nameSize.height() + k_verticalMargin), k_font, Palette::GreyDark, isHighlighted()? Palette::Select : KDColorWhite); } KDSize ScriptNodeCell::ScriptNodeView::minimalSizeForOptimalDisplay() const { @@ -21,7 +31,7 @@ KDSize ScriptNodeCell::ScriptNodeView::minimalSizeForOptimalDisplay() const { return KDSizeZero; } KDSize size1 = k_font->stringSize(m_scriptNode->name(), m_scriptNode->nameLength()); - KDSize size2 = k_font->stringSize(m_scriptStore->scriptAtIndex(m_scriptNode->scriptIndex()).fullName()); + KDSize size2 = m_scriptNode->scriptIndex() == ScriptNode::CurrentScriptIndex ? KDSizeZero : k_font->stringSize(m_scriptStore->scriptAtIndex(m_scriptNode->scriptIndex()).fullName()); KDSize size3 = KDSizeZero; if (m_scriptNode->type() == ScriptNode::Type::Function) { size3 = k_font->stringSize(ScriptNodeCell::k_parentheses); diff --git a/apps/code/script_node_cell.h b/apps/code/script_node_cell.h index 4367e8c12..df14f9b06 100644 --- a/apps/code/script_node_cell.h +++ b/apps/code/script_node_cell.h @@ -14,7 +14,7 @@ public: TableCell(), m_scriptNodeView() {} - void setScriptNode(ScriptNode * node) { m_scriptNode = scriptNode; } + void setScriptNode(ScriptNode * node); void setScriptStore(ScriptStore * scriptStore) { m_scriptNodeView.setScriptStore(scriptStore); } /* TableCell */ @@ -37,7 +37,7 @@ protected: m_scriptNode(nullptr), m_scriptStore(nullptr) {} - void setScriptNode(ScriptNode * node) { m_scriptNode = scriptNode; } + void setScriptNode(ScriptNode * node) { m_scriptNode = node; } void setScriptStore(ScriptStore * scriptStore) { m_scriptStore = scriptStore; } void drawRect(KDContext * ctx, KDRect rect) const override; virtual KDSize minimalSizeForOptimalDisplay() const override; diff --git a/apps/code/variable_box_controller.cpp b/apps/code/variable_box_controller.cpp index 02f003468..8f07eafcb 100644 --- a/apps/code/variable_box_controller.cpp +++ b/apps/code/variable_box_controller.cpp @@ -57,9 +57,8 @@ VariableBoxController::VariableBoxController(ScriptStore * scriptStore) : m_itemCells[i].setScriptStore(scriptStore); } for (int i = 0; i < k_scriptOriginsCount; i++) { - m_subtitleCells[i].setEven(false); - m_subtitleCells[i].setAlignment(0.0f, 0.5f); - m_subtitleCells[i].setMessageFont(KDFont::SmallFont); + m_subtitleCells[i].setBackgroundColor(Palette::WallScreen); + m_subtitleCells[i].setTextColor(Palette::BlueishGrey); } } @@ -131,7 +130,7 @@ void VariableBoxController::willDisplayCellForIndex(HighlightCell * cell, int in I18n::Message::BuiltinFunctionsAndKeyWords, I18n::Message::ImportedModulesAndScripts }; - static_cast(cell)->setMessage(subtitleMessages[(int)cellOrigin], Palette::BlueishGrey); + static_cast(cell)->setMessage(subtitleMessages[(int)cellOrigin]); } int VariableBoxController::typeAtLocation(int i, int j) { @@ -549,7 +548,7 @@ void VariableBoxController::loadCurrentVariablesInScript(const char * scriptCont } } assert(strncmp(tokenInText, name, nameLength) == 0); - addNode(defToken ? ScriptNode::Type::Function : ScriptNode::Type::Variable, NodeOrigin::CurrentScript, tokenInText, nameLength, 1/* TODO LEA*/); + addNode(defToken ? ScriptNode::Type::Function : ScriptNode::Type::Variable, NodeOrigin::CurrentScript, tokenInText, nameLength, ScriptNode::CurrentScriptIndex); } } diff --git a/apps/code/variable_box_controller.h b/apps/code/variable_box_controller.h index 9d1f91459..2ecce3dc8 100644 --- a/apps/code/variable_box_controller.h +++ b/apps/code/variable_box_controller.h @@ -100,7 +100,7 @@ private: ScriptNode m_builtinNodes[k_totalBuiltinNodesCount]; ScriptNode m_importedNodes[k_maxScriptNodesCount]; ScriptNodeCell m_itemCells[k_maxNumberOfDisplayedRows]; - EvenOddMessageTextCell m_subtitleCells[k_scriptOriginsCount]; + MessageTableCell m_subtitleCells[k_scriptOriginsCount]; ScriptStore * m_scriptStore; // TODO LEA Put these in an array? int m_currentScriptNodesCount; diff --git a/escher/include/escher/message_table_cell.h b/escher/include/escher/message_table_cell.h index 10a0e795b..c43985d6d 100644 --- a/escher/include/escher/message_table_cell.h +++ b/escher/include/escher/message_table_cell.h @@ -13,8 +13,12 @@ public: void setMessage(I18n::Message message); virtual void setTextColor(KDColor color); void setMessageFont(const KDFont * font); + void setBackgroundColor(KDColor color); +protected: + KDColor backgroundColor() const override { return m_backgroundColor; } private: MessageTextView m_messageTextView; + KDColor m_backgroundColor; }; #endif diff --git a/escher/include/escher/table_cell.h b/escher/include/escher/table_cell.h index e46da7bf6..4cee2b6aa 100644 --- a/escher/include/escher/table_cell.h +++ b/escher/include/escher/table_cell.h @@ -23,6 +23,7 @@ public: virtual View * subAccessoryView() const; void drawRect(KDContext * ctx, KDRect rect) const override; protected: + virtual KDColor backgroundColor() const { return KDColorWhite; } virtual KDCoordinate labelMargin() const { return Metric::TableCellHorizontalMargin; } virtual KDCoordinate accessoryMargin() const { return Metric::TableCellHorizontalMargin; } int numberOfSubviews() const override; diff --git a/escher/src/message_table_cell.cpp b/escher/src/message_table_cell.cpp index 083b55605..103f0b829 100644 --- a/escher/src/message_table_cell.cpp +++ b/escher/src/message_table_cell.cpp @@ -4,7 +4,8 @@ MessageTableCell::MessageTableCell(I18n::Message label, const KDFont * font, Layout layout) : TableCell(layout), - m_messageTextView(font, label, 0, 0.5, KDColorBlack, KDColorWhite) + m_messageTextView(font, label, 0, 0.5, KDColorBlack, KDColorWhite), + m_backgroundColor(KDColorWhite) { } @@ -14,7 +15,7 @@ View * MessageTableCell::labelView() const { void MessageTableCell::setHighlighted(bool highlight) { HighlightCell::setHighlighted(highlight); - KDColor backgroundColor = highlight? Palette::Select : KDColorWhite; + KDColor backgroundColor = highlight? Palette::Select : m_backgroundColor; m_messageTextView.setBackgroundColor(backgroundColor); } @@ -31,3 +32,8 @@ void MessageTableCell::setMessageFont(const KDFont * font) { m_messageTextView.setFont(font); layoutSubviews(); } + +void MessageTableCell::setBackgroundColor(KDColor color) { + m_backgroundColor = color; + m_messageTextView.setBackgroundColor(color); +} diff --git a/escher/src/table_cell.cpp b/escher/src/table_cell.cpp index 85446c28c..dc4845ee2 100644 --- a/escher/src/table_cell.cpp +++ b/escher/src/table_cell.cpp @@ -164,7 +164,7 @@ void TableCell::layoutSubviews(bool force) { } void TableCell::drawRect(KDContext * ctx, KDRect rect) const { - KDColor backgroundColor = isHighlighted() ? Palette::Select : KDColorWhite; - drawInnerRect(ctx, bounds(), backgroundColor); + KDColor backColor = isHighlighted() ? Palette::Select : backgroundColor(); + drawInnerRect(ctx, bounds(), backColor); drawBorderOfRect(ctx, bounds(), Palette::GreyBright); }