From 97048121b05abb2c51c09a4340fe0aa223f46182 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Fri, 22 Jul 2022 08:33:15 +0300 Subject: Use Counter widget in Alarm --- src/displayapp/screens/Alarm.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/displayapp/screens/Alarm.h') diff --git a/src/displayapp/screens/Alarm.h b/src/displayapp/screens/Alarm.h index 80e446f1..a64bbe81 100644 --- a/src/displayapp/screens/Alarm.h +++ b/src/displayapp/screens/Alarm.h @@ -21,6 +21,7 @@ #include "systemtask/SystemTask.h" #include "displayapp/LittleVgl.h" #include "components/alarm/AlarmController.h" +#include "displayapp/widgets/Counter.h" namespace Pinetime { namespace Applications { @@ -29,29 +30,28 @@ namespace Pinetime { public: Alarm(DisplayApp* app, Controllers::AlarmController& alarmController, - Pinetime::Controllers::Settings& settingsController, + Controllers::Settings::ClockType clockType, System::SystemTask& systemTask); ~Alarm() override; void SetAlerting(); void OnButtonEvent(lv_obj_t* obj, lv_event_t event); bool OnButtonPushed() override; bool OnTouchEvent(TouchEvents event) override; + void OnValueChanged(); void StopAlerting(); private: - uint8_t alarmHours; - uint8_t alarmMinutes; Controllers::AlarmController& alarmController; - Controllers::Settings& settingsController; + const Controllers::Settings::ClockType clockType; System::SystemTask& systemTask; - lv_obj_t *time, *lblampm, *btnStop, *txtStop, *btnMinutesUp, *btnMinutesDown, *btnHoursUp, *btnHoursDown, *txtMinUp, *txtMinDown, - *txtHrUp, *txtHrDown, *btnRecur, *txtRecur, *btnInfo, *txtInfo, *enableSwitch; + lv_obj_t *lblampm, *btnStop, *txtStop, *btnRecur, *txtRecur, *btnInfo, *enableSwitch; lv_obj_t* txtMessage = nullptr; lv_obj_t* btnMessage = nullptr; lv_task_t* taskStopAlarm = nullptr; enum class EnableButtonState { On, Off, Alerting }; + void DisableAlarm(); void SetRecurButtonState(); void SetSwitchState(lv_anim_enable_t anim); void SetAlarm(); @@ -59,6 +59,8 @@ namespace Pinetime { void HideInfo(); void ToggleRecurrence(); void UpdateAlarmTime(); + Widgets::Counter hourCounter = Widgets::Counter(0, 23, jetbrains_mono_76); + Widgets::Counter minuteCounter = Widgets::Counter(0, 59, jetbrains_mono_76); }; }; }; -- cgit v1.2.3-70-g09d2 From 7a6ede112e2a777321db16f367a6e4429604e5d9 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Tue, 26 Jul 2022 13:15:07 +0300 Subject: 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(-) (limited to 'src/displayapp/screens/Alarm.h') 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; -- cgit v1.2.3-70-g09d2