From c77634ce320cdb9bbd9de136e409bd9a0ca64153 Mon Sep 17 00:00:00 2001 From: timaios Date: Fri, 9 Jul 2021 14:11:20 +0200 Subject: Added new screen: SettingSetTime --- src/displayapp/screens/settings/SettingSetTime.cpp | 174 +++++++++++++++++++++ 1 file changed, 174 insertions(+) create mode 100644 src/displayapp/screens/settings/SettingSetTime.cpp (limited to 'src/displayapp/screens/settings/SettingSetTime.cpp') diff --git a/src/displayapp/screens/settings/SettingSetTime.cpp b/src/displayapp/screens/settings/SettingSetTime.cpp new file mode 100644 index 00000000..22d1c011 --- /dev/null +++ b/src/displayapp/screens/settings/SettingSetTime.cpp @@ -0,0 +1,174 @@ +#include "SettingSetTime.h" +#include +#include +#include +#include "displayapp/DisplayApp.h" +#include "displayapp/screens/Symbols.h" + +using namespace Pinetime::Applications::Screens; + +namespace { + static void event_handler(lv_obj_t * obj, lv_event_t event) { + SettingSetTime* screen = static_cast(obj->user_data); + screen->HandleButtonPress(obj, event); + } +} + +SettingSetTime::SettingSetTime( + Pinetime::Applications::DisplayApp *app, Pinetime::Controllers::DateTime &dateTimeController) : + Screen(app), + 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_label_set_text_static(title, "Set current time"); + lv_label_set_align(title, LV_LABEL_ALIGN_CENTER); + lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 15, 15); + + lv_obj_t * icon = lv_label_create(lv_scr_act(), NULL); + lv_obj_set_style_local_text_color(icon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE); + + lv_label_set_text_static(icon, Symbols::clock); + lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER); + lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0); + + hoursValue = static_cast(dateTimeController.Hours()); + lblHours = lv_label_create(lv_scr_act(), NULL); + lv_obj_set_style_local_text_font(lblHours, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); + lv_label_set_text_fmt(lblHours, "%02d", hoursValue); + lv_label_set_align(lblHours, LV_LABEL_ALIGN_CENTER); + lv_obj_align(lblHours, lv_scr_act(), LV_ALIGN_CENTER, -72, -6); + + lv_obj_t * lblColon1 = lv_label_create(lv_scr_act(), NULL); + lv_obj_set_style_local_text_font(lblColon1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); + lv_label_set_text_static(lblColon1, ":"); + lv_label_set_align(lblColon1, LV_LABEL_ALIGN_CENTER); + lv_obj_align(lblColon1, lv_scr_act(), LV_ALIGN_CENTER, -36, -8); + + minutesValue = static_cast(dateTimeController.Minutes()); + lblMinutes = lv_label_create(lv_scr_act(), NULL); + lv_obj_set_style_local_text_font(lblMinutes, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); + lv_label_set_text_fmt(lblMinutes, "%02d", minutesValue); + lv_label_set_align(lblMinutes, LV_LABEL_ALIGN_CENTER); + lv_obj_align(lblMinutes, lv_scr_act(), LV_ALIGN_CENTER, 0, -6); + + lv_obj_t * lblColon2 = lv_label_create(lv_scr_act(), NULL); + lv_obj_set_style_local_text_font(lblColon2, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); + lv_label_set_text_static(lblColon2, ":"); + lv_label_set_align(lblColon2, LV_LABEL_ALIGN_CENTER); + lv_obj_align(lblColon2, lv_scr_act(), LV_ALIGN_CENTER, 36, -8); + + lv_obj_t * lblSeconds = lv_label_create(lv_scr_act(), NULL); + lv_obj_set_style_local_text_font(lblSeconds, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); + lv_label_set_text_static(lblSeconds, "00"); + lv_label_set_align(lblSeconds, LV_LABEL_ALIGN_CENTER); + lv_obj_align(lblSeconds, lv_scr_act(), LV_ALIGN_CENTER, 72, -6); + + btnHoursPlus = lv_btn_create(lv_scr_act(), NULL); + btnHoursPlus->user_data = this; + lv_obj_set_size(btnHoursPlus, 50, 40); + lv_obj_align(btnHoursPlus, lv_scr_act(), LV_ALIGN_CENTER, -72, -50); + lv_obj_set_style_local_value_str(btnHoursPlus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "+"); + lv_obj_set_event_cb(btnHoursPlus, event_handler); + + btnHoursMinus = lv_btn_create(lv_scr_act(), NULL); + btnHoursMinus->user_data = this; + lv_obj_set_size(btnHoursMinus, 50, 40); + lv_obj_align(btnHoursMinus, lv_scr_act(), LV_ALIGN_CENTER, -72, 40); + lv_obj_set_style_local_value_str(btnHoursMinus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "-"); + lv_obj_set_event_cb(btnHoursMinus, event_handler); + + btnMinutesPlus = lv_btn_create(lv_scr_act(), NULL); + btnMinutesPlus->user_data = this; + lv_obj_set_size(btnMinutesPlus, 50, 40); + lv_obj_align(btnMinutesPlus, lv_scr_act(), LV_ALIGN_CENTER, 0, -50); + lv_obj_set_style_local_value_str(btnMinutesPlus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "+"); + lv_obj_set_event_cb(btnMinutesPlus, event_handler); + + btnMinutesMinus = lv_btn_create(lv_scr_act(), NULL); + btnMinutesMinus->user_data = this; + lv_obj_set_size(btnMinutesMinus, 50, 40); + lv_obj_align(btnMinutesMinus, lv_scr_act(), LV_ALIGN_CENTER, 0, 40); + lv_obj_set_style_local_value_str(btnMinutesMinus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "-"); + lv_obj_set_event_cb(btnMinutesMinus, event_handler); + + btnSetTime = lv_btn_create(lv_scr_act(), NULL); + btnSetTime->user_data = this; + lv_obj_set_size(btnSetTime, 70, 40); + lv_obj_align(btnSetTime, lv_scr_act(), LV_ALIGN_CENTER, 0, 90); + lv_obj_set_style_local_value_str(btnSetTime, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "Set"); + lv_obj_set_event_cb(btnSetTime, event_handler); +} + +SettingSetTime::~SettingSetTime() { + lv_obj_clean(lv_scr_act()); +} + +bool SettingSetTime::Refresh() { + return running; +} + + +void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) { + + if(object == btnHoursPlus && (event == LV_EVENT_PRESSED)) { + hoursValue++; + if (hoursValue > 23) + hoursValue = 0; + lv_label_set_text_fmt(lblHours, "%02d", hoursValue); + lv_obj_align(lblHours, lv_scr_act(), LV_ALIGN_CENTER, -72, -6); + lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); + } + + if(object == btnHoursMinus && (event == LV_EVENT_PRESSED)) { + hoursValue--; + if (hoursValue < 0) + hoursValue = 23; + lv_label_set_text_fmt(lblHours, "%02d", hoursValue); + lv_obj_align(lblHours, lv_scr_act(), LV_ALIGN_CENTER, -72, -6); + lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); + } + + if(object == btnMinutesPlus && (event == LV_EVENT_PRESSED)) { + minutesValue++; + if (minutesValue > 59) + minutesValue = 0; + lv_label_set_text_fmt(lblMinutes, "%02d", minutesValue); + lv_obj_align(lblMinutes, lv_scr_act(), LV_ALIGN_CENTER, 0, -6); + lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); + } + + if(object == btnMinutesMinus && (event == LV_EVENT_PRESSED)) { + minutesValue--; + if (minutesValue < 0) + minutesValue = 59; + lv_label_set_text_fmt(lblMinutes, "%02d", minutesValue); + lv_obj_align(lblMinutes, lv_scr_act(), LV_ALIGN_CENTER, 0, -6); + lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); + } + + if(object == btnSetTime && (event == LV_EVENT_PRESSED)) { + NRF_LOG_INFO("Setting time (manually) to %02d:%02d:00", hoursValue, minutesValue); + dateTimeController.SetTime(dateTimeController.Year(), + static_cast(dateTimeController.Month()), + dateTimeController.Day(), + static_cast(dateTimeController.DayOfWeek()), + static_cast(hoursValue), + static_cast(minutesValue), + 0, + nrf_rtc_counter_get(portNRF_RTC_REG)); + lv_btn_set_state(btnSetTime, LV_BTN_STATE_DISABLED); + } +} -- cgit v1.2.3 From 06dfe1425173ffae81294cdce0fd271f1881f7ef Mon Sep 17 00:00:00 2001 From: Tim Taenny Date: Fri, 9 Jul 2021 17:13:29 +0200 Subject: Code optimizations in SettingSetTime --- src/displayapp/screens/settings/SettingSetTime.cpp | 34 +++++++--------------- 1 file changed, 10 insertions(+), 24 deletions(-) (limited to 'src/displayapp/screens/settings/SettingSetTime.cpp') diff --git a/src/displayapp/screens/settings/SettingSetTime.cpp b/src/displayapp/screens/settings/SettingSetTime.cpp index 22d1c011..e8bc81ed 100644 --- a/src/displayapp/screens/settings/SettingSetTime.cpp +++ b/src/displayapp/screens/settings/SettingSetTime.cpp @@ -19,19 +19,6 @@ SettingSetTime::SettingSetTime( Screen(app), 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_label_set_text_static(title, "Set current time"); lv_label_set_align(title, LV_LABEL_ALIGN_CENTER); @@ -106,8 +93,8 @@ SettingSetTime::SettingSetTime( btnSetTime = lv_btn_create(lv_scr_act(), NULL); btnSetTime->user_data = this; - lv_obj_set_size(btnSetTime, 70, 40); - lv_obj_align(btnSetTime, lv_scr_act(), LV_ALIGN_CENTER, 0, 90); + lv_obj_set_size(btnSetTime, 120, 48); + 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_event_cb(btnSetTime, event_handler); } @@ -123,7 +110,10 @@ bool SettingSetTime::Refresh() { void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) { - if(object == btnHoursPlus && (event == LV_EVENT_PRESSED)) { + if (event != LV_EVENT_CLICKED) + return; + + if (object == btnHoursPlus) { hoursValue++; if (hoursValue > 23) hoursValue = 0; @@ -131,8 +121,7 @@ void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) { lv_obj_align(lblHours, lv_scr_act(), LV_ALIGN_CENTER, -72, -6); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); } - - if(object == btnHoursMinus && (event == LV_EVENT_PRESSED)) { + else if (object == btnHoursMinus) { hoursValue--; if (hoursValue < 0) hoursValue = 23; @@ -140,8 +129,7 @@ void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) { lv_obj_align(lblHours, lv_scr_act(), LV_ALIGN_CENTER, -72, -6); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); } - - if(object == btnMinutesPlus && (event == LV_EVENT_PRESSED)) { + else if (object == btnMinutesPlus) { minutesValue++; if (minutesValue > 59) minutesValue = 0; @@ -149,8 +137,7 @@ void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) { lv_obj_align(lblMinutes, lv_scr_act(), LV_ALIGN_CENTER, 0, -6); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); } - - if(object == btnMinutesMinus && (event == LV_EVENT_PRESSED)) { + else if (object == btnMinutesMinus) { minutesValue--; if (minutesValue < 0) minutesValue = 59; @@ -158,8 +145,7 @@ void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) { lv_obj_align(lblMinutes, lv_scr_act(), LV_ALIGN_CENTER, 0, -6); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); } - - if(object == btnSetTime && (event == LV_EVENT_PRESSED)) { + else if (object == btnSetTime) { NRF_LOG_INFO("Setting time (manually) to %02d:%02d:00", hoursValue, minutesValue); dateTimeController.SetTime(dateTimeController.Year(), static_cast(dateTimeController.Month()), -- cgit v1.2.3 From da36d4a5a1322dd7699dbe445bb25962b0819f0a Mon Sep 17 00:00:00 2001 From: Tim Taenny Date: Fri, 9 Jul 2021 20:17:47 +0200 Subject: Code optimizations in SettingSetTime The positions of the labels are controlled by #define's, just like in SettingSetDate. --- src/displayapp/screens/settings/SettingSetTime.cpp | 26 ++++++++++++++-------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'src/displayapp/screens/settings/SettingSetTime.cpp') diff --git a/src/displayapp/screens/settings/SettingSetTime.cpp b/src/displayapp/screens/settings/SettingSetTime.cpp index e8bc81ed..122a537a 100644 --- a/src/displayapp/screens/settings/SettingSetTime.cpp +++ b/src/displayapp/screens/settings/SettingSetTime.cpp @@ -5,6 +5,14 @@ #include "displayapp/DisplayApp.h" #include "displayapp/screens/Symbols.h" +#define POS_X_HOURS -72 +#define POS_X_MINUTES 0 +#define POS_X_SECONDS 72 +#define POS_Y_PLUS -50 +#define POS_Y_TEXT -6 +#define POS_Y_MINUS 40 +#define OFS_Y_COLON -2 + using namespace Pinetime::Applications::Screens; namespace { @@ -36,32 +44,32 @@ SettingSetTime::SettingSetTime( lv_obj_set_style_local_text_font(lblHours, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); lv_label_set_text_fmt(lblHours, "%02d", hoursValue); lv_label_set_align(lblHours, LV_LABEL_ALIGN_CENTER); - lv_obj_align(lblHours, lv_scr_act(), LV_ALIGN_CENTER, -72, -6); + lv_obj_align(lblHours, lv_scr_act(), LV_ALIGN_CENTER, POS_X_HOURS, POS_Y_TEXT); lv_obj_t * lblColon1 = lv_label_create(lv_scr_act(), NULL); lv_obj_set_style_local_text_font(lblColon1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); lv_label_set_text_static(lblColon1, ":"); lv_label_set_align(lblColon1, LV_LABEL_ALIGN_CENTER); - lv_obj_align(lblColon1, lv_scr_act(), LV_ALIGN_CENTER, -36, -8); + lv_obj_align(lblColon1, lv_scr_act(), LV_ALIGN_CENTER, (POS_X_HOURS + POS_X_MINUTES) / 2, POS_Y_TEXT + OFS_Y_COLON); minutesValue = static_cast(dateTimeController.Minutes()); lblMinutes = lv_label_create(lv_scr_act(), NULL); lv_obj_set_style_local_text_font(lblMinutes, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); lv_label_set_text_fmt(lblMinutes, "%02d", minutesValue); lv_label_set_align(lblMinutes, LV_LABEL_ALIGN_CENTER); - lv_obj_align(lblMinutes, lv_scr_act(), LV_ALIGN_CENTER, 0, -6); + lv_obj_align(lblMinutes, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MINUTES, POS_Y_TEXT); lv_obj_t * lblColon2 = lv_label_create(lv_scr_act(), NULL); lv_obj_set_style_local_text_font(lblColon2, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); lv_label_set_text_static(lblColon2, ":"); lv_label_set_align(lblColon2, LV_LABEL_ALIGN_CENTER); - lv_obj_align(lblColon2, lv_scr_act(), LV_ALIGN_CENTER, 36, -8); + lv_obj_align(lblColon2, lv_scr_act(), LV_ALIGN_CENTER, (POS_X_MINUTES + POS_X_SECONDS) / 2, POS_Y_TEXT + OFS_Y_COLON); lv_obj_t * lblSeconds = lv_label_create(lv_scr_act(), NULL); lv_obj_set_style_local_text_font(lblSeconds, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); lv_label_set_text_static(lblSeconds, "00"); lv_label_set_align(lblSeconds, LV_LABEL_ALIGN_CENTER); - lv_obj_align(lblSeconds, lv_scr_act(), LV_ALIGN_CENTER, 72, -6); + lv_obj_align(lblSeconds, lv_scr_act(), LV_ALIGN_CENTER, POS_X_SECONDS, POS_Y_TEXT); btnHoursPlus = lv_btn_create(lv_scr_act(), NULL); btnHoursPlus->user_data = this; @@ -118,7 +126,7 @@ void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) { if (hoursValue > 23) hoursValue = 0; lv_label_set_text_fmt(lblHours, "%02d", hoursValue); - lv_obj_align(lblHours, lv_scr_act(), LV_ALIGN_CENTER, -72, -6); + lv_obj_align(lblHours, lv_scr_act(), LV_ALIGN_CENTER, POS_X_HOURS, POS_Y_TEXT); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); } else if (object == btnHoursMinus) { @@ -126,7 +134,7 @@ void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) { if (hoursValue < 0) hoursValue = 23; lv_label_set_text_fmt(lblHours, "%02d", hoursValue); - lv_obj_align(lblHours, lv_scr_act(), LV_ALIGN_CENTER, -72, -6); + lv_obj_align(lblHours, lv_scr_act(), LV_ALIGN_CENTER, POS_X_HOURS, POS_Y_TEXT); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); } else if (object == btnMinutesPlus) { @@ -134,7 +142,7 @@ void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) { if (minutesValue > 59) minutesValue = 0; lv_label_set_text_fmt(lblMinutes, "%02d", minutesValue); - lv_obj_align(lblMinutes, lv_scr_act(), LV_ALIGN_CENTER, 0, -6); + lv_obj_align(lblMinutes, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MINUTES, POS_Y_TEXT); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); } else if (object == btnMinutesMinus) { @@ -142,7 +150,7 @@ void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) { if (minutesValue < 0) minutesValue = 59; lv_label_set_text_fmt(lblMinutes, "%02d", minutesValue); - lv_obj_align(lblMinutes, lv_scr_act(), LV_ALIGN_CENTER, 0, -6); + lv_obj_align(lblMinutes, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MINUTES, POS_Y_TEXT); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); } else if (object == btnSetTime) { -- cgit v1.2.3 From ffa51612fc6884ccfeb4f23453acc451692c18b3 Mon Sep 17 00:00:00 2001 From: Tim Taenny Date: Fri, 9 Jul 2021 20:35:48 +0200 Subject: Code optimizations in SettingSetDate and SettingSetTime Instead of calling lv_obj_align after each button click, the labels have their auto_realign property set. --- src/displayapp/screens/settings/SettingSetDate.cpp | 14 +++++--------- src/displayapp/screens/settings/SettingSetTime.cpp | 6 ++---- 2 files changed, 7 insertions(+), 13 deletions(-) (limited to 'src/displayapp/screens/settings/SettingSetTime.cpp') diff --git a/src/displayapp/screens/settings/SettingSetDate.cpp b/src/displayapp/screens/settings/SettingSetDate.cpp index fe71cd85..69766a4e 100644 --- a/src/displayapp/screens/settings/SettingSetDate.cpp +++ b/src/displayapp/screens/settings/SettingSetDate.cpp @@ -40,24 +40,26 @@ SettingSetDate::SettingSetDate( dayValue = static_cast(dateTimeController.Day()); lblDay = lv_label_create(lv_scr_act(), NULL); - //lv_obj_set_style_local_text_font(lblDay, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); lv_label_set_text_fmt(lblDay, "%d", dayValue); lv_label_set_align(lblDay, LV_LABEL_ALIGN_CENTER); lv_obj_align(lblDay, lv_scr_act(), LV_ALIGN_CENTER, POS_X_DAY, POS_Y_TEXT); + lv_obj_set_auto_realign(lblDay, true); monthValue = static_cast(dateTimeController.Month()); lblMonth = lv_label_create(lv_scr_act(), NULL); - //lv_obj_set_style_local_text_font(lblMonth, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); UpdateMonthLabel(); + lv_label_set_align(lblMonth, LV_LABEL_ALIGN_CENTER); + lv_obj_align(lblMonth, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MONTH, POS_Y_TEXT); + lv_obj_set_auto_realign(lblMonth, true); yearValue = static_cast(dateTimeController.Year()); if (yearValue < 2021) yearValue = 2021; lblYear = lv_label_create(lv_scr_act(), NULL); - //lv_obj_set_style_local_text_font(lblYear, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); lv_label_set_text_fmt(lblYear, "%d", yearValue); lv_label_set_align(lblYear, LV_LABEL_ALIGN_CENTER); lv_obj_align(lblYear, lv_scr_act(), LV_ALIGN_CENTER, POS_X_YEAR, POS_Y_TEXT); + lv_obj_set_auto_realign(lblYear, true); btnDayPlus = lv_btn_create(lv_scr_act(), NULL); btnDayPlus->user_data = this; @@ -128,7 +130,6 @@ void SettingSetDate::HandleButtonPress(lv_obj_t *object, lv_event_t event) { if (dayValue > MaximumDayOfMonth()) dayValue = 1; lv_label_set_text_fmt(lblDay, "%d", dayValue); - 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); } else if (object == btnDayMinus) { @@ -136,7 +137,6 @@ void SettingSetDate::HandleButtonPress(lv_obj_t *object, lv_event_t event) { if (dayValue < 1) dayValue = MaximumDayOfMonth(); lv_label_set_text_fmt(lblDay, "%d", dayValue); - 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); } else if (object == btnMonthPlus) { @@ -158,14 +158,12 @@ void SettingSetDate::HandleButtonPress(lv_obj_t *object, lv_event_t event) { else if (object == btnYearPlus) { 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_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); CheckDay(); } else if (object == btnYearMinus) { 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_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); CheckDay(); } @@ -211,7 +209,5 @@ void SettingSetDate::CheckDay() { void SettingSetDate::UpdateMonthLabel() { lv_label_set_text_static(lblMonth, Pinetime::Controllers::DateTime::MonthShortToStringLow(static_cast(monthValue))); - lv_label_set_align(lblMonth, LV_LABEL_ALIGN_CENTER); - lv_obj_align(lblMonth, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MONTH, POS_Y_TEXT); } diff --git a/src/displayapp/screens/settings/SettingSetTime.cpp b/src/displayapp/screens/settings/SettingSetTime.cpp index 122a537a..eae11f5e 100644 --- a/src/displayapp/screens/settings/SettingSetTime.cpp +++ b/src/displayapp/screens/settings/SettingSetTime.cpp @@ -45,6 +45,7 @@ SettingSetTime::SettingSetTime( lv_label_set_text_fmt(lblHours, "%02d", hoursValue); lv_label_set_align(lblHours, LV_LABEL_ALIGN_CENTER); lv_obj_align(lblHours, lv_scr_act(), LV_ALIGN_CENTER, POS_X_HOURS, POS_Y_TEXT); + lv_obj_set_auto_realign(lblHours, true); lv_obj_t * lblColon1 = lv_label_create(lv_scr_act(), NULL); lv_obj_set_style_local_text_font(lblColon1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); @@ -58,6 +59,7 @@ SettingSetTime::SettingSetTime( lv_label_set_text_fmt(lblMinutes, "%02d", minutesValue); lv_label_set_align(lblMinutes, LV_LABEL_ALIGN_CENTER); lv_obj_align(lblMinutes, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MINUTES, POS_Y_TEXT); + lv_obj_set_auto_realign(lblMinutes, true); lv_obj_t * lblColon2 = lv_label_create(lv_scr_act(), NULL); lv_obj_set_style_local_text_font(lblColon2, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); @@ -126,7 +128,6 @@ void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) { if (hoursValue > 23) hoursValue = 0; lv_label_set_text_fmt(lblHours, "%02d", hoursValue); - lv_obj_align(lblHours, lv_scr_act(), LV_ALIGN_CENTER, POS_X_HOURS, POS_Y_TEXT); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); } else if (object == btnHoursMinus) { @@ -134,7 +135,6 @@ void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) { if (hoursValue < 0) hoursValue = 23; lv_label_set_text_fmt(lblHours, "%02d", hoursValue); - lv_obj_align(lblHours, lv_scr_act(), LV_ALIGN_CENTER, POS_X_HOURS, POS_Y_TEXT); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); } else if (object == btnMinutesPlus) { @@ -142,7 +142,6 @@ void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) { if (minutesValue > 59) minutesValue = 0; lv_label_set_text_fmt(lblMinutes, "%02d", minutesValue); - lv_obj_align(lblMinutes, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MINUTES, POS_Y_TEXT); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); } else if (object == btnMinutesMinus) { @@ -150,7 +149,6 @@ void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) { if (minutesValue < 0) minutesValue = 59; lv_label_set_text_fmt(lblMinutes, "%02d", minutesValue); - lv_obj_align(lblMinutes, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MINUTES, POS_Y_TEXT); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); } else if (object == btnSetTime) { -- cgit v1.2.3 From f2357b36e5142f3f143f466cac62aafcf7261d5f Mon Sep 17 00:00:00 2001 From: Jean-François Milants Date: Sun, 10 Oct 2021 16:18:14 +0200 Subject: Setting SetDate/SetTime : replace #defines by constexpr variables, NULL by nullptr and other small cleanings. --- src/displayapp/screens/settings/SettingSetDate.cpp | 72 ++++++++++------------ src/displayapp/screens/settings/SettingSetDate.h | 5 +- src/displayapp/screens/settings/SettingSetTime.cpp | 63 +++++++++---------- src/displayapp/screens/settings/SettingSetTime.h | 6 +- 4 files changed, 61 insertions(+), 85 deletions(-) (limited to 'src/displayapp/screens/settings/SettingSetTime.cpp') diff --git a/src/displayapp/screens/settings/SettingSetDate.cpp b/src/displayapp/screens/settings/SettingSetDate.cpp index 705b7a95..ba3413ef 100644 --- a/src/displayapp/screens/settings/SettingSetDate.cpp +++ b/src/displayapp/screens/settings/SettingSetDate.cpp @@ -5,33 +5,31 @@ #include "displayapp/DisplayApp.h" #include "displayapp/screens/Symbols.h" -#define POS_X_DAY -72 -#define POS_X_MONTH 0 -#define POS_X_YEAR 72 -#define POS_Y_PLUS -50 -#define POS_Y_TEXT -6 -#define POS_Y_MINUS 40 - using namespace Pinetime::Applications::Screens; namespace { - static void event_handler(lv_obj_t * obj, lv_event_t event) { - SettingSetDate* screen = static_cast(obj->user_data); + constexpr int16_t POS_X_DAY = -72; + constexpr int16_t POS_X_MONTH = 0; + constexpr int16_t POS_X_YEAR = 72; + constexpr int16_t POS_Y_PLUS = -50; + constexpr int16_t POS_Y_TEXT = -6; + constexpr int16_t POS_Y_MINUS = 40; + + void event_handler(lv_obj_t * obj, lv_event_t event) { + auto* screen = static_cast(obj->user_data); screen->HandleButtonPress(obj, event); } } -SettingSetDate::SettingSetDate( - Pinetime::Applications::DisplayApp *app, Pinetime::Controllers::DateTime &dateTimeController) : +SettingSetDate::SettingSetDate(Pinetime::Applications::DisplayApp *app, Pinetime::Controllers::DateTime &dateTimeController) : Screen(app), - dateTimeController {dateTimeController} -{ - lv_obj_t * title = lv_label_create(lv_scr_act(), NULL); + dateTimeController {dateTimeController} { + lv_obj_t * title = lv_label_create(lv_scr_act(), nullptr); lv_label_set_text_static(title, "Set current date"); lv_label_set_align(title, LV_LABEL_ALIGN_CENTER); lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 15, 15); - lv_obj_t * icon = lv_label_create(lv_scr_act(), NULL); + lv_obj_t * icon = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(icon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE); lv_label_set_text_static(icon, Symbols::clock); @@ -39,14 +37,14 @@ SettingSetDate::SettingSetDate( lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0); dayValue = static_cast(dateTimeController.Day()); - lblDay = lv_label_create(lv_scr_act(), NULL); + lblDay = lv_label_create(lv_scr_act(), nullptr); lv_label_set_text_fmt(lblDay, "%d", dayValue); lv_label_set_align(lblDay, LV_LABEL_ALIGN_CENTER); lv_obj_align(lblDay, lv_scr_act(), LV_ALIGN_CENTER, POS_X_DAY, POS_Y_TEXT); lv_obj_set_auto_realign(lblDay, true); monthValue = static_cast(dateTimeController.Month()); - lblMonth = lv_label_create(lv_scr_act(), NULL); + lblMonth = lv_label_create(lv_scr_act(), nullptr); UpdateMonthLabel(); lv_label_set_align(lblMonth, LV_LABEL_ALIGN_CENTER); lv_obj_align(lblMonth, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MONTH, POS_Y_TEXT); @@ -55,55 +53,55 @@ SettingSetDate::SettingSetDate( yearValue = static_cast(dateTimeController.Year()); if (yearValue < 2021) yearValue = 2021; - lblYear = lv_label_create(lv_scr_act(), NULL); + lblYear = lv_label_create(lv_scr_act(), nullptr); lv_label_set_text_fmt(lblYear, "%d", yearValue); lv_label_set_align(lblYear, LV_LABEL_ALIGN_CENTER); lv_obj_align(lblYear, lv_scr_act(), LV_ALIGN_CENTER, POS_X_YEAR, POS_Y_TEXT); lv_obj_set_auto_realign(lblYear, true); - btnDayPlus = lv_btn_create(lv_scr_act(), NULL); + btnDayPlus = lv_btn_create(lv_scr_act(), nullptr); btnDayPlus->user_data = this; lv_obj_set_size(btnDayPlus, 50, 40); lv_obj_align(btnDayPlus, lv_scr_act(), LV_ALIGN_CENTER, POS_X_DAY, POS_Y_PLUS); lv_obj_set_style_local_value_str(btnDayPlus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "+"); lv_obj_set_event_cb(btnDayPlus, event_handler); - btnDayMinus = lv_btn_create(lv_scr_act(), NULL); + btnDayMinus = lv_btn_create(lv_scr_act(), nullptr); btnDayMinus->user_data = this; lv_obj_set_size(btnDayMinus, 50, 40); lv_obj_align(btnDayMinus, lv_scr_act(), LV_ALIGN_CENTER, POS_X_DAY, POS_Y_MINUS); lv_obj_set_style_local_value_str(btnDayMinus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "-"); lv_obj_set_event_cb(btnDayMinus, event_handler); - btnMonthPlus = lv_btn_create(lv_scr_act(), NULL); + btnMonthPlus = lv_btn_create(lv_scr_act(), nullptr); btnMonthPlus->user_data = this; lv_obj_set_size(btnMonthPlus, 50, 40); lv_obj_align(btnMonthPlus, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MONTH, POS_Y_PLUS); lv_obj_set_style_local_value_str(btnMonthPlus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "+"); lv_obj_set_event_cb(btnMonthPlus, event_handler); - btnMonthMinus = lv_btn_create(lv_scr_act(), NULL); + btnMonthMinus = lv_btn_create(lv_scr_act(), nullptr); btnMonthMinus->user_data = this; lv_obj_set_size(btnMonthMinus, 50, 40); lv_obj_align(btnMonthMinus, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MONTH, POS_Y_MINUS); lv_obj_set_style_local_value_str(btnMonthMinus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "-"); lv_obj_set_event_cb(btnMonthMinus, event_handler); - btnYearPlus = lv_btn_create(lv_scr_act(), NULL); + btnYearPlus = lv_btn_create(lv_scr_act(), nullptr); btnYearPlus->user_data = this; lv_obj_set_size(btnYearPlus, 50, 40); lv_obj_align(btnYearPlus, lv_scr_act(), LV_ALIGN_CENTER, POS_X_YEAR, POS_Y_PLUS); lv_obj_set_style_local_value_str(btnYearPlus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "+"); lv_obj_set_event_cb(btnYearPlus, event_handler); - btnYearMinus = lv_btn_create(lv_scr_act(), NULL); + btnYearMinus = lv_btn_create(lv_scr_act(), nullptr); btnYearMinus->user_data = this; lv_obj_set_size(btnYearMinus, 50, 40); lv_obj_align(btnYearMinus, lv_scr_act(), LV_ALIGN_CENTER, POS_X_YEAR, POS_Y_MINUS); lv_obj_set_style_local_value_str(btnYearMinus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "-"); lv_obj_set_event_cb(btnYearMinus, event_handler); - btnSetTime = lv_btn_create(lv_scr_act(), NULL); + btnSetTime = lv_btn_create(lv_scr_act(), nullptr); btnSetTime->user_data = this; lv_obj_set_size(btnSetTime, 120, 48); lv_obj_align(btnSetTime, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, 0); @@ -116,7 +114,6 @@ SettingSetDate::~SettingSetDate() { } void SettingSetDate::HandleButtonPress(lv_obj_t *object, lv_event_t event) { - if (event != LV_EVENT_CLICKED) return; @@ -126,43 +123,37 @@ void SettingSetDate::HandleButtonPress(lv_obj_t *object, lv_event_t event) { dayValue = 1; lv_label_set_text_fmt(lblDay, "%d", dayValue); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); - } - else if (object == btnDayMinus) { + } else if (object == btnDayMinus) { dayValue--; if (dayValue < 1) dayValue = MaximumDayOfMonth(); lv_label_set_text_fmt(lblDay, "%d", dayValue); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); - } - else if (object == btnMonthPlus) { + } else if (object == btnMonthPlus) { monthValue++; if (monthValue > 12) monthValue = 1; UpdateMonthLabel(); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); CheckDay(); - } - else if (object == btnMonthMinus) { + } else if (object == btnMonthMinus) { monthValue--; if (monthValue < 1) monthValue = 12; UpdateMonthLabel(); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); CheckDay(); - } - else if (object == btnYearPlus) { + } else if (object == btnYearPlus) { yearValue++; lv_label_set_text_fmt(lblYear, "%d", yearValue); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); CheckDay(); - } - else if (object == btnYearMinus) { + } else if (object == btnYearMinus) { yearValue--; lv_label_set_text_fmt(lblYear, "%d", yearValue); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); CheckDay(); - } - else if (object == btnSetTime) { + } else if (object == btnSetTime) { NRF_LOG_INFO("Setting date (manually) to %04d-%02d-%02d", yearValue, monthValue, dayValue); dateTimeController.SetTime(static_cast(yearValue), static_cast(monthValue), @@ -202,7 +193,6 @@ void SettingSetDate::CheckDay() { } void SettingSetDate::UpdateMonthLabel() { - lv_label_set_text_static(lblMonth, - Pinetime::Controllers::DateTime::MonthShortToStringLow(static_cast(monthValue))); + lv_label_set_text_static( + lblMonth, Pinetime::Controllers::DateTime::MonthShortToStringLow(static_cast(monthValue))); } - diff --git a/src/displayapp/screens/settings/SettingSetDate.h b/src/displayapp/screens/settings/SettingSetDate.h index 0f6317d3..477337ff 100644 --- a/src/displayapp/screens/settings/SettingSetDate.h +++ b/src/displayapp/screens/settings/SettingSetDate.h @@ -6,10 +6,8 @@ #include "displayapp/screens/Screen.h" namespace Pinetime { - namespace Applications { namespace Screens { - class SettingSetDate : public Screen{ public: SettingSetDate(DisplayApp* app, Pinetime::Controllers::DateTime &dateTimeController); @@ -17,8 +15,7 @@ namespace Pinetime { void HandleButtonPress(lv_obj_t *object, lv_event_t event); - private: - + private: Controllers::DateTime& dateTimeController; int dayValue; diff --git a/src/displayapp/screens/settings/SettingSetTime.cpp b/src/displayapp/screens/settings/SettingSetTime.cpp index 7083b80f..194bf5eb 100644 --- a/src/displayapp/screens/settings/SettingSetTime.cpp +++ b/src/displayapp/screens/settings/SettingSetTime.cpp @@ -5,34 +5,32 @@ #include "displayapp/DisplayApp.h" #include "displayapp/screens/Symbols.h" -#define POS_X_HOURS -72 -#define POS_X_MINUTES 0 -#define POS_X_SECONDS 72 -#define POS_Y_PLUS -50 -#define POS_Y_TEXT -6 -#define POS_Y_MINUS 40 -#define OFS_Y_COLON -2 - using namespace Pinetime::Applications::Screens; namespace { - static void event_handler(lv_obj_t * obj, lv_event_t event) { - SettingSetTime* screen = static_cast(obj->user_data); + constexpr int16_t POS_X_HOURS = -72; + constexpr int16_t POS_X_MINUTES = 0; + constexpr int16_t POS_X_SECONDS = 72; + constexpr int16_t POS_Y_PLUS = -50; + constexpr int16_t POS_Y_TEXT = -6; + constexpr int16_t POS_Y_MINUS = 40; + constexpr int16_t OFS_Y_COLON = -2; + + void event_handler(lv_obj_t * obj, lv_event_t event) { + auto* screen = static_cast(obj->user_data); screen->HandleButtonPress(obj, event); } } -SettingSetTime::SettingSetTime( - Pinetime::Applications::DisplayApp *app, Pinetime::Controllers::DateTime &dateTimeController) : +SettingSetTime::SettingSetTime(Pinetime::Applications::DisplayApp *app, Pinetime::Controllers::DateTime &dateTimeController) : Screen(app), - dateTimeController {dateTimeController} -{ - lv_obj_t * title = lv_label_create(lv_scr_act(), NULL); + dateTimeController {dateTimeController} { + lv_obj_t * title = lv_label_create(lv_scr_act(), nullptr); lv_label_set_text_static(title, "Set current time"); lv_label_set_align(title, LV_LABEL_ALIGN_CENTER); lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 15, 15); - lv_obj_t * icon = lv_label_create(lv_scr_act(), NULL); + lv_obj_t * icon = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(icon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE); lv_label_set_text_static(icon, Symbols::clock); @@ -40,68 +38,68 @@ SettingSetTime::SettingSetTime( lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0); hoursValue = static_cast(dateTimeController.Hours()); - lblHours = lv_label_create(lv_scr_act(), NULL); + lblHours = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_font(lblHours, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); lv_label_set_text_fmt(lblHours, "%02d", hoursValue); lv_label_set_align(lblHours, LV_LABEL_ALIGN_CENTER); lv_obj_align(lblHours, lv_scr_act(), LV_ALIGN_CENTER, POS_X_HOURS, POS_Y_TEXT); lv_obj_set_auto_realign(lblHours, true); - lv_obj_t * lblColon1 = lv_label_create(lv_scr_act(), NULL); + lv_obj_t * lblColon1 = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_font(lblColon1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); lv_label_set_text_static(lblColon1, ":"); lv_label_set_align(lblColon1, LV_LABEL_ALIGN_CENTER); lv_obj_align(lblColon1, lv_scr_act(), LV_ALIGN_CENTER, (POS_X_HOURS + POS_X_MINUTES) / 2, POS_Y_TEXT + OFS_Y_COLON); minutesValue = static_cast(dateTimeController.Minutes()); - lblMinutes = lv_label_create(lv_scr_act(), NULL); + lblMinutes = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_font(lblMinutes, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); lv_label_set_text_fmt(lblMinutes, "%02d", minutesValue); lv_label_set_align(lblMinutes, LV_LABEL_ALIGN_CENTER); lv_obj_align(lblMinutes, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MINUTES, POS_Y_TEXT); lv_obj_set_auto_realign(lblMinutes, true); - lv_obj_t * lblColon2 = lv_label_create(lv_scr_act(), NULL); + lv_obj_t * lblColon2 = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_font(lblColon2, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); lv_label_set_text_static(lblColon2, ":"); lv_label_set_align(lblColon2, LV_LABEL_ALIGN_CENTER); lv_obj_align(lblColon2, lv_scr_act(), LV_ALIGN_CENTER, (POS_X_MINUTES + POS_X_SECONDS) / 2, POS_Y_TEXT + OFS_Y_COLON); - lv_obj_t * lblSeconds = lv_label_create(lv_scr_act(), NULL); + lv_obj_t * lblSeconds = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_font(lblSeconds, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); lv_label_set_text_static(lblSeconds, "00"); lv_label_set_align(lblSeconds, LV_LABEL_ALIGN_CENTER); lv_obj_align(lblSeconds, lv_scr_act(), LV_ALIGN_CENTER, POS_X_SECONDS, POS_Y_TEXT); - btnHoursPlus = lv_btn_create(lv_scr_act(), NULL); + btnHoursPlus = lv_btn_create(lv_scr_act(), nullptr); btnHoursPlus->user_data = this; lv_obj_set_size(btnHoursPlus, 50, 40); lv_obj_align(btnHoursPlus, lv_scr_act(), LV_ALIGN_CENTER, -72, -50); lv_obj_set_style_local_value_str(btnHoursPlus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "+"); lv_obj_set_event_cb(btnHoursPlus, event_handler); - btnHoursMinus = lv_btn_create(lv_scr_act(), NULL); + btnHoursMinus = lv_btn_create(lv_scr_act(), nullptr); btnHoursMinus->user_data = this; lv_obj_set_size(btnHoursMinus, 50, 40); lv_obj_align(btnHoursMinus, lv_scr_act(), LV_ALIGN_CENTER, -72, 40); lv_obj_set_style_local_value_str(btnHoursMinus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "-"); lv_obj_set_event_cb(btnHoursMinus, event_handler); - btnMinutesPlus = lv_btn_create(lv_scr_act(), NULL); + btnMinutesPlus = lv_btn_create(lv_scr_act(), nullptr); btnMinutesPlus->user_data = this; lv_obj_set_size(btnMinutesPlus, 50, 40); lv_obj_align(btnMinutesPlus, lv_scr_act(), LV_ALIGN_CENTER, 0, -50); lv_obj_set_style_local_value_str(btnMinutesPlus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "+"); lv_obj_set_event_cb(btnMinutesPlus, event_handler); - btnMinutesMinus = lv_btn_create(lv_scr_act(), NULL); + btnMinutesMinus = lv_btn_create(lv_scr_act(), nullptr); btnMinutesMinus->user_data = this; lv_obj_set_size(btnMinutesMinus, 50, 40); lv_obj_align(btnMinutesMinus, lv_scr_act(), LV_ALIGN_CENTER, 0, 40); lv_obj_set_style_local_value_str(btnMinutesMinus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "-"); lv_obj_set_event_cb(btnMinutesMinus, event_handler); - btnSetTime = lv_btn_create(lv_scr_act(), NULL); + btnSetTime = lv_btn_create(lv_scr_act(), nullptr); btnSetTime->user_data = this; lv_obj_set_size(btnSetTime, 120, 48); lv_obj_align(btnSetTime, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, 0); @@ -114,7 +112,6 @@ SettingSetTime::~SettingSetTime() { } void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) { - if (event != LV_EVENT_CLICKED) return; @@ -124,29 +121,25 @@ void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) { hoursValue = 0; lv_label_set_text_fmt(lblHours, "%02d", hoursValue); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); - } - else if (object == btnHoursMinus) { + } else if (object == btnHoursMinus) { hoursValue--; if (hoursValue < 0) hoursValue = 23; lv_label_set_text_fmt(lblHours, "%02d", hoursValue); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); - } - else if (object == btnMinutesPlus) { + } else if (object == btnMinutesPlus) { minutesValue++; if (minutesValue > 59) minutesValue = 0; lv_label_set_text_fmt(lblMinutes, "%02d", minutesValue); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); - } - else if (object == btnMinutesMinus) { + } else if (object == btnMinutesMinus) { minutesValue--; if (minutesValue < 0) minutesValue = 59; lv_label_set_text_fmt(lblMinutes, "%02d", minutesValue); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); - } - else if (object == btnSetTime) { + } else if (object == btnSetTime) { NRF_LOG_INFO("Setting time (manually) to %02d:%02d:00", hoursValue, minutesValue); dateTimeController.SetTime(dateTimeController.Year(), static_cast(dateTimeController.Month()), diff --git a/src/displayapp/screens/settings/SettingSetTime.h b/src/displayapp/screens/settings/SettingSetTime.h index 63fb7d3e..8ba41eae 100644 --- a/src/displayapp/screens/settings/SettingSetTime.h +++ b/src/displayapp/screens/settings/SettingSetTime.h @@ -6,10 +6,8 @@ #include "displayapp/screens/Screen.h" namespace Pinetime { - namespace Applications { namespace Screens { - class SettingSetTime : public Screen{ public: SettingSetTime(DisplayApp* app, Pinetime::Controllers::DateTime &dateTimeController); @@ -17,8 +15,7 @@ namespace Pinetime { void HandleButtonPress(lv_obj_t *object, lv_event_t event); - private: - + private: Controllers::DateTime& dateTimeController; int hoursValue; @@ -30,7 +27,6 @@ namespace Pinetime { lv_obj_t * btnMinutesPlus; lv_obj_t * btnMinutesMinus; lv_obj_t * btnSetTime; - }; } } -- cgit v1.2.3