Timer: Replace time label with Counter control hiding functionality

This commit is contained in:
Riku Isokoski 2022-05-19 12:08:47 +03:00 committed by JF
parent 4a40d29279
commit 254c85246e
2 changed files with 11 additions and 12 deletions

View File

@ -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} { Timer::Timer(DisplayApp* app, Controllers::TimerController& timerController) : Screen(app), timerController {timerController} {
time = lv_label_create(lv_scr_act(), nullptr); lv_obj_t* colonLabel = 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_font(colonLabel, 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_obj_set_style_local_text_color(colonLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
lv_label_set_text_static(time, "00:00"); lv_label_set_text_static(colonLabel, ":");
lv_obj_align(time, lv_scr_act(), LV_ALIGN_CENTER, 0, -29); lv_obj_align(colonLabel, lv_scr_act(), LV_ALIGN_CENTER, 0, -29);
minuteCounter.Create(); minuteCounter.Create();
secondCounter.Create(); secondCounter.Create();
@ -49,19 +49,20 @@ Timer::~Timer() {
void Timer::Refresh() { void Timer::Refresh() {
if (timerController.IsRunning()) { if (timerController.IsRunning()) {
uint32_t seconds = timerController.GetTimeRemaining() / 1000; 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() { void Timer::SetTimerRunning() {
lv_obj_set_hidden(minuteCounter.GetObject(), true); minuteCounter.HideControls();
lv_obj_set_hidden(secondCounter.GetObject(), true); secondCounter.HideControls();
lv_label_set_text_static(txtPlayPause, "Pause"); lv_label_set_text_static(txtPlayPause, "Pause");
} }
void Timer::SetTimerStopped() { void Timer::SetTimerStopped() {
lv_obj_set_hidden(minuteCounter.GetObject(), false); minuteCounter.ShowControls();
lv_obj_set_hidden(secondCounter.GetObject(), false); secondCounter.ShowControls();
lv_label_set_text_static(txtPlayPause, "Start"); 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() { void Timer::SetDone() {
lv_label_set_text_static(time, "00:00");
minuteCounter.SetValue(0); minuteCounter.SetValue(0);
secondCounter.SetValue(0); secondCounter.SetValue(0);
SetTimerStopped(); SetTimerStopped();

View File

@ -23,7 +23,6 @@ namespace Pinetime::Applications::Screens {
void SetTimerRunning(); void SetTimerRunning();
void SetTimerStopped(); void SetTimerStopped();
Controllers::TimerController& timerController; Controllers::TimerController& timerController;
lv_obj_t* time;
lv_obj_t* msecTime; lv_obj_t* msecTime;
lv_obj_t* btnPlayPause; lv_obj_t* btnPlayPause;
lv_obj_t* txtPlayPause; lv_obj_t* txtPlayPause;