how to create a text cursor in sfml

Jul 6, 2022 at 8:03am
I want to create a text cursor, but i don't know how to properly, I've made a simple one, but it breaks when long characters like √ are in the sf::Text, how do i implement it properly? I've been suggested to use sf::Font::getGlyph()::bounds in combo with sf::Text::findCharacterPos(), but i don't know how it could help.

Jul 6, 2022 at 11:40pm
https://www.youtube.com/watch?v=T31MoLJws4U <- try out this video, jump to time 29:28 to see them show the results of their textbox code.
I haven't watched the whole video, but they seem to do a pretty thorough walk-through.
Jul 7, 2022 at 12:30am
@newbieg, I've watched it but the text cursor isn't really a text cursor, as it can't go to any point in the text except the end, which makes it more of a decoration than anything
what i need is to find if the mouse is touching a glyphs rectangle and the glyph's information

Last edited on Jul 7, 2022 at 12:38am
Jul 7, 2022 at 10:10am
sf::Text::findCharacterPos gives you the position of a character.

sf::Font::getGlyph gives you the size of the character.

If you know the position where the click was made it should be possible to use the above information to calculate which character that is clicked (or is closest). I haven't tried but it seems like it should be possible.
Last edited on Jul 7, 2022 at 11:32am
Topic archived. No new replies allowed.