| 663 | } |
| 664 | |
| 665 | void BaseTheme::drawButtonMenu(GfxRenderer& renderer, Rect rect, int buttonCount, int selectedIndex, |
| 666 | const std::function<std::string(int index)>& buttonLabel, |
| 667 | const std::function<UIIcon(int index)>& rowIcon) const { |
| 668 | for (int i = 0; i < buttonCount; ++i) { |
| 669 | const int tileY = BaseMetrics::values.verticalSpacing + rect.y + |
| 670 | static_cast<int>(i) * (BaseMetrics::values.menuRowHeight + BaseMetrics::values.menuSpacing); |
| 671 | |
| 672 | const bool selected = selectedIndex == i; |
| 673 | |
| 674 | if (selected) { |
| 675 | renderer.fillRect(rect.x + BaseMetrics::values.contentSidePadding, tileY, |
| 676 | rect.width - BaseMetrics::values.contentSidePadding * 2, BaseMetrics::values.menuRowHeight); |
| 677 | } else { |
| 678 | renderer.drawRect(rect.x + BaseMetrics::values.contentSidePadding, tileY, |
| 679 | rect.width - BaseMetrics::values.contentSidePadding * 2, BaseMetrics::values.menuRowHeight); |
| 680 | } |
| 681 | |
| 682 | std::string labelStr = buttonLabel(i); |
| 683 | const char* label = labelStr.c_str(); |
| 684 | const int textWidth = renderer.getTextWidth(UI_10_FONT_ID, label); |
| 685 | const int textX = rect.x + (rect.width - textWidth) / 2; |
| 686 | const int lineHeight = renderer.getLineHeight(UI_10_FONT_ID); |
| 687 | const int textY = |
| 688 | tileY + (BaseMetrics::values.menuRowHeight - lineHeight) / 2; // vertically centered assuming y is top of text |
| 689 | // Invert text when the tile is selected, to contrast with the filled background |
| 690 | renderer.drawText(UI_10_FONT_ID, textX, textY, label, selectedIndex != i); |
| 691 | } |
| 692 | } |
| 693 | |
| 694 | Rect BaseTheme::drawPopup(const GfxRenderer& renderer, const char* message) const { |
| 695 | const auto& metrics = UITheme::getInstance().getMetrics(); |
no test coverage detected