diff options
-rw-r--r-- | api.cpp | 21 | ||||
-rw-r--r-- | api.hpp | 7 |
2 files changed, 27 insertions, 1 deletions
@@ -59,7 +59,7 @@ bool Api::gui_popup_text(std::string title, std::string body){ oledRectangle(&m_oled, 9,7, 119,63, 0, 1); // Background oledRectangle(&m_oled, 9,7, 119,63, 1, 0); // Popup border - oledRectangle(&m_oled, 9,7, 119,16, 1, 1); // Title background + oledRectangle(&m_oled, 9,7, 119,16, 1, 1); // Title background, FIXME pixel bleeding oledDumpBuffer(&m_oled, m_ucBuffer); // Display rectangle // Truncate longer strings to avoid wasting time in for loop and drawing on OLED @@ -88,6 +88,25 @@ bool Api::gui_popup_text(std::string title, std::string body){ m_send_button_press_to_app = true; } +bool Api::gui_footer_text(std::string text, int offset_x, int offset_row, int invert) { + // Max chars per line for FONT_8x8 is 16 chars + // Max chars per line for FONT_6x8 is 21 chars + // Truncate longer text + if (text.size() > 21) + text.resize(21); + + // Choose most adapted font size + int font; + if (text.size() > 16) + font = FONT_6x8; + else + font = FONT_8x8; + + oledRectangle(&m_oled, 0,56, 128,64, invert, 1); + oledDumpBuffer(&m_oled, m_ucBuffer); + oledWriteString(&m_oled, 0,offset_x,7-offset_row, &text[0], font, invert, 1); +} + bool Api::datetime_get(datetime_t *t) { return rtc_get_datetime(t); } @@ -30,6 +30,13 @@ class Api { // \param body String containing the popup's body. The zone has a size of 13×6 characters, so body should not be longer than 78 characters. Newline allows going to the next line and the text is automatically wrapped. // \note Strings longer than 13 and 78 respectively will be truncated. bool gui_popup_text(std::string title, std::string body); + // Display text at the bottom of the screen. + // The font size is automatically choosen based on the text lenght. + // \param text Text to display. Text longer than 21 will be truncated. + // \param offset_x Set a horizental offset, to allow, for example, centering the text + // \param offset_row Allow rendering the text higher. For example, one line higher when `offset_row = 1`. + // \param invert allow inverting text and background color. + bool gui_footer_text(std::string text, int offset_x = 0, int offset_row = 0, int invert = 0); bool datetime_get(datetime_t *t); // Get last button pressed, see buttons.hpp for values uint button_last_get(); |