diff options
| author | Michele Bini <michele.bini@gmail.com> | 2022-05-10 22:57:13 (GMT) |
|---|---|---|
| committer | Michele Bini <michele.bini@gmail.com> | 2022-05-10 22:57:13 (GMT) |
| commit | 20bf019ed739231714620010248f7e9e409aa919 (patch) | |
| tree | f487545ba633086678c6e0b2c6b0a85f40929612 | |
| parent | 2f0858fa0561d09d59ab4435c0b4342794738a77 (diff) | |
Remove redundant code in Timer App; inline CreateButtons
| -rw-r--r-- | src/displayapp/DisplayApp.cpp | 5 | ||||
| -rw-r--r-- | src/displayapp/screens/Timer.cpp | 38 | ||||
| -rw-r--r-- | src/displayapp/screens/Timer.h | 46 |
3 files changed, 39 insertions, 50 deletions
diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index 5c5aad2..0ce1002 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -184,10 +184,7 @@ void DisplayApp::Refresh() { LoadApp(Apps::NotificationsPreview, DisplayApp::FullRefreshDirections::Down); break; case Messages::TimerDone: - if (currentApp == Apps::Timer) { - auto* timer = static_cast<Screens::Timer*>(currentScreen.get()); - timer->SetDone(); - } else { + if (currentApp != Apps::Timer) { LoadApp(Apps::Timer, DisplayApp::FullRefreshDirections::Down); } break; diff --git a/src/displayapp/screens/Timer.cpp b/src/displayapp/screens/Timer.cpp index 935dbe2..459d5f6 100644 --- a/src/displayapp/screens/Timer.cpp +++ b/src/displayapp/screens/Timer.cpp @@ -11,44 +11,6 @@ void Timer::btnEventHandler(lv_obj_t* obj, lv_event_t event) { screen->OnButtonEvent(obj, event); } -void Timer::CreateButtons() { - if (btnMinutesUp != nullptr) { - return; - } - - btnMinutesUp = lv_btn_create(lv_scr_act(), nullptr); - btnMinutesUp->user_data = this; - lv_obj_set_event_cb(btnMinutesUp, btnEventHandler); - lv_obj_set_size(btnMinutesUp, 60, 40); - lv_obj_align(btnMinutesUp, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 20, -85); - txtMUp = lv_label_create(btnMinutesUp, nullptr); - lv_label_set_text_static(txtMUp, "+"); - - btnMinutesDown = lv_btn_create(lv_scr_act(), nullptr); - btnMinutesDown->user_data = this; - lv_obj_set_event_cb(btnMinutesDown, btnEventHandler); - lv_obj_set_size(btnMinutesDown, 60, 40); - lv_obj_align(btnMinutesDown, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 20, +35); - txtMDown = lv_label_create(btnMinutesDown, nullptr); - lv_label_set_text_static(txtMDown, "-"); - - btnSecondsUp = lv_btn_create(lv_scr_act(), nullptr); - btnSecondsUp->user_data = this; - lv_obj_set_event_cb(btnSecondsUp, btnEventHandler); - lv_obj_set_size(btnSecondsUp, 60, 40); - lv_obj_align(btnSecondsUp, lv_scr_act(), LV_ALIGN_IN_RIGHT_MID, -20, -85); - txtSUp = lv_label_create(btnSecondsUp, nullptr); - lv_label_set_text_static(txtSUp, "+"); - - btnSecondsDown = lv_btn_create(lv_scr_act(), nullptr); - btnSecondsDown->user_data = this; - lv_obj_set_event_cb(btnSecondsDown, btnEventHandler); - lv_obj_set_size(btnSecondsDown, 60, 40); - lv_obj_align(btnSecondsDown, lv_scr_act(), LV_ALIGN_IN_RIGHT_MID, -20, +35); - txtSDown = lv_label_create(btnSecondsDown, nullptr); - lv_label_set_text_static(txtSDown, "-"); -} - void Timer::Stop() { int32_t secondsRemaining = timerController.GetSecondsRemaining(); if (timerController.IsOvertime()) { diff --git a/src/displayapp/screens/Timer.h b/src/displayapp/screens/Timer.h index cb5aeb2..dd55602 100644 --- a/src/displayapp/screens/Timer.h +++ b/src/displayapp/screens/Timer.h @@ -19,13 +19,6 @@ namespace Pinetime::Applications::Screens { void Refresh() override; void RefreshRunning(); - inline void SetDone() { - lv_label_set_text_static(time, "00:00"); - RefreshRunning(); - secondsToSet = 0; - minutesToSet = 0; - CreateButtons(); - } private: static void btnEventHandler(lv_obj_t* obj, lv_event_t event); inline void OnButtonEvent(lv_obj_t* obj, lv_event_t event) { @@ -76,7 +69,44 @@ namespace Pinetime::Applications::Screens { } } } - void CreateButtons(); + + inline void CreateButtons() { + if (btnMinutesUp != nullptr) { + return; + } + + btnMinutesUp = lv_btn_create(lv_scr_act(), nullptr); + btnMinutesUp->user_data = this; + lv_obj_set_event_cb(btnMinutesUp, btnEventHandler); + lv_obj_set_size(btnMinutesUp, 60, 40); + lv_obj_align(btnMinutesUp, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 20, -85); + txtMUp = lv_label_create(btnMinutesUp, nullptr); + lv_label_set_text_static(txtMUp, "+"); + + btnMinutesDown = lv_btn_create(lv_scr_act(), nullptr); + btnMinutesDown->user_data = this; + lv_obj_set_event_cb(btnMinutesDown, btnEventHandler); + lv_obj_set_size(btnMinutesDown, 60, 40); + lv_obj_align(btnMinutesDown, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 20, +35); + txtMDown = lv_label_create(btnMinutesDown, nullptr); + lv_label_set_text_static(txtMDown, "-"); + + btnSecondsUp = lv_btn_create(lv_scr_act(), nullptr); + btnSecondsUp->user_data = this; + lv_obj_set_event_cb(btnSecondsUp, btnEventHandler); + lv_obj_set_size(btnSecondsUp, 60, 40); + lv_obj_align(btnSecondsUp, lv_scr_act(), LV_ALIGN_IN_RIGHT_MID, -20, -85); + txtSUp = lv_label_create(btnSecondsUp, nullptr); + lv_label_set_text_static(txtSUp, "+"); + + btnSecondsDown = lv_btn_create(lv_scr_act(), nullptr); + btnSecondsDown->user_data = this; + lv_obj_set_event_cb(btnSecondsDown, btnEventHandler); + lv_obj_set_size(btnSecondsDown, 60, 40); + lv_obj_align(btnSecondsDown, lv_scr_act(), LV_ALIGN_IN_RIGHT_MID, -20, +35); + txtSDown = lv_label_create(btnSecondsDown, nullptr); + lv_label_set_text_static(txtSDown, "-"); + } inline void DeleteButtons() { lv_obj_del(btnSecondsDown); btnSecondsDown = nullptr; |
