mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[apps/code/varbox] Subtitles and basic items are displayed properly
This commit is contained in:
@@ -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; }
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<EvenOddMessageTextCell *>(cell)->setMessage(subtitleMessages[(int)cellOrigin], Palette::BlueishGrey);
|
||||
static_cast<MessageTableCell *>(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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user