From 022d01608d80ba0338b173c3f0e07069f6333a92 Mon Sep 17 00:00:00 2001 From: Michele Bini Date: Wed, 30 Mar 2022 22:16:43 +0200 Subject: digital watch face: simplify code and display a bit diff --git a/src/displayapp/screens/WatchFaceDigital.cpp b/src/displayapp/screens/WatchFaceDigital.cpp index e33a403..8c5b6a8 100644 --- a/src/displayapp/screens/WatchFaceDigital.cpp +++ b/src/displayapp/screens/WatchFaceDigital.cpp @@ -34,7 +34,7 @@ WatchFaceDigital::WatchFaceDigital(DisplayApp* app, batteryIcon = lv_label_create(lv_scr_act(), nullptr); lv_label_set_text_fmt(batteryIcon, "B##%%"); lv_obj_set_style_local_text_font(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &neofont1); - lv_obj_align(batteryIcon, lv_scr_act(), LV_ALIGN_IN_TOP_RIGHT, 0, 0); + lv_obj_align(batteryIcon, nullptr, LV_ALIGN_IN_TOP_RIGHT, 0, 0); batteryPlug = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(batteryPlug, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xFFFF00)); @@ -52,18 +52,23 @@ WatchFaceDigital::WatchFaceDigital(DisplayApp* app, lv_obj_align(notificationIcon, nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 0); label_date = lv_label_create(lv_scr_act(), nullptr); - lv_obj_align(label_date, lv_scr_act(), LV_ALIGN_CENTER, 0, 60); + lv_obj_align(label_date, nullptr, LV_ALIGN_CENTER, 0, 60); + lv_obj_set_auto_realign(label_date, true); lv_obj_set_style_local_text_color(label_date, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x999999)); lv_obj_set_style_local_text_font(label_date, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &neofont2); label_time = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_font(label_time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &neofont3); + lv_label_set_text_fmt(label_time, hhmm_label_text); + lv_obj_align(label_time, nullptr, LV_ALIGN_CENTER, 0, 0); + lv_label_set_long_mode(label_time, LV_LABEL_LONG_CROP); + lv_label_set_align(label_time, LV_LABEL_ALIGN_RIGHT); - lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_IN_RIGHT_MID, 0, 0); - - label_time_ampm = lv_label_create(lv_scr_act(), nullptr); - lv_label_set_text_static(label_time_ampm, ""); - lv_obj_align(label_time_ampm, lv_scr_act(), LV_ALIGN_IN_RIGHT_MID, -30, -55); + label_time_pm = lv_label_create(lv_scr_act(), nullptr); + lv_label_set_text_static(label_time_pm, "P"); + lv_obj_set_style_local_text_font(label_time_pm, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &neofont1); + lv_obj_align(label_time_pm, label_time, LV_ALIGN_OUT_LEFT_TOP, 0, 0); + lv_obj_set_hidden(label_time_pm, 1); backgroundLabel = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_click(backgroundLabel, true); @@ -131,24 +136,27 @@ void WatchFaceDigital::Refresh() { if (displayedHour != hour || displayedMinute != minute) { displayedHour = hour; displayedMinute = minute; - + bool hide_pm = true; + uint8_t h0; if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) { - char ampmChar[3] = "AM"; if (hour == 0) { hour = 12; } else if (hour == 12) { - ampmChar[0] = 'P'; + hide_pm = false; } else if (hour > 12) { - hour = hour - 12; - ampmChar[0] = 'P'; + hour -= 12; + hide_pm = false; } - lv_label_set_text(label_time_ampm, ampmChar); - lv_label_set_text_fmt(label_time, "%2d:%02d", hour, minute); - lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_IN_RIGHT_MID, 0, 0); + h0 = hour < 10 ? ' ' : '0' + (hour-10); } else { - lv_label_set_text_fmt(label_time, "%02d:%02d", hour, minute); - lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_CENTER, 0, 0); + h0 = '0' + (hour / 10); } + hhmm_label_text[0] = h0; + hhmm_label_text[1] = '0' + (hour%10); + hhmm_label_text[3] = '0' + (minute / 10); + hhmm_label_text[4] = '0' + (minute % 10); + lv_label_set_text_static(label_time, hhmm_label_text); + lv_obj_set_hidden(label_time_pm, hide_pm); } if ((year != currentYear) || (month != currentMonth) || (dayOfWeek != currentDayOfWeek) || (day != currentDay)) { @@ -159,7 +167,6 @@ void WatchFaceDigital::Refresh() { lv_label_set_text_fmt( label_date, "%s %s %d %d", dateTimeController.DayOfWeekShortToString(), dateTimeController.MonthShortToString(), day, year); } - lv_obj_realign(label_date); currentYear = year; currentMonth = month; diff --git a/src/displayapp/screens/WatchFaceDigital.h b/src/displayapp/screens/WatchFaceDigital.h index 572a783..eb95e6f 100644 --- a/src/displayapp/screens/WatchFaceDigital.h +++ b/src/displayapp/screens/WatchFaceDigital.h @@ -42,6 +42,8 @@ namespace Pinetime { Controllers::DateTime::Days currentDayOfWeek = Pinetime::Controllers::DateTime::Days::Unknown; uint8_t currentDay = 0; + char hhmm_label_text[6] = { '?', '?', ':', '?', '?', 0 }; + DirtyValue batteryPercentRemaining {}; DirtyValue powerPresent {}; DirtyValue bleState {}; @@ -51,7 +53,7 @@ namespace Pinetime { DirtyValue notificationState {}; lv_obj_t* label_time; - lv_obj_t* label_time_ampm; + lv_obj_t* label_time_pm; lv_obj_t* label_date; lv_obj_t* backgroundLabel; lv_obj_t* batteryIcon; -- cgit v0.10.2