mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2025-01-17 22:55:38 +00:00
Single-line TextComponents now stop at the first newline.
Prevents text going outside of the text area if there's a newline early in a description.
This commit is contained in:
parent
4dd60c14e7
commit
7f62b06d1a
|
@ -135,12 +135,27 @@ void TextComponent::onTextChanged()
|
||||||
{
|
{
|
||||||
calculateExtent();
|
calculateExtent();
|
||||||
|
|
||||||
|
if(!mFont || mText.empty())
|
||||||
|
{
|
||||||
|
mTextCache.reset();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
std::string text = mUppercase ? strToUpper(mText) : mText;
|
std::string text = mUppercase ? strToUpper(mText) : mText;
|
||||||
|
|
||||||
std::shared_ptr<Font> f = getFont();
|
std::shared_ptr<Font> f = mFont;
|
||||||
const bool wrap = (mSize.y() == 0 || mSize.y() > f->getHeight()*1.2f);
|
const bool isMultiline = (mSize.y() == 0 || mSize.y() > f->getHeight()*1.2f);
|
||||||
|
|
||||||
|
bool addAbbrev = false;
|
||||||
|
if(!isMultiline)
|
||||||
|
{
|
||||||
|
size_t newline = text.find('\n');
|
||||||
|
text = text.substr(0, newline); // single line of text - stop at the first newline since it'll mess everything up
|
||||||
|
addAbbrev = newline != std::string::npos;
|
||||||
|
}
|
||||||
|
|
||||||
Eigen::Vector2f size = f->sizeText(text);
|
Eigen::Vector2f size = f->sizeText(text);
|
||||||
if(!wrap && mSize.x() && text.size() && size.x() > mSize.x())
|
if(!isMultiline && mSize.x() && text.size() && (size.x() > mSize.x() || addAbbrev))
|
||||||
{
|
{
|
||||||
// abbreviate text
|
// abbreviate text
|
||||||
const std::string abbrev = "...";
|
const std::string abbrev = "...";
|
||||||
|
|
Loading…
Reference in a new issue