I've hit a roadblock while building my custom Text Field from scratch. It's hard, challenging, but fun and I am learning a lot from the experience. One thing that I have struggled to solve is:
Font Kerning.
Other experts on this network have advised me to keep redrawing the entire string to the screen when the user types something into the TextField. Originally, I wanted to redraw each character individually, so as to maintain complete control and to make things much simpler, however, I did face a rather challenging problem - and that is Kerning. If I was going to redraw character by character, I could need to know precisely which location each character should be drawn, and _how far away it should be drawn from the character to its left (or right, if you're using right-left settings). So, I thought, well, I am new in this regard, so I will go with their advice, and redraw the entire string. I have now lost the ability to:
Allow different font styles for each individual character.
I also cannot create a selection marker (you know, that blue thing that grows when you left click and hold and drag to select text...) because I am drawing everything as a string and not each character individually. If I did it my way, I would've stored the location of each character individually so that I could then use that location information to figure out where to begin and end the selection marker as the user was selecting text.
So, that being said, my problem is this:
Should I draw each character as it is being typed and store each character location so that I can redraw each character and make a selection marker - or - should I redraw an entire string every time the user types something, and try to find a way to get the location of characters so I can let the user "select text" and to also custom style each character or word or sentence if need be?
How should I handle this, and how do I know which Kerning (spacing between letters) to use for any given font that the user decides to use? If I can figure out how far apart each character should be from one another, I wouldn't even be asking this question, I'd already be half way through it. But I am stuck, and any help at all will be much appreciated.
Aucun commentaire:
Enregistrer un commentaire