mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[apps/code] Display source and description in var box
This commit is contained in:
@@ -7,22 +7,38 @@ namespace Code {
|
||||
constexpr char ScriptNodeCell::k_parentheses[];
|
||||
constexpr char ScriptNodeCell::k_parenthesesWithEmpty[];
|
||||
|
||||
// TODO LEA remove static inline KDCoordinate maxCoordinate(KDCoordinate x, KDCoordinate y) { return x > y ? x : y; }
|
||||
|
||||
void ScriptNodeCell::ScriptNodeView::drawRect(KDContext * ctx, KDRect rect) const {
|
||||
const KDColor backgroundColor = isHighlighted()? Palette::Select : KDColorWhite;
|
||||
|
||||
/* If it exists, draw the description name. If it did not fit, we would have
|
||||
* put nullptr at the node creation. */
|
||||
const char * descriptionName = m_scriptNode->description();
|
||||
bool drawDescription = descriptionName != nullptr;
|
||||
KDCoordinate rectHeightPerLine = rect.height();
|
||||
if (drawDescription) {
|
||||
rectHeightPerLine = rect.height() / 2;
|
||||
ctx->drawString(descriptionName, KDPoint(0, rectHeightPerLine + k_verticalMargin / 2), k_font, Palette::GreyDark, backgroundColor);
|
||||
}
|
||||
|
||||
// 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;
|
||||
KDSize nameSize = k_font->stringSize(nodeName, nodeNameLength);
|
||||
const KDCoordinate nodeNameY = rectHeightPerLine - k_verticalMargin / 2 - nameSize.height() ;
|
||||
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(), 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);
|
||||
|
||||
/* If it exists, draw the source name. If it did not fit, we would have put
|
||||
* nullptr at the node creation. */
|
||||
const char * sourceName = m_scriptNode->nodeSourceName();
|
||||
if (sourceName != nullptr) {
|
||||
KDSize sourceNameSize = k_font->stringSize(sourceName);
|
||||
ctx->drawString(sourceName, KDPoint(rect.width() - sourceNameSize.width(), nodeNameY), k_font, Palette::GreyDark, backgroundColor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,13 +46,25 @@ KDSize ScriptNodeCell::ScriptNodeView::minimalSizeForOptimalDisplay() const {
|
||||
if (m_scriptNode->name() == nullptr) {
|
||||
return KDSizeZero;
|
||||
}
|
||||
KDSize size1 = k_font->stringSize(m_scriptNode->name(), m_scriptNode->nameLength());
|
||||
KDSize size2 = m_scriptNode->scriptIndex() == ScriptNode::CurrentScriptIndex ? KDSizeZero : k_font->stringSize(m_scriptStore->scriptAtIndex(m_scriptNode->scriptIndex()).fullName());
|
||||
KDSize size3 = KDSizeZero;
|
||||
return KDSize(300 /*TODO LEA*/, 2*k_topBottomMargin + m_scriptNode->description() == nullptr ? k_font->glyphSize().height() : k_font->glyphSize().height() * 2 + k_verticalMargin);
|
||||
#if 0
|
||||
KDSize nameLineSize = k_font->stringSize(m_scriptNode->name(), m_scriptNode->nameLength());
|
||||
if (m_scriptNode->type() == ScriptNode::Type::Function) {
|
||||
size3 = k_font->stringSize(ScriptNodeCell::k_parentheses);
|
||||
nameLineSize = KDSize(nameLineSize.width() + k_font->stringSize(k_parentheses).width(), nameLineSize.height());
|
||||
}
|
||||
return KDSize(size1.width() + size3.width() > size2.width() ? size1.width() + size3.width() : size2.width(), Metric::TableCellVerticalMargin + size1.width() + k_verticalMargin + size2.width());
|
||||
const char * sourceName = m_scriptNode->nodeSourceName();
|
||||
if (sourceName != nullptr) {
|
||||
KDSize sourceNameSize = k_font->stringSize(sourceName, nodeNameLength);
|
||||
nameLineSize = KDSize(nameLineSize.width() + sourceNameSize.width() + k_font->glyphSize().width(), nameLineSize.height());
|
||||
}
|
||||
|
||||
const char * descriptionName = m_scriptNode->description();
|
||||
if (descriptionName == nullptr) {
|
||||
return nameLineSize;
|
||||
}
|
||||
const KDSize descriptionNameSize = k_font->stringSize(descriptionName);
|
||||
return KDSize(maxCoordinate(nameLineSize.width(), descriptionNameSize.width()),2*Metric::TableCellVerticalMargin + nameLineSize.width() + k_verticalMargin + descriptionNameSize.height());
|
||||
#endif
|
||||
}
|
||||
|
||||
void ScriptNodeCell::setScriptNode(ScriptNode * scriptNode) {
|
||||
|
||||
Reference in New Issue
Block a user