Skip to content

Commit

Permalink
Merge pull request #817 from Gemba/fb_reenable_backward_compatible_wr…
Browse files Browse the repository at this point in the history
…apping

Reenables backward compatible text wrapping for some themes
  • Loading branch information
pjft committed Mar 23, 2023
2 parents 70f737b + 955fe06 commit 9afa234
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
16 changes: 12 additions & 4 deletions es-core/src/components/TextComponent.cpp
Expand Up @@ -153,16 +153,24 @@ void TextComponent::render(const Transform4x4f& parentTrans)
}
}

std::string TextComponent::calculateExtent()
std::string TextComponent::calculateExtent(bool allow_wrapping)
{
std::string text = mUppercase ? Utils::String::toUpper(mText) : mText;
if(mAutoCalcExtent.x())
{
mSize = mFont->sizeText(text, mLineSpacing);
}else if(mAutoCalcExtent.y())
}else if(mAutoCalcExtent.y() || allow_wrapping)
// usually a textcomponent wraps only when x > 0 and y == 0 in size (see TextComponent.h).
// The extra flag allow_wrapping does wrapping if an textcomponent has x > 0 and y > height of
// one line (calculated by fontsize and line spacing).
// Some themes rely on this wrap functionality while having an fixed y (y>0) in <size/>.
{
text = mFont->wrapText(text, getSize().x());
mSize.y() = mFont->sizeText(text, mLineSpacing).y();
if (mAutoCalcExtent.y()) {
// only resize when y was 0 before
// otherwise leave y value as defined before (i.e. theme value)
mSize.y() = mFont->sizeText(text, mLineSpacing).y();
}
}
return text;
}
Expand All @@ -176,7 +184,7 @@ void TextComponent::onTextChanged()
}

std::shared_ptr<Font> f = mFont;
std::string text = calculateExtent();
std::string text = calculateExtent(mSize.y() > f->getHeight(mLineSpacing));
const bool oneLiner = mSize.y() > 0 && mSize.y() <= f->getHeight(mLineSpacing);

if(oneLiner)
Expand Down
2 changes: 1 addition & 1 deletion es-core/src/components/TextComponent.h
Expand Up @@ -49,7 +49,7 @@ class TextComponent : public GuiComponent
std::shared_ptr<Font> mFont;

private:
std::string calculateExtent();
std::string calculateExtent(bool allow_wrapping);

void onColorChanged();

Expand Down

0 comments on commit 9afa234

Please sign in to comment.