From 2b2d2e3fd61e8fffb64063ad442ae01c254a3604 Mon Sep 17 00:00:00 2001 From: Norbert Walter Date: Sat, 28 Feb 2026 23:14:38 +0000 Subject: [PATCH] Fix for drawButtonCenter() --- lib/obp60task/OBP60Extensions.cpp | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/lib/obp60task/OBP60Extensions.cpp b/lib/obp60task/OBP60Extensions.cpp index 46cb4e8..5c5bad6 100644 --- a/lib/obp60task/OBP60Extensions.cpp +++ b/lib/obp60task/OBP60Extensions.cpp @@ -487,41 +487,33 @@ std::vector wordwrap(String &line, uint16_t maxwidth) { // Draw centered text void drawTextCenter(int16_t cx, int16_t cy, String text) { -#ifdef DISPLAY_ST7796 - uint16_t w = getdisplay().textWidth(text); - uint16_t h = getdisplay().fontHeight(); - getdisplay().setCursor(cx - static_cast(w / 2), cy + static_cast(h / 2)); - getdisplay().print(text); -#else int16_t x1, y1; uint16_t w, h; - getdisplay().getTextBounds(text, 0, 150, &x1, &y1, &w, &h); - getdisplay().setCursor(cx - w / 2, cy + h / 2); + displayGetTextBounds(text, 0, 0, &x1, &y1, &w, &h); + int16_t cursorX = cx - (x1 + static_cast(w / 2)); + int16_t cursorY = cy - (y1 + static_cast(h / 2)); + getdisplay().setCursor(cursorX, cursorY); getdisplay().print(text); -#endif } // 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 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 + uint16_t w, h; + displayGetTextBounds(text, 0, 0, &x1, &y1, &w, &h); + int16_t cursorX = cx - (x1 + static_cast(w / 2)); + int16_t cursorY = cy - (y1 + static_cast(h / 2)); //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); - getdisplay().setCursor(cx - w/2, cy + h/2); // Set cursor to center + getdisplay().setCursor(cursorX, cursorY); // Set cursor to center getdisplay().print(text); // Draw text } else{ getdisplay().drawRoundRect(cx - sx / 2, cy - sy / 2, sx, sy, 5, fg); // Draw button getdisplay().setTextColor(fg); - getdisplay().setCursor(cx - w/2, cy + h/2); // Set cursor to center + getdisplay().setCursor(cursorX, cursorY); // Set cursor to center getdisplay().print(text); // Draw text } }