diff options
| author | Jean-François Milants <jf@codingfield.com> | 2025-12-26 14:50:01 +0100 |
|---|---|---|
| committer | JF <JF002@users.noreply.github.com> | 2026-01-05 13:19:06 +0100 |
| commit | c451d2ce9fae0c491a5e516a85f2faf1cf25273e (patch) | |
| tree | b6c58142c8c0ff6f0056af3a7df47bed0b1899a6 /src/displayapp/screens/BatteryIcon.cpp | |
| parent | 8d87a9ed2a7ba4c04d24862f85306f7496b3d6f5 (diff) | |
Refactor battery color calculation logic into `BatteryIcon::ColorFromPercentage()`.
Diffstat (limited to 'src/displayapp/screens/BatteryIcon.cpp')
| -rw-r--r-- | src/displayapp/screens/BatteryIcon.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/displayapp/screens/BatteryIcon.cpp b/src/displayapp/screens/BatteryIcon.cpp index 6194807d..ec740e93 100644 --- a/src/displayapp/screens/BatteryIcon.cpp +++ b/src/displayapp/screens/BatteryIcon.cpp @@ -3,6 +3,7 @@ #include "displayapp/screens/Symbols.h" #include "displayapp/icons/battery/batteryicon.c" #include "displayapp/InfiniTimeTheme.h" +#include <lvgl/src/lv_misc/lv_color.h> using namespace Pinetime::Applications::Screens; @@ -51,3 +52,12 @@ const char* BatteryIcon::GetPlugIcon(bool isCharging) { else return ""; } + +lv_color_t BatteryIcon::ColorFromPercentage(int batteryPercent) { + // HSV color model has red at 0° and green at 120°. + // We lock saturation and brightness at 100% and traverse the cylinder + // between red and green, thus avoiding the darker RGB on medium battery + // charges and giving us a much nicer color range. + const uint8_t hue = batteryPercent * 120 / 100; + return lv_color_hsv_to_rgb(hue, 100, 100); +} |
