mirror of
https://github.com/FunKey-Project/RetroFE.git
synced 2026-01-02 20:18:52 +01:00
Improved text alignment when text is larger than the allowed image width.
This commit is contained in:
parent
d1263ccc92
commit
92b0ca41c3
@ -78,6 +78,9 @@ void Text::draw()
|
||||
imageHeight = (float)font->getHeight();
|
||||
float scale = (float)baseViewInfo.FontSize / (float)imageHeight;
|
||||
|
||||
unsigned int textIndexMax = 0;
|
||||
unsigned int emptySpace = 0;
|
||||
|
||||
// determine image width
|
||||
for(unsigned int i = 0; i < textData_.size(); ++i)
|
||||
{
|
||||
@ -90,9 +93,14 @@ void Text::draw()
|
||||
}
|
||||
|
||||
if ((imageWidth + glyph.advance)*scale > imageMaxWidth )
|
||||
break;
|
||||
{
|
||||
imageWidth -= emptySpace;
|
||||
break;
|
||||
}
|
||||
|
||||
imageWidth += glyph.advance;
|
||||
textIndexMax = i;
|
||||
emptySpace = glyph.advance - glyph.maxX;
|
||||
imageWidth += glyph.advance;
|
||||
}
|
||||
|
||||
}
|
||||
@ -119,7 +127,7 @@ void Text::draw()
|
||||
SDL_Rect rect;
|
||||
rect.x = static_cast<int>(xOrigin);
|
||||
|
||||
for(unsigned int i = 0; i < textData_.size(); ++i)
|
||||
for(unsigned int i = 0; i <= textIndexMax; ++i)
|
||||
{
|
||||
Font::GlyphInfo glyph;
|
||||
|
||||
@ -146,10 +154,6 @@ void Text::draw()
|
||||
|
||||
rect.x += static_cast<int>(glyph.advance * scale);
|
||||
|
||||
if((static_cast<float>(rect.x) - xOrigin) > imageMaxWidth)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user