Enhance tft_drawText function to support background color

This commit is contained in:
Nacho 2026-05-28 21:33:56 +02:00
parent e158f50970
commit 60c1659875
2 changed files with 11 additions and 3 deletions

View File

@ -2,6 +2,8 @@
#include "defs/screen_defs.h" #include "defs/screen_defs.h"
#include "defs/defs.h" #include "defs/defs.h"
#include <TFT_eSPI.h>
int xPos = 0; int xPos = 0;
int yPos = 0; int yPos = 0;
@ -59,9 +61,15 @@ void tft_drawCenteredText(const char* text, int size, int yGlobal) {
composite.drawString(text, x, yGlobal); composite.drawString(text, x, yGlobal);
} }
void tft_drawText(const char* text, int size, int x, int y, uint16_t color) { void tft_drawText(const char* text, int size, int x, int y, uint16_t color, uint16_t bgColor = TFT_TRANSPARENT) {
composite.setTextSize(size); composite.setTextSize(size);
composite.setTextColor(color);
if (bgColor != TFT_TRANSPARENT) {
composite.setTextColor(color, bgColor);
} else {
composite.setTextColor(color);
}
composite.drawString(text, x, y); composite.drawString(text, x, y);
} }

View File

@ -12,7 +12,7 @@ void tft_drawBuffer();
void tft_clearBuffer(TFT_eSprite &buffer, uint16_t color = TFT_WHITE); void tft_clearBuffer(TFT_eSprite &buffer, uint16_t color = TFT_WHITE);
void tft_clearBuffer(uint16_t color = TFT_WHITE); void tft_clearBuffer(uint16_t color = TFT_WHITE);
void tft_drawCenteredText(const char* text, int factor, int y); void tft_drawCenteredText(const char* text, int factor, int y);
void tft_drawText(const char* text, int size, int x, int y, uint16_t color = TFT_BLACK); void tft_drawText(const char* text, int size, int x, int y, uint16_t color = TFT_BLACK, uint16_t bgColor = TFT_TRANSPARENT);
void tft_drawRectangle(int x, int y, int w, int h, uint16_t color = TFT_BLACK); void tft_drawRectangle(int x, int y, int w, int h, uint16_t color = TFT_BLACK);
#endif #endif