Note: there is additional stuff in my version of the library: https://github.com/KurtE/ILI9341_t3n
The code has the concept of center,
Where you can output a string and have it centered at the center of the screen:
or specific X and center y, or center x and specific y...
Also it has an extra parameter on setCursor which says center the text here:
like:
Code:
tft.setCursor(width / 2, height - 30, true);
tft.print("Center");
The true says to center. Note the centering only works for one output, after that the text cursor will be at the end of that output.
The example ILI_Ada_fontTest4 in my library shows exampls of this in function: displayStuff1
Note: Several of the display libraries that ship with Teensydunio I believe we added this stuff... But I don't think it made it back into the ILI9341_t3 library.
But to do it manual:
With ILI9341_t3, I believe the functions are as thebigg mentioned:
Did you try calling measureTextWidth() / measureTextHeight() to retrieve the bounds of the rendered text?
If you want the text centered at some location: x, y
then something like:
int text_width = tft.measureTextWidth("45");
int text_height = tft.measureTextHeight("45");
tft.setCursor(x - (text_width/2), y - (text_height / 2));
tft.print("45");
Assuming you want it centered at that spot... May have to fudge
With ILI9341_t3n and some of the others we have:
Code:
void getTextBounds(const uint8_t *buffer, uint16_t len, int16_t x, int16_t y,
int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h);
void getTextBounds(const char *string, int16_t x, int16_t y, int16_t *x1,
int16_t *y1, uint16_t *w, uint16_t *h);
void getTextBounds(const String &str, int16_t x, int16_t y, int16_t *x1,
int16_t *y1, uint16_t *w, uint16_t *h);
int16_t strPixelLen(const char *str, uint16_t cb=0xffff); // optional number of characters...
Looks like the only example showing that is in the Kurts_ILI9341_t3n_FB_and_clip_test.ino.
Or like in the main libary .cpp file and see how it is used in the Centering code mentioned above.
The idea of these functions, is you pass in your string as well as where maybe you would be drawing it, or 0, 0 if you will compute that from this data.
And you pass in pointers to x, y, w, h to retrieve the bounding rectangle for where the text would output. Note, there are some characters in some fonts, that
may bias the text t0 actually output some pixels offset in the negative direction...