Skip to content

Commit f181cd7

Browse files
committed
BatteryIcon: Round level to nearest pixel, low-battery colours on PineTimeStyle
The battery fill is rounded to the nearest pixel instead of down, so 99% shows as full. PineTimeStyle's battery icon now turns orange at 15% and below and red at 5% and below, like the status bar icon. Closes #2306
1 parent 5f2d566 commit f181cd7

3 files changed

Lines changed: 13 additions & 5 deletions

File tree

‎src/displayapp/screens/BatteryIcon.cpp‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,27 @@ lv_obj_t* BatteryIcon::GetObject() {
2626
}
2727

2828
void BatteryIcon::SetBatteryPercentage(uint8_t percentage) {
29-
lv_obj_set_height(batteryJuice, percentage * 14 / 100);
29+
lv_obj_set_height(batteryJuice, (percentage * 14 + 50) / 100);
3030
lv_obj_realign(batteryJuice);
3131
if (colorOnLowBattery) {
3232
static constexpr int lowBatteryThreshold = 15;
3333
static constexpr int criticalBatteryThreshold = 5;
3434
if (percentage > lowBatteryThreshold) {
35-
SetColor(LV_COLOR_WHITE);
35+
ApplyColor(normalColor);
3636
} else if (percentage > criticalBatteryThreshold) {
37-
SetColor(LV_COLOR_ORANGE);
37+
ApplyColor(LV_COLOR_ORANGE);
3838
} else {
39-
SetColor(Colors::deepOrange);
39+
ApplyColor(Colors::deepOrange);
4040
}
4141
}
4242
}
4343

4444
void BatteryIcon::SetColor(lv_color_t color) {
45+
normalColor = color;
46+
ApplyColor(color);
47+
}
48+
49+
void BatteryIcon::ApplyColor(lv_color_t color) {
4550
lv_obj_set_style_local_image_recolor(batteryImg, LV_IMG_PART_MAIN, LV_STATE_DEFAULT, color);
4651
lv_obj_set_style_local_image_recolor_opa(batteryImg, LV_IMG_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_COVER);
4752
lv_obj_set_style_local_bg_color(batteryJuice, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, color);

‎src/displayapp/screens/BatteryIcon.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ namespace Pinetime {
2222
lv_obj_t* batteryImg;
2323
lv_obj_t* batteryJuice;
2424
bool colorOnLowBattery = false;
25+
lv_color_t normalColor = LV_COLOR_WHITE;
26+
27+
void ApplyColor(lv_color_t color);
2528
};
2629
}
2730
}

‎src/displayapp/screens/WatchFacePineTimeStyle.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ WatchFacePineTimeStyle::WatchFacePineTimeStyle(Controllers::DateTime& dateTimeCo
5353
Controllers::MotionController& motionController,
5454
Controllers::SimpleWeatherService& weatherService)
5555
: currentDateTime {{}},
56-
batteryIcon(false),
56+
batteryIcon(true),
5757
dateTimeController {dateTimeController},
5858
batteryController {batteryController},
5959
bleController {bleController},

0 commit comments

Comments
 (0)