@@ -100,10 +100,7 @@ PineTimeStyle::PineTimeStyle(DisplayApp* app,
100100 lv_obj_set_style_local_text_color (batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex (0x000000 ));
101101 lv_label_set_text (batteryIcon, Symbols::batteryFull);
102102 lv_obj_align (batteryIcon, sidebar, LV_ALIGN_IN_TOP_MID, 0 , 2 );
103-
104- batteryPlug = lv_label_create (lv_scr_act (), nullptr );
105- lv_obj_set_style_local_text_color (batteryPlug, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex (0x000000 ));
106- lv_obj_align (batteryPlug, sidebar, LV_ALIGN_IN_TOP_MID, 0 , 2 );
103+ lv_obj_set_auto_realign (batteryIcon, true );
107104
108105 bleIcon = lv_label_create (lv_scr_act (), nullptr );
109106 lv_obj_set_style_local_text_color (bleIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex (0x000000 ));
@@ -205,18 +202,24 @@ PineTimeStyle::~PineTimeStyle() {
205202 lv_obj_clean (lv_scr_act ());
206203}
207204
205+ void PineTimeStyle::SetBatteryIcon () {
206+ auto batteryPercent = batteryPercentRemaining.Get ();
207+ lv_label_set_text (batteryIcon, BatteryIcon::GetBatteryIcon (batteryPercent));
208+ }
209+
208210void PineTimeStyle::Refresh () {
209- batteryPercentRemaining = batteryController.PercentRemaining ();
210- if (batteryPercentRemaining.IsUpdated ()) {
211- auto batteryPercent = batteryPercentRemaining.Get ();
212- if (batteryController.IsCharging ()) {
213- auto isCharging = batteryController.IsCharging () || batteryController.IsPowerPresent ();
214- lv_label_set_text (batteryPlug, BatteryIcon::GetPlugIcon (isCharging));
215- lv_obj_realign (batteryPlug);
216- lv_label_set_text (batteryIcon, " " );
211+ isCharging = batteryController.IsCharging ();
212+ if (isCharging.IsUpdated ()) {
213+ if (isCharging.Get ()) {
214+ lv_label_set_text (batteryIcon, Symbols::plug);
217215 } else {
218- lv_label_set_text (batteryIcon, BatteryIcon::GetBatteryIcon (batteryPercent));
219- lv_label_set_text (batteryPlug, " " );
216+ SetBatteryIcon ();
217+ }
218+ }
219+ if (!isCharging.Get ()) {
220+ batteryPercentRemaining = batteryController.PercentRemaining ();
221+ if (batteryPercentRemaining.IsUpdated ()) {
222+ SetBatteryIcon ();
220223 }
221224 }
222225
0 commit comments