From 7edfc534819ba7b9a14523d84df62952852a0fe3 Mon Sep 17 00:00:00 2001 From: Kieran Cawthray Date: Thu, 24 Jun 2021 21:49:04 +0200 Subject: [PATCH] PineTimeStyle color picker add settings integration --- src/components/settings/Settings.h | 31 ++++++ .../screens/settings/SettingPineTimeStyle.cpp | 102 ++++++++++-------- 2 files changed, 86 insertions(+), 47 deletions(-) diff --git a/src/components/settings/Settings.h b/src/components/settings/Settings.h index 4409425b..69e28e5b 100644 --- a/src/components/settings/Settings.h +++ b/src/components/settings/Settings.h @@ -27,6 +27,33 @@ namespace Pinetime { return settings.clockFace; }; + void SetPTSColorTime(uint8_t colorTime) { + if (colorTime != settings.PTSColorTime) + settingsChanged = true; + settings.PTSColorTime = colorTime; + }; + uint8_t GetPTSColorTime() const { + return settings.PTSColorTime; + }; + + void SetPTSColorBar(uint8_t colorBar) { + if (colorBar != settings.PTSColorBar) + settingsChanged = true; + settings.PTSColorBar = colorBar; + }; + uint8_t GetPTSColorBar() const { + return settings.PTSColorBar; + }; + + void SetPTSColorBG(uint8_t colorBG) { + if (colorBG != settings.PTSColorBG) + settingsChanged = true; + settings.PTSColorBG = colorBG; + }; + uint8_t GetPTSColorBG() const { + return settings.PTSColorBG; + }; + void SetAppMenu(uint8_t menu) { appMenu = menu; }; @@ -103,6 +130,10 @@ namespace Pinetime { uint8_t clockFace = 0; + uint8_t PTSColorTime = 11; + uint8_t PTSColorBar = 11; + uint8_t PTSColorBG = 3; + uint32_t stepsGoal = 10000; uint32_t screenTimeOut = 15000; diff --git a/src/displayapp/screens/settings/SettingPineTimeStyle.cpp b/src/displayapp/screens/settings/SettingPineTimeStyle.cpp index 3aceeb71..3673e79c 100644 --- a/src/displayapp/screens/settings/SettingPineTimeStyle.cpp +++ b/src/displayapp/screens/settings/SettingPineTimeStyle.cpp @@ -12,6 +12,12 @@ namespace { } } +lv_color_t pts_colors[17] = {LV_COLOR_WHITE, LV_COLOR_SILVER, LV_COLOR_GRAY, LV_COLOR_BLACK, + LV_COLOR_RED, LV_COLOR_MAROON, LV_COLOR_YELLOW, LV_COLOR_OLIVE, + LV_COLOR_LIME, LV_COLOR_GREEN, LV_COLOR_CYAN, LV_COLOR_TEAL, + LV_COLOR_BLUE, LV_COLOR_NAVY, LV_COLOR_MAGENTA, LV_COLOR_PURPLE, + LV_COLOR_ORANGE}; + SettingPineTimeStyle::SettingPineTimeStyle( Pinetime::Applications::DisplayApp *app, Pinetime::Controllers::Settings &settingsController) : Screen(app), @@ -19,7 +25,7 @@ SettingPineTimeStyle::SettingPineTimeStyle( { timebar = lv_obj_create(lv_scr_act(), nullptr); - lv_obj_set_style_local_bg_color(timebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x000000)); + lv_obj_set_style_local_bg_color(timebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK); lv_obj_set_style_local_radius(timebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 0); lv_obj_set_size(timebar, 200, 240); lv_obj_align(timebar, lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 5, 0); @@ -28,18 +34,18 @@ SettingPineTimeStyle::SettingPineTimeStyle( timeDD1 = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_font(timeDD1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &open_sans_light); - lv_obj_set_style_local_text_color(timeDD1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x008080)); + lv_obj_set_style_local_text_color(timeDD1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_TEAL); lv_label_set_text(timeDD1, "12"); lv_obj_align(timeDD1, timebar, LV_ALIGN_IN_TOP_MID, 5, 5); timeDD2 = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_font(timeDD2, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &open_sans_light); - lv_obj_set_style_local_text_color(timeDD2, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x008080)); + lv_obj_set_style_local_text_color(timeDD2, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_TEAL); lv_label_set_text(timeDD2, "34"); lv_obj_align(timeDD2, timebar, LV_ALIGN_IN_BOTTOM_MID, 5, -5); timeAMPM = lv_label_create(lv_scr_act(), nullptr); - lv_obj_set_style_local_text_color(timeAMPM, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x008080)); + lv_obj_set_style_local_text_color(timeAMPM, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_TEAL); lv_obj_set_style_local_text_line_space(timeAMPM, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, -3); lv_label_set_text(timeAMPM, "A\nM"); lv_obj_align(timeAMPM, timebar, LV_ALIGN_IN_BOTTOM_LEFT, 2, -20); @@ -47,7 +53,7 @@ SettingPineTimeStyle::SettingPineTimeStyle( /* Create a 40px wide bar down the right side of the screen */ sidebar = lv_obj_create(lv_scr_act(), nullptr); - lv_obj_set_style_local_bg_color(sidebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x008080)); + lv_obj_set_style_local_bg_color(sidebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_TEAL); lv_obj_set_style_local_radius(sidebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 0); lv_obj_set_size(sidebar, 40, 240); lv_obj_align(sidebar, lv_scr_act(), LV_ALIGN_IN_TOP_RIGHT, 0, 0); @@ -142,6 +148,13 @@ SettingPineTimeStyle::SettingPineTimeStyle( lv_obj_set_style_local_line_width(stepGauge, LV_GAUGE_PART_NEEDLE, LV_STATE_DEFAULT, 4); lv_obj_set_style_local_pad_inner(stepGauge, LV_GAUGE_PART_NEEDLE, LV_STATE_DEFAULT, 4); + backgroundLabel = lv_label_create(lv_scr_act(), nullptr); + lv_obj_set_click(backgroundLabel, true); + lv_label_set_long_mode(backgroundLabel, LV_LABEL_LONG_CROP); + lv_obj_set_size(backgroundLabel, 240, 240); + lv_obj_set_pos(backgroundLabel, 0, 0); + lv_label_set_text(backgroundLabel, ""); + // lv_style_copy(&style_button, &lv_style_plain_color); // style_button.body.opa = LV_OPA_50; btnNextTime = lv_btn_create(lv_scr_act(), nullptr); @@ -186,14 +199,6 @@ SettingPineTimeStyle::SettingPineTimeStyle( lv_obj_set_style_local_value_str(btnPrevBG, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "<"); lv_obj_set_event_cb(btnPrevBG, event_handler); - backgroundLabel = lv_label_create(lv_scr_act(), nullptr); - lv_obj_set_click(backgroundLabel, true); - lv_label_set_long_mode(backgroundLabel, LV_LABEL_LONG_CROP); - lv_obj_set_size(backgroundLabel, 240, 240); - lv_obj_set_pos(backgroundLabel, 0, 0); - lv_label_set_text(backgroundLabel, ""); - - /* stepValue = lv_label_create(lv_scr_act(), nullptr); @@ -228,52 +233,55 @@ bool SettingPineTimeStyle::Refresh() { } void SettingPineTimeStyle::UpdateSelected(lv_obj_t *object, lv_event_t event) { - uint8_t value = 0; - lv_color_t pts_colors[17] = {LV_COLOR_WHITE, LV_COLOR_SILVER, LV_COLOR_GRAY, LV_COLOR_BLACK, - LV_COLOR_RED, LV_COLOR_MAROON, LV_COLOR_YELLOW, LV_COLOR_OLIVE, - LV_COLOR_LIME, LV_COLOR_GREEN, LV_COLOR_CYAN, LV_COLOR_TEAL, - LV_COLOR_BLUE, LV_COLOR_NAVY, LV_COLOR_MAGENTA, LV_COLOR_PURPLE, - LV_COLOR_ORANGE}; + uint8_t valueTime = settingsController.GetPTSColorTime(); + uint8_t valueBar = settingsController.GetPTSColorBar(); + uint8_t valueBG = settingsController.GetPTSColorBG(); - if((object == btnNextBar) && (event == LV_EVENT_PRESSED)) { - if ( value < 16 ) { - value += 1; - lv_obj_set_style_local_bg_color(sidebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, pts_colors[value]); - } - } - if((object == btnPrevBar) && (event == LV_EVENT_PRESSED)) { - if ( value > 0 ) { - value -= 1; - lv_obj_set_style_local_bg_color(sidebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, pts_colors[value]); - } - } if((object == btnNextTime) && (event == LV_EVENT_PRESSED)) { - if ( value < 16 ) { - value += 1; - lv_obj_set_style_local_text_color(timeDD1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, pts_colors[value]); - lv_obj_set_style_local_text_color(timeDD2, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, pts_colors[value]); - lv_obj_set_style_local_text_color(timeAMPM, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, pts_colors[value]); + if ( valueTime < 17 ) { + valueTime += 1; + 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]); } } if((object == btnPrevTime) && (event == LV_EVENT_PRESSED)) { - if ( value > 0 ) { - value -= 1; - lv_obj_set_style_local_text_color(timeDD1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, pts_colors[value]); - lv_obj_set_style_local_text_color(timeDD2, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, pts_colors[value]); - lv_obj_set_style_local_text_color(timeAMPM, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, pts_colors[value]); + if ( valueTime > 0 ) { + valueTime -= 1; + 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]); + } + } + if((object == btnNextBar) && (event == LV_EVENT_PRESSED)) { + if ( valueBar < 17 ) { + valueBar += 1; + settingsController.SetPTSColorBar(valueBar); + lv_obj_set_style_local_bg_color(sidebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, pts_colors[valueBar]); + } + } + if((object == btnPrevBar) && (event == LV_EVENT_PRESSED)) { + if ( valueBar > 0 ) { + valueBar -= 1; + settingsController.SetPTSColorBar(valueBar); + lv_obj_set_style_local_bg_color(sidebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, pts_colors[valueBar]); } } if((object == btnNextBG) && (event == LV_EVENT_PRESSED)) { - if ( value < 16 ) { - value += 1; - lv_obj_set_style_local_bg_color(timebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, pts_colors[value]); + if ( valueBG < 17 ) { + valueBG += 1; + settingsController.SetPTSColorBG(valueBG); + lv_obj_set_style_local_bg_color(timebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, pts_colors[valueBG]); } } if((object == btnPrevBG) && (event == LV_EVENT_PRESSED)) { - if ( value > 0 ) { - value -= 1; - lv_obj_set_style_local_bg_color(timebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, pts_colors[value]); + if ( valueBG > 0 ) { + valueBG -= 1; + settingsController.SetPTSColorBG(valueBG); + lv_obj_set_style_local_bg_color(timebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, pts_colors[valueBG]); } }