diff --git a/ui/ui_screen.cpp b/ui/ui_screen.cpp index 4730353b5b..d1fdb22f66 100644 --- a/ui/ui_screen.cpp +++ b/ui/ui_screen.cpp @@ -450,4 +450,19 @@ void TextEditPopupScreen::OnCompleted(DialogResult result) { } } +void ChoiceWithValueDisplay::Draw(UIContext &dc) { + Style style = dc.theme->itemStyle; + std::ostringstream valueText; + Choice::Draw(dc); + dc.SetFontStyle(dc.theme->uiFont); + + if (sValue_ != nullptr) { + valueText << *sValue_; + } else if (iValue_ != nullptr) { + valueText << *iValue_; + } + + dc.DrawText(valueText.str().c_str(), bounds_.x2() - 12, bounds_.centerY(), style.fgColor, ALIGN_RIGHT | ALIGN_VCENTER); +} + } // namespace UI diff --git a/ui/ui_screen.h b/ui/ui_screen.h index 95af3041d7..252a807821 100644 --- a/ui/ui_screen.h +++ b/ui/ui_screen.h @@ -266,4 +266,19 @@ private: std::string defaultText_; }; +class ChoiceWithValueDisplay : public UI::Choice { +public: + ChoiceWithValueDisplay(int *value, const std::string &text, LayoutParams *layoutParams = 0) + : Choice(text, layoutParams), iValue_(value) { sValue_ = nullptr; } + + ChoiceWithValueDisplay(std::string *value, const std::string &text, LayoutParams *layoutParams = 0) + : Choice(text, layoutParams), sValue_(value) { iValue_ = nullptr; } + + void Draw(UIContext &dc); + +private: + int *iValue_; + std::string *sValue_; +}; + } // namespace UI