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

Author Topic: Highlighting Text  (Read 2405 times)

0 Members and 1 Guest are viewing this topic.

Ant

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • Email
Highlighting Text
« on: January 02, 2015, 03:25:45 am »
Hello,

I'm designing a text field where the user can position a cursor in a middle of a text field, and select chunks of text to copy or overwrite the selected text.

One of my concerns with my plans is rendering the highlighted text.  A solution I thought of is having 3 instanced sf::Text (One Text contains the text before the highlight, the second contains the highlighted text with inverted colors, and the third is the text after the highlighted part).  Then I'll was thinking about drawing rectangles (one for each selected line) to represent the highlighted part.

This method sounds slower than it needs to be, and it seems strange to pass characters from one Text instance to another whenever the user is dragging the mouse.  I was curious if there was a better way of doing this.  Does this seem to be the right approach?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
AW: Highlighting Text
« Reply #1 on: January 02, 2015, 10:04:11 am »
The best method would be to use a shader.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Ant

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • Email
Re: Highlighting Text
« Reply #2 on: January 02, 2015, 10:03:16 pm »
Interesting suggestion!  Overlaying a material does sound much easier than aligning 3 Text instances.

I haven't worked with SFML shaders, but I'll read up its documentation.  I'll let you know what I find, or if I have additional questions.