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

Author Topic: Multiple Colors in sf::Text  (Read 6002 times)

0 Members and 1 Guest are viewing this topic.

NGM88

  • Full Member
  • ***
  • Posts: 162
    • View Profile
Multiple Colors in sf::Text
« on: January 06, 2019, 09:26:10 am »
Would it be possible to have sf::Text use multiple colors? As far as implementation goes, it could hold a vector of strings instead of one and you could do something like

txtObject.addString("str", sf::Color::Red)

instead of just setString().

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Multiple Colors in sf::Text
« Reply #1 on: January 06, 2019, 01:44:47 pm »
This would lead to a complex formatting feature -- the next request would be to apply style (bold/italics/underline) and size (pt) partially.

It's possible to build such a formatter out of separate sf::Text instances, and it has been done before, IIRC one of them with a markup language similar to HTML. If you look on the forum or the Wiki, you should find such extensions.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Multiple Colors in sf::Text
« Reply #2 on: January 06, 2019, 02:41:18 pm »
There are extension libraries like RichText that provide such features: https://github.com/skyrpex/RichText

I'd say it's not necessarily out of SFML's scope, but since it can be implemented in many ways with certain trade-offs, it's not as simple to pick an API that works for most everyone.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/