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

Method drawTabBar

src/components/themes/BaseTheme.cpp:405–433  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

403}
404
405void BaseTheme::drawTabBar(const GfxRenderer& renderer, const Rect rect, const std::vector<TabInfo>& tabs,
406 bool selected) const {
407 constexpr int underlineHeight = 2; // Height of selection underline
408 constexpr int underlineGap = 4; // Gap between text and underline
409
410 const int lineHeight = renderer.getLineHeight(UI_12_FONT_ID);
411
412 int currentX = rect.x + BaseMetrics::values.contentSidePadding;
413
414 for (const auto& tab : tabs) {
415 const int textWidth =
416 renderer.getTextWidth(UI_12_FONT_ID, tab.label, tab.selected ? EpdFontFamily::BOLD : EpdFontFamily::REGULAR);
417
418 // Draw underline for selected tab
419 if (tab.selected) {
420 if (selected) {
421 renderer.fillRect(currentX - 3, rect.y, textWidth + 6, lineHeight + underlineGap);
422 } else {
423 renderer.fillRect(currentX, rect.y + lineHeight + underlineGap, textWidth, underlineHeight);
424 }
425 }
426
427 // Draw tab label
428 renderer.drawText(UI_12_FONT_ID, currentX, rect.y, tab.label, !(tab.selected && selected),
429 tab.selected ? EpdFontFamily::BOLD : EpdFontFamily::REGULAR);
430
431 currentX += textWidth + BaseMetrics::values.tabSpacing;
432 }
433}
434
435// Draw the "Recent Book" cover card on the home screen
436// TODO: Refactor method to make it cleaner, split into smaller methods

Callers 1

renderMethod · 0.45

Calls 4

getLineHeightMethod · 0.80
getTextWidthMethod · 0.80
fillRectMethod · 0.80
drawTextMethod · 0.80

Tested by

no test coverage detected