Comment 30 for bug 1001033

Revision history for this message
Sam Bull (dreamsorcerer) wrote :

Unfortunately, that suggestion is no better. The rendered width of each character varies, so the there is no single value that can place the cursor in the correct place. If the character 'h' is 10 pixels and 'i' is 9 pixels, then 'hih' will be 29 pixels and the cursor would need to be placed at 0, 10, 19 and 29 pixels to make sense.

My solution for the labels, which works fine, is to find the rendered length of the first character, then the length of the first two characters, then the length of the first 3 characters and so on. Storing all these values allows me to work out the correct position.

Because there's quite a bit of repetition, this can take a little bit of CPU time. My only concern with the input box, is that it needs to recalculate all of this, everytime the user types something, and it is designed for use in games where a fraction of a millisecond can still be important to keep the game running smoothly.