Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: sf::Text for continuous text  (Read 1607 times)

0 Members and 1 Guest are viewing this topic.

lexected

  • Newbie
  • *
  • Posts: 8
    • View Profile
sf::Text for continuous text
« on: January 04, 2016, 01:19:49 pm »
Hello!

I'd like to ask whether it's possible to display continuous text using sf::Text. I thought I could somehow set the size of a line and then set the text happily, but I haven't found anything saying that it could be done that way...

Does anybody have experience with handling such thing? Is it possible?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sf::Text for continuous text
« Reply #1 on: January 04, 2016, 01:56:54 pm »
Maybe it's just me, but I have no idea what you mean with "continuous text" or "set the size of a line".
Laurent Gomila - SFML developer

lexected

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: sf::Text for continuous text
« Reply #2 on: January 04, 2016, 03:05:48 pm »
Sorry.

By continuous text I mean text that goes through several lines constrained by the size of a container it is in. For example, this text is going to get to the second line, because its length exceeded the size limit.

On my screen there's a line break after "this" in the previous sentence, and I didn't put it there - it must have been inserted automatically.

Is there a way to achieve something similar in SFML?
« Last Edit: January 04, 2016, 03:09:04 pm by lexected »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sf::Text for continuous text
« Reply #3 on: January 04, 2016, 03:55:14 pm »
You're not the first one to ask, so you may already find useful posts on this forum about this subject.

Otherwise, short answer: compute the position of every character (text.findCharacterPos) and insert a line break when the position exceeds the width of the container.
Laurent Gomila - SFML developer

lexected

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: sf::Text for continuous text
« Reply #4 on: January 05, 2016, 06:45:05 am »
Thank you!
It works, although it looks little tricky.