More tidying following review

This commit is contained in:
Kieran Cawthray 2021-08-15 15:00:54 +02:00
parent 5789f1527c
commit 639fd3a9bd

View File

@ -6,17 +6,14 @@
using namespace Pinetime::Applications::Screens; using namespace Pinetime::Applications::Screens;
namespace { namespace {
static void event_handler(lv_obj_t * obj, lv_event_t event) { static void event_handler(lv_obj_t* obj, lv_event_t event) {
SettingPineTimeStyle* screen = static_cast<SettingPineTimeStyle *>(obj->user_data); SettingPineTimeStyle* screen = static_cast<SettingPineTimeStyle*>(obj->user_data);
screen->UpdateSelected(obj, event); screen->UpdateSelected(obj, event);
} }
} }
SettingPineTimeStyle::SettingPineTimeStyle( SettingPineTimeStyle::SettingPineTimeStyle(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settingsController)
Pinetime::Applications::DisplayApp *app, Pinetime::Controllers::Settings &settingsController) : : Screen(app), settingsController {settingsController} {
Screen(app),
settingsController{settingsController}
{
timebar = lv_obj_create(lv_scr_act(), nullptr); timebar = lv_obj_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_bg_color(timebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, pts_colors[settingsController.GetPTSColorBG()]); lv_obj_set_style_local_bg_color(timebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, pts_colors[settingsController.GetPTSColorBG()]);
lv_obj_set_style_local_radius(timebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 0); lv_obj_set_style_local_radius(timebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 0);
@ -222,74 +219,79 @@ bool SettingPineTimeStyle::Refresh() {
return running; return running;
} }
void SettingPineTimeStyle::UpdateSelected(lv_obj_t *object, lv_event_t event) { void SettingPineTimeStyle::UpdateSelected(lv_obj_t* object, lv_event_t event) {
uint8_t valueTime = settingsController.GetPTSColorTime(); uint8_t valueTime = settingsController.GetPTSColorTime();
uint8_t valueBar = settingsController.GetPTSColorBar(); uint8_t valueBar = settingsController.GetPTSColorBar();
uint8_t valueBG = settingsController.GetPTSColorBG(); uint8_t valueBG = settingsController.GetPTSColorBG();
if((object == btnNextTime) && (event == LV_EVENT_PRESSED)) { if (event == LV_EVENT_CLICKED) {
if ( valueTime < 16 ) { if (object == btnNextTime) {
valueTime += 1; if (valueTime < 16) {
} else { valueTime += 1;
valueTime = 0; } else {
valueTime = 0;
}
settingsController.SetPTSColorTime(valueTime);
lv_obj_set_style_local_text_color(timeDD1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, pts_colors[valueTime]);
lv_obj_set_style_local_text_color(timeDD2, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, pts_colors[valueTime]);
lv_obj_set_style_local_text_color(timeAMPM, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, pts_colors[valueTime]);
} }
settingsController.SetPTSColorTime(valueTime); if (object == btnPrevTime) {
lv_obj_set_style_local_text_color(timeDD1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, pts_colors[valueTime]); if (valueTime > 0) {
lv_obj_set_style_local_text_color(timeDD2, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, pts_colors[valueTime]); valueTime -= 1;
lv_obj_set_style_local_text_color(timeAMPM, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, pts_colors[valueTime]); } else {
} valueTime = 16;
if((object == btnPrevTime) && (event == LV_EVENT_PRESSED)) { }
if ( valueTime > 0 ) { settingsController.SetPTSColorTime(valueTime);
valueTime -= 1; lv_obj_set_style_local_text_color(timeDD1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, pts_colors[valueTime]);
} else { lv_obj_set_style_local_text_color(timeDD2, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, pts_colors[valueTime]);
valueTime = 16; lv_obj_set_style_local_text_color(timeAMPM, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, pts_colors[valueTime]);
} }
settingsController.SetPTSColorTime(valueTime); if (object == btnNextBar) {
lv_obj_set_style_local_text_color(timeDD1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, pts_colors[valueTime]); if (valueBar < 16) {
lv_obj_set_style_local_text_color(timeDD2, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, pts_colors[valueTime]); valueBar += 1;
lv_obj_set_style_local_text_color(timeAMPM, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, pts_colors[valueTime]); // Avoid setting the sidebar black
} if (valueBar == 3) {
if((object == btnNextBar) && (event == LV_EVENT_PRESSED)) { valueBar += 1;
if ( valueBar < 16 ) { }
valueBar += 1; } else {
// Avoid setting the sidebar black valueBar = 0;
if ( valueBar == 3 ) { valueBar += 1; } }
} else { settingsController.SetPTSColorBar(valueBar);
valueBar = 0; lv_obj_set_style_local_bg_color(sidebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, pts_colors[valueBar]);
} }
settingsController.SetPTSColorBar(valueBar); if (object == btnPrevBar) {
lv_obj_set_style_local_bg_color(sidebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, pts_colors[valueBar]); if (valueBar > 0) {
} valueBar -= 1;
if((object == btnPrevBar) && (event == LV_EVENT_PRESSED)) { // Avoid setting the sidebar black
if ( valueBar > 0 ) { if (valueBar == 3) {
valueBar -= 1; valueBar -= 1;
// Avoid setting the sidebar black }
if ( valueBar == 3 ) { valueBar -= 1; } } else {
} else { valueBar = 16;
valueBar = 16; }
settingsController.SetPTSColorBar(valueBar);
lv_obj_set_style_local_bg_color(sidebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, pts_colors[valueBar]);
} }
settingsController.SetPTSColorBar(valueBar); if (object == btnNextBG) {
lv_obj_set_style_local_bg_color(sidebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, pts_colors[valueBar]); if (valueBG < 16) {
} valueBG += 1;
if((object == btnNextBG) && (event == LV_EVENT_PRESSED)) { } else {
if ( valueBG < 16 ) { valueBG = 0;
valueBG += 1; }
} else { settingsController.SetPTSColorBG(valueBG);
valueBG = 0; lv_obj_set_style_local_bg_color(timebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, pts_colors[valueBG]);
} }
settingsController.SetPTSColorBG(valueBG); if (object == btnPrevBG) {
lv_obj_set_style_local_bg_color(timebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, pts_colors[valueBG]); if (valueBG > 0) {
} valueBG -= 1;
if((object == btnPrevBG) && (event == LV_EVENT_PRESSED)) { } else {
if ( valueBG > 0 ) { valueBG = 16;
valueBG -= 1; }
} else { settingsController.SetPTSColorBG(valueBG);
valueBG = 16; lv_obj_set_style_local_bg_color(timebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, pts_colors[valueBG]);
} }
settingsController.SetPTSColorBG(valueBG); if (object == btnReset) {
lv_obj_set_style_local_bg_color(timebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, pts_colors[valueBG]);
}
if((object == btnReset) && (event == LV_EVENT_PRESSED)) {
settingsController.SetPTSColorTime(11); settingsController.SetPTSColorTime(11);
lv_obj_set_style_local_text_color(timeDD1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, pts_colors[11]); lv_obj_set_style_local_text_color(timeDD1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, pts_colors[11]);
lv_obj_set_style_local_text_color(timeDD2, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, pts_colors[11]); lv_obj_set_style_local_text_color(timeDD2, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, pts_colors[11]);
@ -298,25 +300,26 @@ void SettingPineTimeStyle::UpdateSelected(lv_obj_t *object, lv_event_t event) {
lv_obj_set_style_local_bg_color(sidebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, pts_colors[11]); lv_obj_set_style_local_bg_color(sidebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, pts_colors[11]);
settingsController.SetPTSColorBG(3); settingsController.SetPTSColorBG(3);
lv_obj_set_style_local_bg_color(timebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, pts_colors[3]); lv_obj_set_style_local_bg_color(timebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, pts_colors[3]);
}
if((object == btnRandom) && (event == LV_EVENT_PRESSED)) {
uint8_t randTime = rand() % 17;
uint8_t randBar = rand() % 17;
uint8_t randBG = rand() % 17;
// Check if the time color is the same as its background, or if the sidebar is black. If so, change them to more useful values.
if (randTime == randBG) {
randBG += 1;
} }
if (randBar == 3) { if (object == btnRandom) {
randBar = randTime; uint8_t randTime = rand() % 17;
uint8_t randBar = rand() % 17;
uint8_t randBG = rand() % 17;
// Check if the time color is the same as its background, or if the sidebar is black. If so, change them to more useful values.
if (randTime == randBG) {
randBG += 1;
}
if (randBar == 3) {
randBar = randTime;
}
settingsController.SetPTSColorTime(randTime);
lv_obj_set_style_local_text_color(timeDD1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, pts_colors[randTime]);
lv_obj_set_style_local_text_color(timeDD2, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, pts_colors[randTime]);
lv_obj_set_style_local_text_color(timeAMPM, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, pts_colors[randTime]);
settingsController.SetPTSColorBar(randBar);
lv_obj_set_style_local_bg_color(sidebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, pts_colors[randBar]);
settingsController.SetPTSColorBG(randBG);
lv_obj_set_style_local_bg_color(timebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, pts_colors[randBG]);
} }
settingsController.SetPTSColorTime(randTime);
lv_obj_set_style_local_text_color(timeDD1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, pts_colors[randTime]);
lv_obj_set_style_local_text_color(timeDD2, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, pts_colors[randTime]);
lv_obj_set_style_local_text_color(timeAMPM, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, pts_colors[randTime]);
settingsController.SetPTSColorBar(randBar);
lv_obj_set_style_local_bg_color(sidebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, pts_colors[randBar]);
settingsController.SetPTSColorBG(randBG);
lv_obj_set_style_local_bg_color(timebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, pts_colors[randBG]);
} }
} }