Code optimizations in SettingSetDate
This commit is contained in:
parent
5ae4192d8d
commit
f78c9bfcab
|
@ -26,19 +26,6 @@ SettingSetDate::SettingSetDate(
|
||||||
Screen(app),
|
Screen(app),
|
||||||
dateTimeController {dateTimeController}
|
dateTimeController {dateTimeController}
|
||||||
{
|
{
|
||||||
|
|
||||||
lv_obj_t * container1 = lv_cont_create(lv_scr_act(), nullptr);
|
|
||||||
|
|
||||||
//lv_obj_set_style_local_bg_color(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x111111));
|
|
||||||
lv_obj_set_style_local_bg_opa(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP);
|
|
||||||
lv_obj_set_style_local_pad_all(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 10);
|
|
||||||
lv_obj_set_style_local_pad_inner(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5);
|
|
||||||
lv_obj_set_style_local_border_width(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0);
|
|
||||||
lv_obj_set_pos(container1, 30, 60);
|
|
||||||
lv_obj_set_width(container1, LV_HOR_RES - 50);
|
|
||||||
lv_obj_set_height(container1, LV_VER_RES - 60);
|
|
||||||
lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT);
|
|
||||||
|
|
||||||
lv_obj_t * title = lv_label_create(lv_scr_act(), NULL);
|
lv_obj_t * title = lv_label_create(lv_scr_act(), NULL);
|
||||||
lv_label_set_text_static(title, "Set current date");
|
lv_label_set_text_static(title, "Set current date");
|
||||||
lv_label_set_align(title, LV_LABEL_ALIGN_CENTER);
|
lv_label_set_align(title, LV_LABEL_ALIGN_CENTER);
|
||||||
|
@ -116,8 +103,8 @@ SettingSetDate::SettingSetDate(
|
||||||
|
|
||||||
btnSetTime = lv_btn_create(lv_scr_act(), NULL);
|
btnSetTime = lv_btn_create(lv_scr_act(), NULL);
|
||||||
btnSetTime->user_data = this;
|
btnSetTime->user_data = this;
|
||||||
lv_obj_set_size(btnSetTime, 70, 40);
|
lv_obj_set_size(btnSetTime, 120, 48);
|
||||||
lv_obj_align(btnSetTime, lv_scr_act(), LV_ALIGN_CENTER, 0, 90);
|
lv_obj_align(btnSetTime, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, 0);
|
||||||
lv_obj_set_style_local_value_str(btnSetTime, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "Set");
|
lv_obj_set_style_local_value_str(btnSetTime, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "Set");
|
||||||
lv_obj_set_event_cb(btnSetTime, event_handler);
|
lv_obj_set_event_cb(btnSetTime, event_handler);
|
||||||
}
|
}
|
||||||
|
@ -133,7 +120,10 @@ bool SettingSetDate::Refresh() {
|
||||||
|
|
||||||
void SettingSetDate::HandleButtonPress(lv_obj_t *object, lv_event_t event) {
|
void SettingSetDate::HandleButtonPress(lv_obj_t *object, lv_event_t event) {
|
||||||
|
|
||||||
if(object == btnDayPlus && (event == LV_EVENT_PRESSED)) {
|
if (event != LV_EVENT_CLICKED)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (object == btnDayPlus) {
|
||||||
dayValue++;
|
dayValue++;
|
||||||
if (dayValue > MaximumDayOfMonth())
|
if (dayValue > MaximumDayOfMonth())
|
||||||
dayValue = 1;
|
dayValue = 1;
|
||||||
|
@ -141,8 +131,7 @@ void SettingSetDate::HandleButtonPress(lv_obj_t *object, lv_event_t event) {
|
||||||
lv_obj_align(lblDay, lv_scr_act(), LV_ALIGN_CENTER, POS_X_DAY, POS_Y_TEXT);
|
lv_obj_align(lblDay, lv_scr_act(), LV_ALIGN_CENTER, POS_X_DAY, POS_Y_TEXT);
|
||||||
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
|
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
|
||||||
}
|
}
|
||||||
|
else if (object == btnDayMinus) {
|
||||||
if(object == btnDayMinus && (event == LV_EVENT_PRESSED)) {
|
|
||||||
dayValue--;
|
dayValue--;
|
||||||
if (dayValue < 1)
|
if (dayValue < 1)
|
||||||
dayValue = MaximumDayOfMonth();
|
dayValue = MaximumDayOfMonth();
|
||||||
|
@ -150,8 +139,7 @@ void SettingSetDate::HandleButtonPress(lv_obj_t *object, lv_event_t event) {
|
||||||
lv_obj_align(lblDay, lv_scr_act(), LV_ALIGN_CENTER, POS_X_DAY, POS_Y_TEXT);
|
lv_obj_align(lblDay, lv_scr_act(), LV_ALIGN_CENTER, POS_X_DAY, POS_Y_TEXT);
|
||||||
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
|
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
|
||||||
}
|
}
|
||||||
|
else if (object == btnMonthPlus) {
|
||||||
if(object == btnMonthPlus && (event == LV_EVENT_PRESSED)) {
|
|
||||||
monthValue++;
|
monthValue++;
|
||||||
if (monthValue > 12)
|
if (monthValue > 12)
|
||||||
monthValue = 1;
|
monthValue = 1;
|
||||||
|
@ -159,8 +147,7 @@ void SettingSetDate::HandleButtonPress(lv_obj_t *object, lv_event_t event) {
|
||||||
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
|
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
|
||||||
CheckDay();
|
CheckDay();
|
||||||
}
|
}
|
||||||
|
else if (object == btnMonthMinus) {
|
||||||
if(object == btnMonthMinus && (event == LV_EVENT_PRESSED)) {
|
|
||||||
monthValue--;
|
monthValue--;
|
||||||
if (monthValue < 1)
|
if (monthValue < 1)
|
||||||
monthValue = 12;
|
monthValue = 12;
|
||||||
|
@ -168,24 +155,21 @@ void SettingSetDate::HandleButtonPress(lv_obj_t *object, lv_event_t event) {
|
||||||
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
|
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
|
||||||
CheckDay();
|
CheckDay();
|
||||||
}
|
}
|
||||||
|
else if (object == btnYearPlus) {
|
||||||
if(object == btnYearPlus && (event == LV_EVENT_PRESSED)) {
|
|
||||||
yearValue++;
|
yearValue++;
|
||||||
lv_label_set_text_fmt(lblYear, "%d", yearValue);
|
lv_label_set_text_fmt(lblYear, "%d", yearValue);
|
||||||
lv_obj_align(lblYear, lv_scr_act(), LV_ALIGN_CENTER, POS_X_YEAR, POS_Y_TEXT);
|
lv_obj_align(lblYear, lv_scr_act(), LV_ALIGN_CENTER, POS_X_YEAR, POS_Y_TEXT);
|
||||||
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
|
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
|
||||||
CheckDay();
|
CheckDay();
|
||||||
}
|
}
|
||||||
|
else if (object == btnYearMinus) {
|
||||||
if(object == btnYearMinus && (event == LV_EVENT_PRESSED)) {
|
|
||||||
yearValue--;
|
yearValue--;
|
||||||
lv_label_set_text_fmt(lblYear, "%d", yearValue);
|
lv_label_set_text_fmt(lblYear, "%d", yearValue);
|
||||||
lv_obj_align(lblYear, lv_scr_act(), LV_ALIGN_CENTER, POS_X_YEAR, POS_Y_TEXT);
|
lv_obj_align(lblYear, lv_scr_act(), LV_ALIGN_CENTER, POS_X_YEAR, POS_Y_TEXT);
|
||||||
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
|
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
|
||||||
CheckDay();
|
CheckDay();
|
||||||
}
|
}
|
||||||
|
else if (object == btnSetTime) {
|
||||||
if(object == btnSetTime && (event == LV_EVENT_PRESSED)) {
|
|
||||||
NRF_LOG_INFO("Setting date (manually) to %04d-%02d-%02d", yearValue, monthValue, dayValue);
|
NRF_LOG_INFO("Setting date (manually) to %04d-%02d-%02d", yearValue, monthValue, dayValue);
|
||||||
dateTimeController.SetTime(static_cast<uint16_t>(yearValue),
|
dateTimeController.SetTime(static_cast<uint16_t>(yearValue),
|
||||||
static_cast<uint8_t>(monthValue),
|
static_cast<uint8_t>(monthValue),
|
||||||
|
|
Loading…
Reference in a new issue