Reputation: 47
I have this snippet of code
void Graphics::render_text(std::string bunch_of_text) {
sf::Text text;
text.setFont(font); // font is a sf::Font
text.setString(bunch_of_text);
text.setCharacterSize(text_size); // in pixels, not points!
text.setFillColor(text_color);
text.setStyle(text_style);
window.draw(text);
window.display();
}
And sometimes this text is really long, and the remainder of the text can't be seen because of bounds.
Is there an opportunity to make text perfectly fitting on the screen, such as splitting text
into multiple parts or making a new line(\n
) inside the text
where needed?
Upvotes: 0
Views: 241
Reputation: 13589
Here's one idea (pseudocode):
text.getLocalBounds().width
> window.size().x
:
text.getCharacterSize()
and/or text.getLetterSpacing()
to do this calculation.text.setString()
to set the new string.Upvotes: 1