From 7a6ede112e2a777321db16f367a6e4429604e5d9 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Tue, 26 Jul 2022 13:15:07 +0300 Subject: [PATCH] Remove clockType variable by checking for nullptr instead. Saves a few bytes --- src/displayapp/screens/Alarm.cpp | 16 ++++++++-------- src/displayapp/screens/Alarm.h | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/displayapp/screens/Alarm.cpp b/src/displayapp/screens/Alarm.cpp index d508dd39..bcb6eff8 100644 --- a/src/displayapp/screens/Alarm.cpp +++ b/src/displayapp/screens/Alarm.cpp @@ -43,12 +43,18 @@ Alarm::Alarm(DisplayApp* app, Controllers::AlarmController& alarmController, Controllers::Settings::ClockType clockType, System::SystemTask& systemTask) - : Screen(app), alarmController {alarmController}, clockType {clockType}, systemTask {systemTask} { + : Screen(app), alarmController {alarmController}, systemTask {systemTask} { hourCounter.Create(); lv_obj_align(hourCounter.GetObject(), nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 0); if (clockType == Controllers::Settings::ClockType::H12) { hourCounter.EnableTwelveHourMode(); + + lblampm = lv_label_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_text_font(lblampm, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_bold_20); + lv_label_set_text_static(lblampm, "AM"); + lv_label_set_align(lblampm, LV_LABEL_ALIGN_CENTER); + lv_obj_align(lblampm, lv_scr_act(), LV_ALIGN_CENTER, 0, 30); } hourCounter.SetValue(alarmController.Hours()); hourCounter.SetValueChangedEventCallback(this, ValueChangedHandler); @@ -63,12 +69,6 @@ Alarm::Alarm(DisplayApp* app, lv_label_set_text_static(colonLabel, ":"); lv_obj_align(colonLabel, lv_scr_act(), LV_ALIGN_CENTER, 0, -29); - lblampm = lv_label_create(lv_scr_act(), nullptr); - lv_obj_set_style_local_text_font(lblampm, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_bold_20); - lv_label_set_text_static(lblampm, " "); - lv_label_set_align(lblampm, LV_LABEL_ALIGN_CENTER); - lv_obj_align(lblampm, lv_scr_act(), LV_ALIGN_CENTER, 0, 30); - btnStop = lv_btn_create(lv_scr_act(), nullptr); btnStop->user_data = this; lv_obj_set_event_cb(btnStop, btnEventHandler); @@ -179,7 +179,7 @@ void Alarm::OnValueChanged() { } void Alarm::UpdateAlarmTime() { - if (clockType == Controllers::Settings::ClockType::H12) { + if (lblampm != nullptr) { if (hourCounter.GetValue() >= 12) { lv_label_set_text_static(lblampm, "PM"); } else { diff --git a/src/displayapp/screens/Alarm.h b/src/displayapp/screens/Alarm.h index a64bbe81..fba9d5d9 100644 --- a/src/displayapp/screens/Alarm.h +++ b/src/displayapp/screens/Alarm.h @@ -42,10 +42,10 @@ namespace Pinetime { private: Controllers::AlarmController& alarmController; - const Controllers::Settings::ClockType clockType; System::SystemTask& systemTask; - lv_obj_t *lblampm, *btnStop, *txtStop, *btnRecur, *txtRecur, *btnInfo, *enableSwitch; + lv_obj_t *btnStop, *txtStop, *btnRecur, *txtRecur, *btnInfo, *enableSwitch; + lv_obj_t* lblampm = nullptr; lv_obj_t* txtMessage = nullptr; lv_obj_t* btnMessage = nullptr; lv_task_t* taskStopAlarm = nullptr;