Open Walley7 opened 11 years ago
The fix seems to work for LabelMultiline but makes TextBox crash.
Here's the fix on the fix:
Gwen::Point Gwen::Renderer::SFML2::MeasureText( Gwen::Font* pFont, const Gwen::UnicodeString& text )
{
// If the font doesn't exist, or the font size should be changed
if ( !pFont->data || fabs( pFont->realsize - pFont->size * Scale() ) > 2 )
{
FreeFont( pFont );
LoadFont( pFont );
}
const sf::Font* pSFFont = reinterpret_cast<sf::Font*>( pFont->data );
sf::FloatRect sz;
if (pSFFont) {
if ( text != L" " ) {
sf::Text sfStr;
sfStr.setString( text );
sfStr.setFont( *pSFFont );
sfStr.setScale( Scale(), Scale() );
sfStr.setCharacterSize( pFont->realsize );
sz = sfStr.getLocalBounds();
}
// SFML gives 0 dimensions for a space, use line spacing instead
sz.height = pSFFont->getLineSpacing( pFont->realsize );
}
return Gwen::Point( sz.left + sz.width, sz.top + sz.height );
}
The text in text entries was moving up/down depending on what character was typed and not handling trailing and preceding spaces properly. Final fix?
Gwen::Point Gwen::Renderer::SFML2::MeasureText( Gwen::Font* pFont, const Gwen::UnicodeString& text )
{
// If the font doesn't exist, or the font size should be changed
if ( !pFont->data || fabs( pFont->realsize - pFont->size * Scale() ) > 2 )
{
FreeFont( pFont );
LoadFont( pFont );
}
const sf::Font* pSFFont = reinterpret_cast<sf::Font*>( pFont->data );
Gwen::Point sz;
if ( pSFFont ) {
for ( Gwen::UnicodeString::const_iterator it = text.begin(); it != text.end(); ++it ) {
sz.x += pSFFont->getGlyph( *it, pFont->realsize, false ).advance * Scale();
}
sz.y = pSFFont->getLineSpacing( pFont->realsize ) * Scale();
}
return sz;
}
(I ninja-edited a multiplication by Scale())
SFML2 returns a width of 0 for the space glyph, which end up connecting to issues caused with multi line labels (all text ends up on the same line due to bounds not incrementing correctly). This may apply to SFML as well, though I haven't checked.
A semi hacky solution (tested to solve the multi line problem, but not much beyond that) is the following MeasureText function (the last 4 lines in the else statement being the brunt of the fix):