@@ -61,22 +61,32 @@ StopWatch::StopWatch(DisplayApp* app)
6161 lv_obj_set_style_local_text_font (time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_76);
6262 lv_obj_set_style_local_text_color (time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY);
6363 lv_label_set_text (time, " 00:00" );
64- lv_obj_align (time, lv_scr_act (), LV_ALIGN_IN_LEFT_MID , 0 , -45 );
64+ lv_obj_align (time, lv_scr_act (), LV_ALIGN_CENTER , 0 , -45 );
6565
6666 msecTime = lv_label_create (lv_scr_act (), nullptr );
6767 // lv_obj_set_style_local_text_font(msecTime, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_bold_20);
6868 lv_obj_set_style_local_text_color (msecTime, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY);
6969 lv_label_set_text (msecTime, " 00" );
70- lv_obj_align (msecTime, lv_scr_act (), LV_ALIGN_IN_LEFT_MID, 108 , 3 );
70+ lv_obj_align (msecTime, lv_scr_act (), LV_ALIGN_CENTER, 0 , 3 );
7171
7272 btnPlayPause = lv_btn_create (lv_scr_act (), nullptr );
7373 btnPlayPause->user_data = this ;
7474 lv_obj_set_event_cb (btnPlayPause, play_pause_event_handler);
75- lv_obj_align (btnPlayPause, lv_scr_act (), LV_ALIGN_IN_BOTTOM_MID, 0 , -10 );
76- lv_obj_set_height (btnPlayPause, 40 );
75+ lv_obj_set_height (btnPlayPause, 50 );
76+ lv_obj_set_width (btnPlayPause, 115 );
77+ lv_obj_align (btnPlayPause, lv_scr_act (), LV_ALIGN_IN_BOTTOM_RIGHT, 0 , 0 );
7778 txtPlayPause = lv_label_create (btnPlayPause, nullptr );
7879 lv_label_set_text (txtPlayPause, Symbols::play);
7980
81+ btnStopLap = lv_btn_create (lv_scr_act (), nullptr );
82+ btnStopLap->user_data = this ;
83+ lv_obj_set_event_cb (btnStopLap, stop_lap_event_handler);
84+ lv_obj_set_height (btnStopLap, 50 );
85+ lv_obj_set_width (btnStopLap, 115 );
86+ lv_obj_align (btnStopLap, lv_scr_act (), LV_ALIGN_IN_BOTTOM_LEFT, 0 , 0 );
87+ txtStopLap = lv_label_create (btnStopLap, nullptr );
88+ lv_obj_set_hidden (btnStopLap, true );
89+
8090 lapOneText = lv_label_create (lv_scr_act (), nullptr );
8191 // lv_obj_set_style_local_text_font(lapOneText, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_bold_20);
8292 lv_obj_set_style_local_text_color (lapOneText, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_YELLOW);
@@ -88,9 +98,6 @@ StopWatch::StopWatch(DisplayApp* app)
8898 lv_obj_set_style_local_text_color (lapTwoText, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_YELLOW);
8999 lv_obj_align (lapTwoText, lv_scr_act (), LV_ALIGN_IN_LEFT_MID, 50 , 55 );
90100 lv_label_set_text (lapTwoText, " " );
91-
92- // We don't want this button in the init state
93- btnStopLap = nullptr ;
94101}
95102
96103StopWatch::~StopWatch () {
@@ -115,10 +122,6 @@ bool StopWatch::Refresh() {
115122 // Init state when an user first opens the app
116123 // and when a stop/reset button is pressed
117124 case States::Init: {
118- if (btnStopLap != nullptr ) {
119- lv_obj_del (btnStopLap);
120- btnStopLap = nullptr ;
121- }
122125 // The initial default value
123126 lv_label_set_text (time, " 00:00" );
124127 lv_label_set_text (msecTime, " 00" );
@@ -129,16 +132,12 @@ bool StopWatch::Refresh() {
129132 lapNr = 0 ;
130133
131134 if (currentEvent == Events::Play) {
132- btnStopLap = lv_btn_create (lv_scr_act (), nullptr );
133- btnStopLap->user_data = this ;
134- lv_obj_set_event_cb (btnStopLap, stop_lap_event_handler);
135- lv_obj_align (btnStopLap, lv_scr_act (), LV_ALIGN_IN_TOP_MID, 0 , 0 );
136- lv_obj_set_height (btnStopLap, 40 );
137- txtStopLap = lv_label_create (btnStopLap, nullptr );
138- lv_label_set_text (txtStopLap, Symbols::lapsFlag);
135+ lv_obj_set_hidden (btnStopLap, false );
139136
140137 startTime = xTaskGetTickCount ();
141138 currentState = States::Running;
139+ } else {
140+ lv_obj_set_hidden (btnStopLap, true );
142141 }
143142 break ;
144143 }
0 commit comments