Add a new Choice subclass which lets the UI display a value in addition to the title, similar to other controls.

This commit is contained in:
The Dax committed 2014-07-18 18:45:26 -04:00
1 parent ceb5a94c4a
commit 085faa87cc
2 files changed
+30

No files matched your search

+15
View File
@@ -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
+15
View File
@@ -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