aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorConfuSomu2021-03-01 20:28:36 -0500
committerConfuSomu2021-03-01 20:28:36 -0500
commit7c452f2abe26f7dbcd2646f0be944f03d96f0b44 (patch)
treeffae0efa590d45d432e49ac87503aa32adfffc33
parentdb15966f0e0e72b51b359d3c36399f14befe40a9 (diff)
downloadpico-watch-7c452f2abe26f7dbcd2646f0be944f03d96f0b44.tar
pico-watch-7c452f2abe26f7dbcd2646f0be944f03d96f0b44.tar.gz
pico-watch-7c452f2abe26f7dbcd2646f0be944f03d96f0b44.zip
Implement API method for display header text
-rw-r--r--api.cpp19
-rw-r--r--api.hpp7
2 files changed, 26 insertions, 0 deletions
diff --git a/api.cpp b/api.cpp
index 2617483..7279f19 100644
--- a/api.cpp
+++ b/api.cpp
@@ -107,6 +107,25 @@ bool Api::gui_footer_text(std::string text, int offset_x, int offset_row, int in
oledWriteString(&m_oled, 0,offset_x,7-offset_row, &text[0], font, invert, 1);
}
+bool Api::gui_header_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,0, 128,8, invert, 1);
+ oledDumpBuffer(&m_oled, m_ucBuffer);
+ oledWriteString(&m_oled, 0,offset_x,0+offset_row, &text[0], font, invert, 1);
+}
+
bool Api::datetime_get(datetime_t *t) {
return rtc_get_datetime(t);
}
diff --git a/api.hpp b/api.hpp
index 9dabacf..7e2a3e9 100644
--- a/api.hpp
+++ b/api.hpp
@@ -37,6 +37,13 @@ class Api {
// \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);
+ // Display text at the top 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 Render text lines lower. For example, one text line lower with `offset_row = 1`.
+ // \param invert Invert text and background color.
+ bool gui_header_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();