From 254c85246e8bb0c79a83c291323f06c2af3f9618 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Thu, 19 May 2022 12:08:47 +0300 Subject: [PATCH] Timer: Replace time label with Counter control hiding functionality --- src/displayapp/screens/Timer.cpp | 22 +++++++++++----------- src/displayapp/screens/Timer.h | 1 - 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/displayapp/screens/Timer.cpp b/src/displayapp/screens/Timer.cpp index 1cff1d64..a1df662a 100644 --- a/src/displayapp/screens/Timer.cpp +++ b/src/displayapp/screens/Timer.cpp @@ -12,11 +12,11 @@ static void btnEventHandler(lv_obj_t* obj, lv_event_t event) { Timer::Timer(DisplayApp* app, Controllers::TimerController& timerController) : Screen(app), timerController {timerController} { - time = lv_label_create(lv_scr_act(), nullptr); - lv_obj_set_style_local_text_font(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_76); - lv_obj_set_style_local_text_color(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); - lv_label_set_text_static(time, "00:00"); - lv_obj_align(time, lv_scr_act(), LV_ALIGN_CENTER, 0, -29); + lv_obj_t* colonLabel = lv_label_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_text_font(colonLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_76); + lv_obj_set_style_local_text_color(colonLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); + lv_label_set_text_static(colonLabel, ":"); + lv_obj_align(colonLabel, lv_scr_act(), LV_ALIGN_CENTER, 0, -29); minuteCounter.Create(); secondCounter.Create(); @@ -49,19 +49,20 @@ Timer::~Timer() { void Timer::Refresh() { if (timerController.IsRunning()) { uint32_t seconds = timerController.GetTimeRemaining() / 1000; - lv_label_set_text_fmt(time, "%02lu:%02lu", seconds / 60, seconds % 60); + minuteCounter.SetValue(seconds / 60); + secondCounter.SetValue(seconds % 60); } } void Timer::SetTimerRunning() { - lv_obj_set_hidden(minuteCounter.GetObject(), true); - lv_obj_set_hidden(secondCounter.GetObject(), true); + minuteCounter.HideControls(); + secondCounter.HideControls(); lv_label_set_text_static(txtPlayPause, "Pause"); } void Timer::SetTimerStopped() { - lv_obj_set_hidden(minuteCounter.GetObject(), false); - lv_obj_set_hidden(secondCounter.GetObject(), false); + minuteCounter.ShowControls(); + secondCounter.ShowControls(); lv_label_set_text_static(txtPlayPause, "Start"); } @@ -84,7 +85,6 @@ void Timer::OnButtonEvent(lv_obj_t* obj, lv_event_t event) { } void Timer::SetDone() { - lv_label_set_text_static(time, "00:00"); minuteCounter.SetValue(0); secondCounter.SetValue(0); SetTimerStopped(); diff --git a/src/displayapp/screens/Timer.h b/src/displayapp/screens/Timer.h index 2dcc5973..2797a4fa 100644 --- a/src/displayapp/screens/Timer.h +++ b/src/displayapp/screens/Timer.h @@ -23,7 +23,6 @@ namespace Pinetime::Applications::Screens { void SetTimerRunning(); void SetTimerStopped(); Controllers::TimerController& timerController; - lv_obj_t* time; lv_obj_t* msecTime; lv_obj_t* btnPlayPause; lv_obj_t* txtPlayPause;