improve ui and optimize code
This commit is contained in:
parent
f88c0f41fa
commit
b393105082
|
@ -61,22 +61,32 @@ StopWatch::StopWatch(DisplayApp* app)
|
|||
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_GRAY);
|
||||
lv_label_set_text(time, "00:00");
|
||||
lv_obj_align(time, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, -45);
|
||||
lv_obj_align(time, lv_scr_act(), LV_ALIGN_CENTER, 0, -45);
|
||||
|
||||
msecTime = lv_label_create(lv_scr_act(), nullptr);
|
||||
// lv_obj_set_style_local_text_font(msecTime, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_bold_20);
|
||||
lv_obj_set_style_local_text_color(msecTime, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY);
|
||||
lv_label_set_text(msecTime, "00");
|
||||
lv_obj_align(msecTime, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 108, 3);
|
||||
lv_obj_align(msecTime, lv_scr_act(), LV_ALIGN_CENTER, 0, 3);
|
||||
|
||||
btnPlayPause = lv_btn_create(lv_scr_act(), nullptr);
|
||||
btnPlayPause->user_data = this;
|
||||
lv_obj_set_event_cb(btnPlayPause, play_pause_event_handler);
|
||||
lv_obj_align(btnPlayPause, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, -10);
|
||||
lv_obj_set_height(btnPlayPause, 40);
|
||||
lv_obj_set_height(btnPlayPause, 50);
|
||||
lv_obj_set_width(btnPlayPause, 115);
|
||||
lv_obj_align(btnPlayPause, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0);
|
||||
txtPlayPause = lv_label_create(btnPlayPause, nullptr);
|
||||
lv_label_set_text(txtPlayPause, Symbols::play);
|
||||
|
||||
btnStopLap = lv_btn_create(lv_scr_act(), nullptr);
|
||||
btnStopLap->user_data = this;
|
||||
lv_obj_set_event_cb(btnStopLap, stop_lap_event_handler);
|
||||
lv_obj_set_height(btnStopLap, 50);
|
||||
lv_obj_set_width(btnStopLap, 115);
|
||||
lv_obj_align(btnStopLap, lv_scr_act(), LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
|
||||
txtStopLap = lv_label_create(btnStopLap, nullptr);
|
||||
lv_obj_set_hidden(btnStopLap, true);
|
||||
|
||||
lapOneText = lv_label_create(lv_scr_act(), nullptr);
|
||||
// lv_obj_set_style_local_text_font(lapOneText, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_bold_20);
|
||||
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)
|
|||
lv_obj_set_style_local_text_color(lapTwoText, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_YELLOW);
|
||||
lv_obj_align(lapTwoText, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 50, 55);
|
||||
lv_label_set_text(lapTwoText, "");
|
||||
|
||||
// We don't want this button in the init state
|
||||
btnStopLap = nullptr;
|
||||
}
|
||||
|
||||
StopWatch::~StopWatch() {
|
||||
|
@ -115,10 +122,6 @@ bool StopWatch::Refresh() {
|
|||
// Init state when an user first opens the app
|
||||
// and when a stop/reset button is pressed
|
||||
case States::Init: {
|
||||
if (btnStopLap != nullptr) {
|
||||
lv_obj_del(btnStopLap);
|
||||
btnStopLap = nullptr;
|
||||
}
|
||||
// The initial default value
|
||||
lv_label_set_text(time, "00:00");
|
||||
lv_label_set_text(msecTime, "00");
|
||||
|
@ -129,16 +132,12 @@ bool StopWatch::Refresh() {
|
|||
lapNr = 0;
|
||||
|
||||
if (currentEvent == Events::Play) {
|
||||
btnStopLap = lv_btn_create(lv_scr_act(), nullptr);
|
||||
btnStopLap->user_data = this;
|
||||
lv_obj_set_event_cb(btnStopLap, stop_lap_event_handler);
|
||||
lv_obj_align(btnStopLap, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 0, 0);
|
||||
lv_obj_set_height(btnStopLap, 40);
|
||||
txtStopLap = lv_label_create(btnStopLap, nullptr);
|
||||
lv_label_set_text(txtStopLap, Symbols::lapsFlag);
|
||||
lv_obj_set_hidden(btnStopLap, false);
|
||||
|
||||
startTime = xTaskGetTickCount();
|
||||
currentState = States::Running;
|
||||
} else {
|
||||
lv_obj_set_hidden(btnStopLap, true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user