Hello Everyone! I have a 160 pixel wide tft display. I would like to display variable width text with a width of 145 pixels, so that it always falls in the middle. How do you do this? I tried this, but obviously it's not good:
The center of the screen is SCREEN_WIDTH/2
Calculate the length of the text and divide it by two. TEXT_LENGTH/2
Text length will depend on the font size of the text. (* pixels per character)
Start text at SCREEN_WIDTH/2 - (TEXT_LENGTH * PIXELS_PER_CHAR)/2
I moved your topic to an appropriate forum category @azxo1 .
In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.
Thank you very much, it works. "-58" is included in the code because another data appears on the screen there.
SCREEN_WIDTH/2 - (TEXT_LENGTH * PIXELS_PER_CHAR)/2