Merge pull request #247 from jquatier/ui-text-width

UI Text Width - minor improvement
This commit is contained in:
ripplebiz 2025-05-05 11:53:47 +10:00 committed by GitHub
commit 1f06d22bde
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 30 additions and 8 deletions

View file

@ -24,5 +24,6 @@ public:
virtual void fillRect(int x, int y, int w, int h) = 0;
virtual void drawRect(int x, int y, int w, int h) = 0;
virtual void drawXbm(int x, int y, const uint8_t* bits, int w, int h) = 0;
virtual uint16_t getTextWidth(const char* str) = 0;
virtual void endFrame() = 0;
};

View file

@ -94,6 +94,13 @@ void GxEPDDisplay::drawXbm(int x, int y, const uint8_t* bits, int w, int h) {
display.drawBitmap(x*1.5, (y*1.5) + 10, bits, w, h, GxEPD_BLACK);
}
uint16_t GxEPDDisplay::getTextWidth(const char* str) {
int16_t x1, y1;
uint16_t w, h;
display.getTextBounds(str, 0, 0, &x1, &y1, &w, &h);
return w;
}
void GxEPDDisplay::endFrame() {
display.display(true);
}

View file

@ -47,5 +47,6 @@ public:
void fillRect(int x, int y, int w, int h) override;
void drawRect(int x, int y, int w, int h) override;
void drawXbm(int x, int y, const uint8_t* bits, int w, int h) override;
uint16_t getTextWidth(const char* str) override;
void endFrame() override;
};

View file

@ -62,6 +62,13 @@ void SSD1306Display::drawXbm(int x, int y, const uint8_t* bits, int w, int h) {
display.drawBitmap(x, y, bits, w, h, SSD1306_WHITE);
}
uint16_t SSD1306Display::getTextWidth(const char* str) {
int16_t x1, y1;
uint16_t w, h;
display.getTextBounds(str, 0, 0, &x1, &y1, &w, &h);
return w;
}
void SSD1306Display::endFrame() {
display.display();
}

View file

@ -36,5 +36,6 @@ public:
void fillRect(int x, int y, int w, int h) override;
void drawRect(int x, int y, int w, int h) override;
void drawXbm(int x, int y, const uint8_t* bits, int w, int h) override;
uint16_t getTextWidth(const char* str) override;
void endFrame() override;
};

View file

@ -107,6 +107,10 @@ void ST7789Display::drawXbm(int x, int y, const uint8_t* bits, int w, int h) {
display.drawBitmap(x+X_OFFSET, y, w, h, bits);
}
uint16_t ST7789Display::getTextWidth(const char* str) {
return display.getStringWidth(str);
}
void ST7789Display::endFrame() {
display.display();
}

View file

@ -31,5 +31,6 @@ public:
void fillRect(int x, int y, int w, int h) override;
void drawRect(int x, int y, int w, int h) override;
void drawXbm(int x, int y, const uint8_t* bits, int w, int h) override;
uint16_t getTextWidth(const char* str) override;
void endFrame() override;
};