Bodmer / TFT_eSPI

Arduino and PlatformIO IDE compatible TFT library optimised for the Raspberry Pi Pico (RP2040), STM32, ESP8266 and ESP32 that supports different driver chips
Other
3.79k stars 1.09k forks source link

Centre Text #1977

Closed ghost closed 2 years ago

ghost commented 2 years ago

How can i print a word in the centre of my display? using the ST7735 library I use tft.setCursor(tft.width() / 2, 15, true); that prints any length word in the top centre of my display but the eSPI library starts the word in the centre

ive tried using the string align example but still cant figure it out

zuhairmst commented 2 years ago

Use the function setTextDATUM() with MC_DATUM which means middle centre.

ghost commented 2 years ago

How do I print something Top Centre and 15px from top?

zuhairmst commented 2 years ago

tft.setTextDatum(TC_DATUM); tft.setCursor(width/2,15);

Bodmer commented 2 years ago

The print stream cannot be used with text formatting for technical reasons. Use drawString():

tft.setTextDatum(MC_DATUM);
tft.drawString("Hello", tft.width() / 2, 15);