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

Method drawList

src/components/themes/BaseTheme.cpp:258–352  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

256}
257
258void BaseTheme::drawList(const GfxRenderer& renderer, Rect rect, int itemCount, int selectedIndex,
259 const std::function<std::string(int index)>& rowTitle,
260 const std::function<std::string(int index)>& rowSubtitle,
261 const std::function<UIIcon(int index)>& rowIcon,
262 const std::function<std::string(int index)>& rowValue, bool highlightValue,
263 const std::function<bool(int index)>& rowDimmed) const {
264 int rowHeight =
265 (rowSubtitle != nullptr) ? BaseMetrics::values.listWithSubtitleRowHeight : BaseMetrics::values.listRowHeight;
266 int pageItems = rect.height / rowHeight;
267
268 const int totalPages = (itemCount + pageItems - 1) / pageItems;
269 if (totalPages > 1) {
270 constexpr int indicatorWidth = 20;
271 constexpr int arrowSize = 6;
272 constexpr int margin = 15; // Offset from right edge
273
274 const int centerX = rect.x + rect.width - indicatorWidth / 2 - margin;
275 const int indicatorTop = rect.y; // Offset to avoid overlapping side button hints
276 const int indicatorBottom = rect.y + rect.height - arrowSize;
277
278 // Draw up arrow at top (^) - narrow point at top, wide base at bottom
279 for (int i = 0; i < arrowSize; ++i) {
280 const int lineWidth = 1 + i * 2;
281 const int startX = centerX - i;
282 renderer.drawLine(startX, indicatorTop + i, startX + lineWidth - 1, indicatorTop + i);
283 }
284
285 // Draw down arrow at bottom (v) - wide base at top, narrow point at bottom
286 for (int i = 0; i < arrowSize; ++i) {
287 const int lineWidth = 1 + (arrowSize - 1 - i) * 2;
288 const int startX = centerX - (arrowSize - 1 - i);
289 renderer.drawLine(startX, indicatorBottom - arrowSize + 1 + i, startX + lineWidth - 1,
290 indicatorBottom - arrowSize + 1 + i);
291 }
292 }
293
294 // Draw selection
295 int contentWidth = rect.width - 5;
296 if (selectedIndex >= 0) {
297 renderer.fillRect(rect.x, rect.y + selectedIndex % pageItems * rowHeight - 2, rect.width, rowHeight);
298 }
299 constexpr int minValueGap = 10;
300
301 // Draw all items
302 const auto pageStartIndex = selectedIndex / pageItems * pageItems;
303 for (int i = pageStartIndex; i < itemCount && i < pageStartIndex + pageItems; i++) {
304 const int itemY = rect.y + (i % pageItems) * rowHeight;
305
306 int rowTextWidth = contentWidth - BaseMetrics::values.contentSidePadding * 2;
307 std::string valueText;
308 if (rowValue != nullptr) {
309 valueText = rowValue(i);
310 if (!valueText.empty()) {
311 int maxValW = std::max(0, rowTextWidth - 40 - minValueGap);
312 valueText = renderer.truncatedText(UI_10_FONT_ID, valueText.c_str(), maxValW);
313 int valueWidth = renderer.getTextWidth(UI_10_FONT_ID, valueText.c_str()) + minValueGap;
314 rowTextWidth -= valueWidth;
315 }

Callers 15

renderNetworkListMethod · 0.45
renderMethod · 0.45
renderMethod · 0.45
renderMethod · 0.45
renderMethod · 0.45
renderMethod · 0.45
renderMethod · 0.45
renderMethod · 0.45
renderMethod · 0.45
renderMethod · 0.45
renderMethod · 0.45
renderMethod · 0.45

Calls 8

drawLineMethod · 0.80
fillRectMethod · 0.80
truncatedTextMethod · 0.80
getTextWidthMethod · 0.80
drawTextMethod · 0.80
getLineHeightMethod · 0.80
drawPixelMethod · 0.80
emptyMethod · 0.45

Tested by

no test coverage detected