mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[apps/code] Cosmetic fixes on the variable box
This commit is contained in:
@@ -7,38 +7,32 @@ 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. */
|
||||
// If it exists, draw the description name.
|
||||
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);
|
||||
if (descriptionName != nullptr) {
|
||||
ctx->drawString(descriptionName, KDPoint(0, m_frame.height() - k_bottomMargin - k_font->glyphSize().height()), k_font, Palette::GreyDark, backgroundColor);
|
||||
}
|
||||
|
||||
// Draw the node name
|
||||
const char * nodeName = m_scriptNode->name();
|
||||
const int nodeNameLength = m_scriptNode->nameLength();
|
||||
KDSize nameSize = k_font->stringSize(nodeName, nodeNameLength);
|
||||
const KDCoordinate nodeNameY = rectHeightPerLine - k_verticalMargin / 2 - nameSize.height() ;
|
||||
const KDCoordinate nodeNameY = k_topMargin;
|
||||
ctx->drawString(nodeName, KDPoint(0, nodeNameY), k_font, KDColorBlack, backgroundColor, nodeNameLength);
|
||||
// If it is a function, draw the parentheses
|
||||
// If it is needed, draw the parentheses
|
||||
if (m_scriptNode->type() == ScriptNode::Type::WithParentheses) {
|
||||
ctx->drawString(ScriptNodeCell::k_parentheses, KDPoint(nameSize.width(), nodeNameY), k_font, KDColorBlack, backgroundColor);
|
||||
}
|
||||
|
||||
/* If it exists, draw the source name. If it did not fit, we would have put
|
||||
* nullptr at the node creation. */
|
||||
* nullptr at the node creation. TODO LEA */
|
||||
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);
|
||||
ctx->drawString(sourceName, KDPoint(m_frame.width() - sourceNameSize.width(), nodeNameY), k_font, Palette::GreyDark, backgroundColor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,25 +40,9 @@ KDSize ScriptNodeCell::ScriptNodeView::minimalSizeForOptimalDisplay() const {
|
||||
if (m_scriptNode->name() == nullptr) {
|
||||
return 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::WithParentheses) {
|
||||
nameLineSize = KDSize(nameLineSize.width() + k_font->stringSize(k_parentheses).width(), nameLineSize.height());
|
||||
}
|
||||
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
|
||||
return KDSize(
|
||||
Ion::Display::Width - Metric::PopUpLeftMargin - Metric::PopUpRightMargin,
|
||||
m_scriptNode->description() == nullptr ? k_simpleItemHeight : k_complexItemHeight);
|
||||
}
|
||||
|
||||
void ScriptNodeCell::setScriptNode(ScriptNode * scriptNode) {
|
||||
|
||||
@@ -27,7 +27,8 @@ public:
|
||||
static_assert('\x11' == UCodePointEmpty, "Unicode error");
|
||||
constexpr static char k_parentheses[] = "()";
|
||||
constexpr static char k_parenthesesWithEmpty[] = "(\x11)";
|
||||
|
||||
constexpr static KDCoordinate k_simpleItemHeight = 27;
|
||||
constexpr static KDCoordinate k_complexItemHeight = 42;
|
||||
protected:
|
||||
class ScriptNodeView : public HighlightCell {
|
||||
public:
|
||||
@@ -43,8 +44,8 @@ protected:
|
||||
}
|
||||
private:
|
||||
constexpr static const KDFont * k_font = KDFont::SmallFont;
|
||||
constexpr static KDCoordinate k_topBottomMargin = Metric::TableCellVerticalMargin;
|
||||
constexpr static KDCoordinate k_verticalMargin = 7;
|
||||
constexpr static KDCoordinate k_bottomMargin = 5;
|
||||
constexpr static KDCoordinate k_topMargin = k_bottomMargin + k_separatorThickness;
|
||||
ScriptNode * m_scriptNode;
|
||||
};
|
||||
ScriptNodeView m_scriptNodeView;
|
||||
|
||||
@@ -81,9 +81,9 @@ KDCoordinate VariableBoxController::rowHeight(int j) {
|
||||
if (cellType == k_itemCellType) {
|
||||
//TODO LEA if cellOrigin == Imported?
|
||||
if (scriptNodeAtIndex(j - cumulatedOriginsCount)->description() != nullptr) {
|
||||
return k_complexItemRowHeight;
|
||||
return ScriptNodeCell::k_complexItemHeight;
|
||||
}
|
||||
return k_simpleItemRowHeight;
|
||||
return ScriptNodeCell::k_simpleItemHeight;
|
||||
}
|
||||
assert(cellType == k_subtitleCellType);
|
||||
return k_subtitleRowHeight;
|
||||
|
||||
@@ -39,8 +39,7 @@ private:
|
||||
constexpr static uint8_t k_subtitleCellType = NodeCellType; // We don't care as it is not selectable
|
||||
constexpr static uint8_t k_itemCellType = LeafCellType; // So that upper class NestedMenuController knows it's a leaf
|
||||
constexpr static KDCoordinate k_subtitleRowHeight = 23;
|
||||
constexpr static KDCoordinate k_simpleItemRowHeight = 27;
|
||||
constexpr static KDCoordinate k_complexItemRowHeight = 44;
|
||||
|
||||
enum class NodeOrigin : uint8_t {
|
||||
CurrentScript = 0,
|
||||
Builtins = 1,
|
||||
|
||||
@@ -24,8 +24,8 @@ public:
|
||||
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; }
|
||||
virtual KDCoordinate labelMargin() const { return k_horizontalMargin; }
|
||||
virtual KDCoordinate accessoryMargin() const { return k_horizontalMargin; }
|
||||
int numberOfSubviews() const override;
|
||||
View * subviewAtIndex(int index) override;
|
||||
void layoutSubviews(bool force = false) override;
|
||||
|
||||
@@ -98,16 +98,16 @@ void TableCell::layoutSubviews(bool force) {
|
||||
y += labelHeight + k_verticalMargin;
|
||||
}
|
||||
horizontalMargin = k_separatorThickness + k_horizontalMargin;
|
||||
y = std::max<KDCoordinate>(y, height - k_separatorThickness - withMargin(accessorySize.height(), Metric::TableCellVerticalMargin) - withMargin(subAccessorySize.height(), 0));
|
||||
y = std::max<KDCoordinate>(y, height - k_separatorThickness - withMargin(accessorySize.height(), k_verticalMargin) - withMargin(subAccessorySize.height(), 0));
|
||||
if (subAccessory) {
|
||||
KDCoordinate subAccessoryHeight = std::min<KDCoordinate>(subAccessorySize.height(), height - y - k_separatorThickness - Metric::TableCellVerticalMargin);
|
||||
KDCoordinate subAccessoryHeight = std::min<KDCoordinate>(subAccessorySize.height(), height - y - k_separatorThickness - k_verticalMargin);
|
||||
accessory->setFrame(KDRect(horizontalMargin, y, width - 2*horizontalMargin, subAccessoryHeight), force);
|
||||
y += subAccessoryHeight;
|
||||
}
|
||||
horizontalMargin = k_separatorThickness + accessoryMargin();
|
||||
y = std::max<KDCoordinate>(y, height - k_separatorThickness - withMargin(accessorySize.height(), Metric::TableCellVerticalMargin));
|
||||
y = std::max<KDCoordinate>(y, height - k_separatorThickness - withMargin(accessorySize.height(), k_verticalMargin));
|
||||
if (accessory) {
|
||||
KDCoordinate accessoryHeight = std::min<KDCoordinate>(accessorySize.height(), height - y - k_separatorThickness - Metric::TableCellVerticalMargin);
|
||||
KDCoordinate accessoryHeight = std::min<KDCoordinate>(accessorySize.height(), height - y - k_separatorThickness - k_verticalMargin);
|
||||
accessory->setFrame(KDRect(horizontalMargin, y, width - 2*horizontalMargin, accessoryHeight), force);
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user