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

Centering text in the middle/wrapping #3075

Closed xpresas closed 10 months ago

xpresas commented 10 months ago
  1. Simply Im writing a program that fetches direct messagess from discord bot api and I want to display them on the screen. Ive run into multiple problems which most of them I managed to make it work. (Playing gifs, uploading them to littlefs, swapping gifs and etc). Tbh I havent checked ALL of the examples because some are outdated and theres so much of them I just thought that Im going to write here and I might get help. The problem Im facing right now is pretty simple. I pull a message from discords api. That message contains a handful of words. I cant seem to find a way to
  1. Arduino v1.
  2. Latest
  3. Latest esp32 2.0.14
  4. ESP32-Wroom-32U (same old esp, just 38pin version)
  5. ST7789_DRIVER (320x240 from aliexpress)
  6. SPI
    tft.fillScreen(TFT_BLACK);
    tft.setTextColor(TFT_WHITE);
    tft.setTextSize(2);
    tft.setTextDatum(CC_DATUM);
   //this is weird, and I bet there is an easier way to manage this
    tft.drawString("Test1",tft.width() / 2,tft.height() / 2 - 15);
    tft.drawString("Test2",tft.width() / 2,tft.height() / 2 + 0);
    tft.drawString("Test3",tft.width() / 2,tft.height() / 2 + 15);

Basically if it would be possible to provide an example of how would I go about centering a text string while also wrapping it. I would appreciate it.

Bodmer commented 10 months ago

You will need to write code to split strings at an appropriate point and then plot each segment onto the screen. I do not have further example code to do this.