Skip to content

Commit 58a8507

Browse files
authored
Merge pull request #405 from Riksu9000/improve_stopwatch
Improve stopwatch
2 parents d796261 + c696926 commit 58a8507

1 file changed

Lines changed: 23 additions & 18 deletions

File tree

src/displayapp/screens/StopWatch.cpp

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,36 @@ 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+
lv_obj_set_style_local_bg_color(btnStopLap, LV_BTN_PART_MAIN, LV_STATE_DISABLED, lv_color_hex(0x080808));
88+
txtStopLap = lv_label_create(btnStopLap, nullptr);
89+
lv_obj_set_style_local_text_color(txtStopLap, LV_BTN_PART_MAIN, LV_STATE_DISABLED, lv_color_hex(0x888888));
90+
lv_label_set_text(txtStopLap, Symbols::stop);
91+
lv_obj_set_state(btnStopLap, LV_STATE_DISABLED);
92+
lv_obj_set_state(txtStopLap, LV_STATE_DISABLED);
93+
8094
lapOneText = lv_label_create(lv_scr_act(), nullptr);
8195
// lv_obj_set_style_local_text_font(lapOneText, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_bold_20);
8296
lv_obj_set_style_local_text_color(lapOneText, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_YELLOW);
@@ -88,9 +102,6 @@ StopWatch::StopWatch(DisplayApp* app)
88102
lv_obj_set_style_local_text_color(lapTwoText, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_YELLOW);
89103
lv_obj_align(lapTwoText, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 50, 55);
90104
lv_label_set_text(lapTwoText, "");
91-
92-
// We don't want this button in the init state
93-
btnStopLap = nullptr;
94105
}
95106

96107
StopWatch::~StopWatch() {
@@ -115,10 +126,6 @@ bool StopWatch::Refresh() {
115126
// Init state when an user first opens the app
116127
// and when a stop/reset button is pressed
117128
case States::Init: {
118-
if (btnStopLap != nullptr) {
119-
lv_obj_del(btnStopLap);
120-
btnStopLap = nullptr;
121-
}
122129
// The initial default value
123130
lv_label_set_text(time, "00:00");
124131
lv_label_set_text(msecTime, "00");
@@ -129,16 +136,14 @@ bool StopWatch::Refresh() {
129136
lapNr = 0;
130137

131138
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);
139+
lv_obj_set_state(btnStopLap, LV_STATE_DEFAULT);
140+
lv_obj_set_state(txtStopLap, LV_STATE_DEFAULT);
139141

140142
startTime = xTaskGetTickCount();
141143
currentState = States::Running;
144+
} else {
145+
lv_obj_set_state(btnStopLap, LV_STATE_DISABLED);
146+
lv_obj_set_state(txtStopLap, LV_STATE_DISABLED);
142147
}
143148
break;
144149
}

0 commit comments

Comments
 (0)