Quantcast
Channel: Questions in topic: "bold"
Viewing all articles
Browse latest Browse all 19

How to bold only the selected characters from a text?

$
0
0

Hi all!


I am making an educational game for children where they need to bold **names** from a paragraph of story-type text.


So far I have figured out a way to bold the selected characters but it has some issues. I use TextMeshPro Input Field with Read Only and Rich Text enabled, so the characters can be selected by highlighting. I wrote a script that adds and tags around the selected text when a key is pressed. To detect the position where to insert them I used TMP_TextUtilities.FindNearestCharacter which works quite well.


The problem however is that when I keep bolding the words from the text, the index number of characters change as the bolding tags are calculated as well. The FindNearestCharacter method doesn't seem to count the tags though, so after a while the bolding has offset. I tried to counter this by creating a calculation that would take the increase in characters into account but it works only for some time. At some point the offset appears.


Another problem occurs in the case if the selected characters are already bold. Instead of adding extra tags there I would need to remove the existing tags if I want to unbold the characters.


So I am asking is there any other way to bold the selected text than to add HTML tags? It is enough if the text appears to be bold even though in reality it is not.


My coding level is somewhere between beginner and intermediate, so I am quite clueless how to continue from this or is it even possible with the UI text.


Viewing all articles
Browse latest Browse all 19

Latest Images

Trending Articles





Latest Images