MCPcopy Create free account
hub / github.com/crosspoint-reader/crosspoint-reader / drawHeader

Method drawHeader

src/components/themes/lyra/LyraTheme.cpp:107–155  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

105}
106
107void LyraTheme::drawHeader(const GfxRenderer& renderer, Rect rect, const char* title, const char* subtitle) const {
108 renderer.fillRect(rect.x, rect.y, rect.width, rect.height, false);
109
110 const bool showBatteryPercentage =
111 SETTINGS.hideBatteryPercentage != CrossPointSettings::HIDE_BATTERY_PERCENTAGE::HIDE_ALWAYS;
112 // Position icon at right edge, drawBatteryRight will place text to the left
113 const int batteryX = rect.x + rect.width - 12 - LyraMetrics::values.batteryWidth;
114 drawBatteryRight(renderer,
115 Rect{batteryX, rect.y + 5, LyraMetrics::values.batteryWidth, LyraMetrics::values.batteryHeight},
116 showBatteryPercentage);
117
118 int maxTitleWidth = title != nullptr ? renderer.getTextWidth(UI_12_FONT_ID, title, EpdFontFamily::BOLD) : 0;
119 int maxSubtitleWidth =
120 subtitle != nullptr ? renderer.getTextWidth(SMALL_FONT_ID, subtitle, EpdFontFamily::REGULAR) : 0;
121
122 // Available space is the distance between the side paddings, and a with side padding between title and subtitle.
123 const int availableSpace = rect.width - LyraMetrics::values.contentSidePadding * 3;
124
125 if (maxTitleWidth + maxSubtitleWidth > availableSpace) {
126 if ((maxTitleWidth > availableSpace / 2) && (maxSubtitleWidth > availableSpace / 2)) {
127 // Both are wider then half the space, truncate both.
128 maxTitleWidth = availableSpace / 2;
129 maxSubtitleWidth = availableSpace / 2;
130 } else {
131 // Truncate the the longest one
132 if (maxTitleWidth > maxSubtitleWidth) {
133 maxTitleWidth = availableSpace - maxSubtitleWidth;
134 } else {
135 maxSubtitleWidth = availableSpace - maxTitleWidth;
136 }
137 }
138 }
139
140 if (title) {
141 auto truncatedTitle = renderer.truncatedText(UI_12_FONT_ID, title, maxTitleWidth, EpdFontFamily::BOLD);
142 renderer.drawText(UI_12_FONT_ID, rect.x + LyraMetrics::values.contentSidePadding,
143 rect.y + LyraMetrics::values.batteryBarHeight + 3, truncatedTitle.c_str(), true,
144 EpdFontFamily::BOLD);
145 renderer.drawLine(rect.x, rect.y + rect.height - 3, rect.x + rect.width - 1, rect.y + rect.height - 3, 3, true);
146 }
147
148 if (subtitle) {
149 auto truncatedSubtitle = renderer.truncatedText(SMALL_FONT_ID, subtitle, maxSubtitleWidth, EpdFontFamily::REGULAR);
150 int truncatedSubtitleWidth = renderer.getTextWidth(SMALL_FONT_ID, truncatedSubtitle.c_str());
151 renderer.drawText(SMALL_FONT_ID,
152 rect.x + rect.width - LyraMetrics::values.contentSidePadding - truncatedSubtitleWidth,
153 rect.y + 50, truncatedSubtitle.c_str(), true);
154 }
155}
156
157void LyraTheme::drawSubHeader(const GfxRenderer& renderer, Rect rect, const char* label, const char* rightLabel) const {
158 int currentX = rect.x + LyraMetrics::values.contentSidePadding;

Callers

nothing calls this directly

Calls 5

fillRectMethod · 0.80
getTextWidthMethod · 0.80
truncatedTextMethod · 0.80
drawTextMethod · 0.80
drawLineMethod · 0.80

Tested by

no test coverage detected