diff options
Diffstat (limited to 'src/displayapp/screens/BatteryIcon.cpp')
| -rw-r--r-- | src/displayapp/screens/BatteryIcon.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/displayapp/screens/BatteryIcon.cpp b/src/displayapp/screens/BatteryIcon.cpp index 2fe7c251..6194807d 100644 --- a/src/displayapp/screens/BatteryIcon.cpp +++ b/src/displayapp/screens/BatteryIcon.cpp @@ -2,9 +2,12 @@ #include <cstdint> #include "displayapp/screens/Symbols.h" #include "displayapp/icons/battery/batteryicon.c" +#include "displayapp/InfiniTimeTheme.h" using namespace Pinetime::Applications::Screens; +BatteryIcon::BatteryIcon(bool colorOnLowBattery) : colorOnLowBattery {colorOnLowBattery} {}; + void BatteryIcon::Create(lv_obj_t* parent) { batteryImg = lv_img_create(parent, nullptr); lv_img_set_src(batteryImg, &batteryicon); @@ -23,6 +26,17 @@ lv_obj_t* BatteryIcon::GetObject() { void BatteryIcon::SetBatteryPercentage(uint8_t percentage) { lv_obj_set_height(batteryJuice, percentage * 14 / 100); lv_obj_realign(batteryJuice); + if (colorOnLowBattery) { + static constexpr int lowBatteryThreshold = 15; + static constexpr int criticalBatteryThreshold = 5; + if (percentage > lowBatteryThreshold) { + SetColor(LV_COLOR_WHITE); + } else if (percentage > criticalBatteryThreshold) { + SetColor(LV_COLOR_ORANGE); + } else { + SetColor(Colors::deepOrange); + } + } } void BatteryIcon::SetColor(lv_color_t color) { |
