solarus
solarus copied to clipboard
text_surface:get_size() returns zero for space character(s)
If a text_surface has text comprised entirely of space characters, then text_surface:get_size() returns 0 for both return values. This happens both for outline fonts and bitmap fonts.
Example:
text_surface:set_text" " --2 spaces
text_surface:get_size() --returns 0, 0
text_surface:set_text" a" --2 spaces followed by a
text_surface:get_size() --returns 14, 18
text_surface:set_text" " --4 spaces
text_surface:get_size() --returns 0, 0
text_surface:set_text" a" --4 spaces followed by a
text_surface:get_size() --returns 20, 18
For another example, see my quest at https://github.com/llamaizing/cythera-tech-demo
- Talk to an NPC to bring up the conversation dialog
- There is a text field where the player can enter text using the keyboard
- The text field has a blinking text entry cursor that has its horizontal position set to the first return value of text_surface:get_size()
- Enter several spaces in the text field and the blinking cursor does not move
- Now enter a non-space character and the cursor jumps the distance of the spaces plus the non-space character