diff options
Diffstat (limited to 'src/display.cpp')
-rw-r--r-- | src/display.cpp | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/src/display.cpp b/src/display.cpp index 104ce44..1aa91bc 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -168,17 +168,15 @@ void de::uvok::badge::display_direct(uint8_t num) void de::uvok::badge::display_indicator(DisplayIndicator indicator) { + LOG_F("Set indicator to %d\n", indicator); // no idea what do about initial state.. display.setRotation(rotation); display.setTextColor(GxEPD_BLACK); display.setFont(&FreeMono9pt7b); - const char *display_text; + const char *display_text = ""; switch (indicator) { - case DisplayIndicator::None: - display_text = ""; - break; case DisplayIndicator::Advertising: display_text = "Adv"; break; @@ -188,9 +186,19 @@ void de::uvok::badge::display_indicator(DisplayIndicator indicator) } int16_t tbx, tby; uint16_t tbw, tbh; - display.getTextBounds(display_text, 0, 0, &tbx, &tby, &tbw, &tbh); + constexpr int TEXT_BORDER_X = 3; + constexpr int TEXT_POS_Y = 15; + // For Y, cursor means the "bottom" line? + display.getTextBounds(display_text, TEXT_BORDER_X, TEXT_POS_Y, &tbx, &tby, &tbw, &tbh); + LOG_F("GTB for %s@%d,%d returned %d, %d, %d, %d\n", display_text, (int16_t)TEXT_BORDER_X, (int16_t)TEXT_POS_Y, tbx, + tby, tbw, tbh); + + // Determined by debugging + constexpr uint16_t max_width = 50; + constexpr uint16_t max_height = 18; + // right-align stuff + const uint16_t rect_x = display.width() - max_width; - constexpr int TEXT_BORDER = 3; display.firstPage(); do { @@ -203,13 +211,12 @@ void de::uvok::badge::display_indicator(DisplayIndicator indicator) } else { - display.setPartialWindow(tbx - TEXT_BORDER, tby - TEXT_BORDER, tbw + 2 * TEXT_BORDER, - tbh + 2 * TEXT_BORDER); + display.setPartialWindow(rect_x, 0, max_width, max_height); } - display.fillRect(tbx - TEXT_BORDER, tby - TEXT_BORDER, tbw + 2 * TEXT_BORDER, tbh + 2 * TEXT_BORDER, - GxEPD_WHITE); - display.setCursor(tbx, tby); + display.fillRect(rect_x, 0, max_width, max_height, GxEPD_WHITE); + + display.setCursor(TEXT_BORDER_X + rect_x, TEXT_POS_Y); display.print(display_text); } while (display.nextPage()); |