1
0
mirror of https://github.com/thooge/esp32-nmea2000-obp60.git synced 2026-08-18 18:32:30 +02:00

Fix for drawButtonCenter()

This commit is contained in:
Norbert Walter
2026-02-28 23:06:30 +00:00
parent abcbf50422
commit 75724b29eb
+5 -18
View File
@@ -503,39 +503,26 @@ void drawTextCenter(int16_t cx, int16_t cy, String text) {
// Draw centered botton with centered text
void drawButtonCenter(int16_t cx, int16_t cy, int8_t sx, int8_t sy, String text, uint16_t fg, uint16_t bg, bool inverted) {
uint16_t color;
#ifndef DISPLAY_ST7796
int16_t x1, y1;
uint16_t w, h;
#ifdef DISPLAY_ST7796
w = getdisplay().textWidth(text);
h = getdisplay().fontHeight();
#else
int16_t x1, y1;
getdisplay().getTextBounds(text, cx, cy, &x1, &y1, &w, &h); // Find text center
#endif
//getdisplay().drawPixel(cx, cy, fg); // Debug pixel for center position
if (inverted) {
getdisplay().fillRoundRect(cx - sx / 2, cy - sy / 2, sx, sy, 5, fg); // Draw button
getdisplay().setTextColor(bg);
#ifdef DISPLAY_ST7796
auto oldDatum = getdisplay().getTextDatum();
getdisplay().setTextDatum(textdatum_t::middle_center);
getdisplay().drawString(text, cx, cy);
getdisplay().setTextDatum(oldDatum);
#else
getdisplay().setCursor(cx - w/2, cy + h/2); // Set cursor to center
getdisplay().print(text); // Draw text
#endif
}
else{
getdisplay().drawRoundRect(cx - sx / 2, cy - sy / 2, sx, sy, 5, fg); // Draw button
getdisplay().setTextColor(fg);
#ifdef DISPLAY_ST7796
auto oldDatum = getdisplay().getTextDatum();
getdisplay().setTextDatum(textdatum_t::middle_center);
getdisplay().drawString(text, cx, cy);
getdisplay().setTextDatum(oldDatum);
#else
getdisplay().setCursor(cx - w/2, cy + h/2); // Set cursor to center
getdisplay().print(text); // Draw text
#endif
}
}