From 75724b29ebac3c6165e488d9ad1fffd84090f84b Mon Sep 17 00:00:00 2001 From: Norbert Walter Date: Sat, 28 Feb 2026 23:06:30 +0000 Subject: [PATCH] Fix for drawButtonCenter() --- lib/obp60task/OBP60Extensions.cpp | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/lib/obp60task/OBP60Extensions.cpp b/lib/obp60task/OBP60Extensions.cpp index 4b33954..46cb4e8 100644 --- a/lib/obp60task/OBP60Extensions.cpp +++ b/lib/obp60task/OBP60Extensions.cpp @@ -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 } }