diff --git a/include/apps/widget/OswAppWidgets.h b/include/apps/widget/OswAppWidgets.h new file mode 100644 index 000000000..88c3dc361 --- /dev/null +++ b/include/apps/widget/OswAppWidgets.h @@ -0,0 +1,11 @@ +#pragma once + +#include +#include + +class OswAppWidget { + public: +#ifdef OSW_FEATURE_STATS_STEPS + static void drawStepHistory(OswUI* ui, uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint32_t max); +#endif +}; \ No newline at end of file diff --git a/src/apps/watchfaces/OswAppWatchfaceDigital.cpp b/src/apps/watchfaces/OswAppWatchfaceDigital.cpp index ec1e09138..584a17f38 100644 --- a/src/apps/watchfaces/OswAppWatchfaceDigital.cpp +++ b/src/apps/watchfaces/OswAppWatchfaceDigital.cpp @@ -5,6 +5,7 @@ #include "./apps/watchfaces/OswAppWatchface.h" #include "./apps/watchfaces/OswAppWatchfaceDigital.h" +#include "./apps/widget/OswAppWidgets.h" #include OSW_TARGET_PLATFORM_HEADER uint8_t OswAppWatchfaceDigital::dateFormatCache = 42; @@ -137,7 +138,7 @@ const char* OswAppWatchfaceDigital::getAppName() { void OswAppWatchfaceDigital::drawSteps() { #ifdef OSW_FEATURE_STATS_STEPS uint8_t w = 8; - OswAppWatchface::drawStepHistory(OswUI::getInstance(), (DISP_W / 2) - w * 3.5f, 180, w, w * 4, OswConfigAllKeys::stepsPerDay.get()); + OswAppWidget::drawStepHistory(OswUI::getInstance(), (DISP_W / 2) - w * 3.5f, 180, w, w * 4, OswConfigAllKeys::stepsPerDay.get()); #else OswHal* hal = OswHal::getInstance(); uint32_t steps = hal->environment()->getStepsToday(); diff --git a/src/apps/widget/OswAppWidgets.cpp b/src/apps/widget/OswAppWidgets.cpp new file mode 100644 index 000000000..1d05e891c --- /dev/null +++ b/src/apps/widget/OswAppWidgets.cpp @@ -0,0 +1,44 @@ +#include +#include +#include +#include +#include "./apps/widget/OswAppWidgets.h" +#include OSW_TARGET_PLATFORM_HEADER + +#ifdef OSW_FEATURE_STATS_STEPS +void OswAppWidget::drawStepHistory(OswUI* ui, uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint32_t max) { + OswHal* hal = OswHal::getInstance(); + OswUI::getInstance()->resetTextColors(); + + OswDate oswDate = { }; + hal->getLocalDate(oswDate); + + for (uint8_t i = 0; i < 7; i++) { + uint32_t s = hal->environment()->getStepsOnDay(i); + uint16_t boxHeight = ((float)(s > max ? max : s) / max) * h; + boxHeight = boxHeight < 2 ? 0 : boxHeight; + + // step bars + uint16_t c = (unsigned int) OswConfigAllKeys::stepsPerDay.get() <= s ? ui->getSuccessColor() : ui->getPrimaryColor(); + hal->gfx()->fillFrame(x + i * w, y + (h - boxHeight), w, boxHeight, c); + // bar frames + uint16_t f = oswDate.weekDay == i ? ui->getForegroundColor() : ui->getForegroundDimmedColor(); + hal->gfx()->drawRFrame(x + i * w, y, w, h, 2, f); + + // labels + hal->gfx()->setTextCenterAligned(); // horiz. + hal->gfx()->setTextBottomAligned(); + hal->gfx()->setTextSize(1); + hal->gfx()->setTextCursor(DISP_W / 2, y - 1); + + hal->gfx()->print(hal->environment()->getStepsToday() + (OswConfigAllKeys::settingDisplayStepsGoal.get() ? String("/") + max:"")); + + hal->gfx()->setTextCursor(DISP_W / 2, y + 1 + 8 + w * 4); + hal->gfx()->setTextColor(ui->getForegroundColor()); // Let's make the background transparent. + // See : https://github.com/Open-Smartwatch/open-smartwatch-os/issues/194 + // font : WHITE / bg : None + hal->gfx()->print(hal->environment()->getStepsTotal()); + hal->gfx()->setTextColor(ui->getForegroundColor(), ui->getBackgroundColor()); // restore. font : WHITE / bg : BLACK + } +} +#endif \ No newline at end of file