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();
}
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;
mHelpText = helpText;
@ -74,10 +77,12 @@ void ButtonComponent::setText(const std::string& text, const std::string& helpTe
const float minWidth {mFont->sizeText("DELETE").x +
(12.0f * mRenderer->getScreenResolutionModifier())};
setSize(
std::max(mTextCache->metrics.size.x + (12.0f * mRenderer->getScreenResolutionModifier()),
if (resize) {
setSize(std::max(mTextCache->metrics.size.x +
(12.0f * mRenderer->getScreenResolutionModifier()),
minWidth),
mTextCache->metrics.size.y);
}
updateHelpPrompts();
}

View file

@ -27,7 +27,10 @@ public:
void onFocusGained() 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; }
void setPressedFunc(std::function<void()> f) { mPressedFunc = f; }