Added a parameter for whether to resize ButtonComponent when calling setText()

This commit is contained in:
Leon Styhre 2023-07-27 13:06:07 +02:00
parent 24508baade
commit 69e46d96a5
2 changed files with 14 additions and 6 deletions

View file

@ -64,7 +64,10 @@ void ButtonComponent::onFocusLost()
updateImage(); updateImage();
} }
void ButtonComponent::setText(const std::string& text, const std::string& helpText, bool upperCase) void ButtonComponent::setText(const std::string& text,
const std::string& helpText,
bool upperCase,
bool resize)
{ {
mText = upperCase ? Utils::String::toUpper(text) : text; mText = upperCase ? Utils::String::toUpper(text) : text;
mHelpText = helpText; mHelpText = helpText;
@ -74,10 +77,12 @@ void ButtonComponent::setText(const std::string& text, const std::string& helpTe
const float minWidth {mFont->sizeText("DELETE").x + const float minWidth {mFont->sizeText("DELETE").x +
(12.0f * mRenderer->getScreenResolutionModifier())}; (12.0f * mRenderer->getScreenResolutionModifier())};
setSize( if (resize) {
std::max(mTextCache->metrics.size.x + (12.0f * mRenderer->getScreenResolutionModifier()), setSize(std::max(mTextCache->metrics.size.x +
minWidth), (12.0f * mRenderer->getScreenResolutionModifier()),
mTextCache->metrics.size.y); minWidth),
mTextCache->metrics.size.y);
}
updateHelpPrompts(); updateHelpPrompts();
} }

View file

@ -27,7 +27,10 @@ public:
void onFocusGained() override; void onFocusGained() override;
void onFocusLost() override; void onFocusLost() override;
void setText(const std::string& text, const std::string& helpText, bool upperCase = true); void setText(const std::string& text,
const std::string& helpText,
bool upperCase = true,
bool resize = true);
const std::string& getText() const { return mText; } const std::string& getText() const { return mText; }
void setPressedFunc(std::function<void()> f) { mPressedFunc = f; } void setPressedFunc(std::function<void()> f) { mPressedFunc = f; }