Timer App : add background label to ensure that the app will be displayed correctly after a full refresh (HW scrolling transition).

Code cleaning and rename methods.
This commit is contained in:
Jean-François Milants 2022-03-27 20:21:44 +02:00 committed by JF
parent 4761fcb63a
commit 8f436e1d74
3 changed files with 28 additions and 20 deletions

View File

@ -207,7 +207,7 @@ void DisplayApp::Refresh() {
case Messages::TimerDone: case Messages::TimerDone:
if (currentApp == Apps::Timer) { if (currentApp == Apps::Timer) {
auto* timer = static_cast<Screens::Timer*>(currentScreen.get()); auto* timer = static_cast<Screens::Timer*>(currentScreen.get());
timer->setDone(); timer->SetDone();
} else { } else {
LoadApp(Apps::Timer, DisplayApp::FullRefreshDirections::Down); LoadApp(Apps::Timer, DisplayApp::FullRefreshDirections::Down);
} }

View File

@ -1,5 +1,4 @@
#include "displayapp/screens/Timer.h" #include "displayapp/screens/Timer.h"
#include "displayapp/screens/Screen.h" #include "displayapp/screens/Screen.h"
#include "displayapp/screens/Symbols.h" #include "displayapp/screens/Symbols.h"
#include <lvgl/lvgl.h> #include <lvgl/lvgl.h>
@ -7,11 +6,11 @@
using namespace Pinetime::Applications::Screens; using namespace Pinetime::Applications::Screens;
static void btnEventHandler(lv_obj_t* obj, lv_event_t event) { static void btnEventHandler(lv_obj_t* obj, lv_event_t event) {
Timer* screen = static_cast<Timer*>(obj->user_data); auto* screen = static_cast<Timer*>(obj->user_data);
screen->OnButtonEvent(obj, event); screen->OnButtonEvent(obj, event);
} }
void Timer::createButtons() { void Timer::CreateButtons() {
btnMinutesUp = lv_btn_create(lv_scr_act(), nullptr); btnMinutesUp = lv_btn_create(lv_scr_act(), nullptr);
btnMinutesUp->user_data = this; btnMinutesUp->user_data = this;
lv_obj_set_event_cb(btnMinutesUp, btnEventHandler); lv_obj_set_event_cb(btnMinutesUp, btnEventHandler);
@ -51,6 +50,12 @@ void Timer::createButtons() {
Timer::Timer(DisplayApp* app, Controllers::TimerController& timerController) Timer::Timer(DisplayApp* app, Controllers::TimerController& timerController)
: Screen(app), running {true}, timerController {timerController} { : Screen(app), running {true}, timerController {timerController} {
backgroundLabel = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_click(backgroundLabel, true);
lv_label_set_long_mode(backgroundLabel, LV_LABEL_LONG_CROP);
lv_obj_set_size(backgroundLabel, 240, 240);
lv_obj_set_pos(backgroundLabel, 0, 0);
lv_label_set_text(backgroundLabel, "");
time = lv_label_create(lv_scr_act(), nullptr); 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_font(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_76);
@ -71,7 +76,7 @@ Timer::Timer(DisplayApp* app, Controllers::TimerController& timerController)
lv_label_set_text(txtPlayPause, Symbols::pause); lv_label_set_text(txtPlayPause, Symbols::pause);
} else { } else {
lv_label_set_text(txtPlayPause, Symbols::play); lv_label_set_text(txtPlayPause, Symbols::play);
createButtons(); CreateButtons();
} }
taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this); taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this);
@ -98,7 +103,7 @@ void Timer::OnButtonEvent(lv_obj_t* obj, lv_event_t event) {
minutesToSet = seconds / 60; minutesToSet = seconds / 60;
secondsToSet = seconds % 60; secondsToSet = seconds % 60;
timerController.StopTimer(); timerController.StopTimer();
createButtons(); CreateButtons();
} else if (secondsToSet + minutesToSet > 0) { } else if (secondsToSet + minutesToSet > 0) {
lv_label_set_text(txtPlayPause, Symbols::pause); lv_label_set_text(txtPlayPause, Symbols::pause);
@ -152,10 +157,10 @@ void Timer::OnButtonEvent(lv_obj_t* obj, lv_event_t event) {
} }
} }
void Timer::setDone() { void Timer::SetDone() {
lv_label_set_text(time, "00:00"); lv_label_set_text(time, "00:00");
lv_label_set_text(txtPlayPause, Symbols::play); lv_label_set_text(txtPlayPause, Symbols::play);
secondsToSet = 0; secondsToSet = 0;
minutesToSet = 0; minutesToSet = 0;
createButtons(); CreateButtons();
} }

View File

@ -8,32 +8,35 @@
#include "components/timer/TimerController.h" #include "components/timer/TimerController.h"
namespace Pinetime::Applications::Screens { namespace Pinetime::Applications::Screens {
class Timer : public Screen { class Timer : public Screen {
public: public:
enum class Modes { Normal, Done }; enum class Modes { Normal, Done };
Timer(DisplayApp* app, Controllers::TimerController& timerController); Timer(DisplayApp* app, Controllers::TimerController& timerController);
~Timer() override; ~Timer() override;
void Refresh() override; void Refresh() override;
void SetDone();
void setDone();
void OnButtonEvent(lv_obj_t* obj, lv_event_t event); void OnButtonEvent(lv_obj_t* obj, lv_event_t event);
private: private:
void CreateButtons();
bool running; bool running;
uint8_t secondsToSet = 0; uint8_t secondsToSet = 0;
uint8_t minutesToSet = 0; uint8_t minutesToSet = 0;
Controllers::TimerController& timerController; Controllers::TimerController& timerController;
lv_obj_t* backgroundLabel;
void createButtons(); lv_obj_t* time;
lv_obj_t* msecTime;
lv_obj_t *time, *msecTime, *btnPlayPause, *txtPlayPause, *btnMinutesUp, *btnMinutesDown, *btnSecondsUp, *btnSecondsDown, *txtMUp, lv_obj_t* btnPlayPause;
*txtMDown, *txtSUp, *txtSDown; lv_obj_t* txtPlayPause;
lv_obj_t* btnMinutesUp;
lv_obj_t* btnMinutesDown;
lv_obj_t* btnSecondsUp;
lv_obj_t* btnSecondsDown;
lv_obj_t* txtMUp;
lv_obj_t* txtMDown;
lv_obj_t* txtSUp;
lv_obj_t* txtSDown;
lv_task_t* taskRefresh; lv_task_t* taskRefresh;
}; };
} }