Hey guys!
Im working with a 2.4 inch TFT screen, connected to a wemos D1 mini.
And I made a function thats draws the text in the center of a given X and Y coordinate.
uint16_t * displayHandler::placeTextInCenter(const String &textBuf, uint16_t x, uint16_t y, uint8_t textSize, uint16_t textColor){
int16_t x1, y1;
static uint16_t size[2] = {0, 0};
tft.setTextSize(textSize);
tft.setTextColor(textColor);
tft.getTextBounds(textBuf, x, y, &x1, &y1, &size[0], &size[1]); //calc width of new string
tft.setCursor(x - size[0] / 2, y - size[1] / 2);
tft.print(textBuf);
return size;
}
when I call this function with setTextSize = 2:
uint16_t *sizetxt = placeTextInCenter("Setup is done", (DISPLAY_X_MAX / 2), Y_OFFSET + (HEIGHT / 2), 2, ILI9341_BLUE);
Serial.println(sizetxt[0]);
Serial.println(sizetxt[1]);
Serial.print:
156 // width
16 // height
The text is neatly in the center.
But when I call this function with a bigger text size, say 3 setTextSize = 3:
uint16_t *sizetxt = placeTextInCenter("Setup is done", (DISPLAY_X_MAX / 2), Y_OFFSET + (HEIGHT / 2), 3, ILI9341_BLUE);
Serial.println(sizetxt[0]);
Serial.println(sizetxt[1]);
Serial.print:
304 // width
48 // height
But here not, somehow it thinks the string "setup is done" is way longer than it really is.
What is going on here?

