SFML community forums

Help => Graphics => Topic started by: makerimages on December 11, 2013, 03:03:08 pm

Title: [2.1] sf::Text wrap at a specific X co-ord
Post by: makerimages on December 11, 2013, 03:03:08 pm
hey, lets say I have a text like this:
contentT=sf::Text(content,*game->getGuiFont());
        contentT.setColor(sf::Color::Black);
        contentT.setCharacterSize(16);
        contentT.setPosition(xPos-170, yPos-70);
 

and it has a long piece of text(like ddddddddddddddddiwwwwwwwwwwwwwwwwwwwwwwwwwwwaaaaa) in it, the xPos and yPos are relative to the current object these are in, the whole container width is 349px

How could I now make the contentT, when drawed- do a line wrap at lets say xPos+170 ? and go to the next line at xPos-170 again?
Title: Re: [2.1] sf::Text wrap at a specific X co-ord
Post by: Nexus on December 11, 2013, 03:14:00 pm
You have to adapt the strings correspondingly. Either you insert "\n" characters or you use multiple sf::Text objects aligned below each other.

To know where to break your string, you have to sum up character widths until your threshold is reached. Have a look at the sf::Font and sf::Glyph classes, they provide you with the information you need.
Title: Re: [2.1] sf::Text wrap at a specific X co-ord
Post by: Laurent on December 11, 2013, 07:16:52 pm
Don't forget Text::findCharacterPos.