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:
@@ -503,39 +503,26 @@ void drawTextCenter(int16_t cx, int16_t cy, String text) {
|
|||||||
|
|
||||||
// Draw centered botton with centered 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) {
|
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;
|
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
|
getdisplay().getTextBounds(text, cx, cy, &x1, &y1, &w, &h); // Find text center
|
||||||
#endif
|
#endif
|
||||||
//getdisplay().drawPixel(cx, cy, fg); // Debug pixel for center position
|
//getdisplay().drawPixel(cx, cy, fg); // Debug pixel for center position
|
||||||
if (inverted) {
|
if (inverted) {
|
||||||
getdisplay().fillRoundRect(cx - sx / 2, cy - sy / 2, sx, sy, 5, fg); // Draw button
|
getdisplay().fillRoundRect(cx - sx / 2, cy - sy / 2, sx, sy, 5, fg); // Draw button
|
||||||
getdisplay().setTextColor(bg);
|
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().setCursor(cx - w/2, cy + h/2); // Set cursor to center
|
||||||
getdisplay().print(text); // Draw text
|
getdisplay().print(text); // Draw text
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
getdisplay().drawRoundRect(cx - sx / 2, cy - sy / 2, sx, sy, 5, fg); // Draw button
|
getdisplay().drawRoundRect(cx - sx / 2, cy - sy / 2, sx, sy, 5, fg); // Draw button
|
||||||
getdisplay().setTextColor(fg);
|
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().setCursor(cx - w/2, cy + h/2); // Set cursor to center
|
||||||
getdisplay().print(text); // Draw text
|
getdisplay().print(text); // Draw text
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user