added new function to have text automaticly at the bottom
This commit is contained in:
@@ -3,13 +3,16 @@
|
||||
|
||||
//constructor
|
||||
DisplayText::DisplayText(Adafruit_ST7796S_kbv& tftDisplay) : tft(tftDisplay) {
|
||||
|
||||
tft.setCursor(0,0);
|
||||
}
|
||||
|
||||
void DisplayText::writeText(char* text, int size, int posX, int posY, int screenTime, bool center) {
|
||||
void DisplayText::writeText(char* text, int size, int posX, int posY, int screenTime, bool center, bool bottom) {
|
||||
if (center) {
|
||||
posX = centerText(text);
|
||||
}
|
||||
if (bottom) {
|
||||
posY = bottomText(text);
|
||||
}
|
||||
tft.setCursor(posX, posY);
|
||||
tft.setTextSize(size);
|
||||
tft.println(text);
|
||||
@@ -22,4 +25,12 @@ int DisplayText::centerText(char* text) {
|
||||
tft.getTextBounds(text, 0, 0, &x1, &y1, &w, &h);
|
||||
int x = (tft.width() - w) / 2;
|
||||
return x;
|
||||
}
|
||||
|
||||
int DisplayText::bottomText(char* text) {
|
||||
int16_t x1, y1;
|
||||
uint16_t w, h;
|
||||
tft.getTextBounds(text, 0, 0, &x1, &y1, &w, &h);
|
||||
int y = (tft.height() - h);
|
||||
return y;
|
||||
}
|
@@ -8,10 +8,11 @@ class DisplayText {
|
||||
private:
|
||||
Adafruit_ST7796S_kbv& tft;
|
||||
int centerText(char* text);
|
||||
int bottomText(char* text);
|
||||
|
||||
public:
|
||||
DisplayText(Adafruit_ST7796S_kbv& tftDisplay);
|
||||
void writeText(char* text, int size, int posX, int posY, int screenTime, bool center);
|
||||
void writeText(char* text, int size, int posX, int posY, int screenTime, bool center, bool bottom);
|
||||
};
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user