11#include " displayapp/InfiniTimeTheme.h"
2+ #include < libraries/log/nrf_log.h>
23#include " components/fs/FS.h"
34#include < algorithm>
4- #include < cstdlib>
55#include < cstring>
6- #include < cstdio>
7-
8- #ifdef NRF_LOG_ENABLED
9- #include < libraries/log/nrf_log.h>
10- #define THEME_LOG (fmt, ...) NRF_LOG_INFO(fmt, ##__VA_ARGS__)
11- #else
12- #define THEME_LOG (fmt, ...) printf(" Theme: " fmt " \n " , ##__VA_ARGS__)
13- #endif
146
157// Replace LV_DPX with a constexpr version using a constant LV_DPI
168#undef LV_DPX
@@ -31,23 +23,21 @@ namespace {
3123 if (!hexStr || std::strlen (hexStr) < 6 ) {
3224 return defaultColor;
3325 }
34-
26+
3527 char * endptr;
3628 uint32_t value = std::strtoul (hexStr, &endptr, 16 );
37-
29+
3830 // Check if conversion was successful and we consumed all characters
3931 if (endptr == hexStr || *endptr != ' \0 ' || value > 0xFFFFFF ) {
4032 return defaultColor;
4133 }
42-
34+
4335 uint8_t r = (value >> 16 ) & 0xFF ;
4436 uint8_t g = (value >> 8 ) & 0xFF ;
4537 uint8_t b = value & 0xFF ;
46-
38+
4739 lv_color_t result = LV_COLOR_MAKE (r, g, b);
48- THEME_LOG (" parseHexColor: input='%s' -> 0x%06X -> RGB(%02X,%02X,%02X) -> 0x%06X" ,
49- hexStr, value, r, g, b, result.full );
50-
40+
5141 return result;
5242 }
5343
@@ -64,7 +54,7 @@ namespace {
6454 if (*line == ' #' || *line == ' \0 ' || *line == ' \n ' || *line == ' \r ' ) {
6555 return false ;
6656 }
67-
57+
6858 // Parse key
6959 size_t keyLen = 0 ;
7060 while (*line != ' =' && *line != ' \0 ' && *line != ' \n ' && keyLen < maxKeyLen - 1 ) {
@@ -76,31 +66,31 @@ namespace {
7666 key[keyLen++] = c;
7767 }
7868 }
79-
69+
8070 // Trim trailing whitespace from key
8171 while (keyLen > 0 && (key[keyLen - 1 ] == ' ' || key[keyLen - 1 ] == ' \t ' )) {
8272 keyLen--;
8373 }
84-
74+
8575 key[keyLen] = ' \0 ' ;
86-
76+
8777 if (*line != ' =' || keyLen == 0 ) {
8878 return false ;
8979 }
9080 line++; // Skip '='
91-
81+
9282 // Skip leading whitespace in value
9383 while (*line == ' ' || *line == ' \t ' ) {
9484 line++;
9585 }
96-
86+
9787 // Parse value
9888 size_t valueLen = 0 ;
9989 while (*line != ' \0 ' && *line != ' \n ' && *line != ' \r ' && valueLen < maxValueLen - 1 ) {
10090 value[valueLen++] = *line++;
10191 }
10292 value[valueLen] = ' \0 ' ;
103-
93+
10494 return true ;
10595 }
10696
@@ -117,14 +107,12 @@ namespace {
117107 */
118108 void loadThemeConfig (Pinetime::Controllers::FS* filesystem) {
119109 if (!filesystem) {
120- THEME_LOG (" loadThemeConfig: No filesystem provided" );
121110 return ;
122111 }
123112
124- THEME_LOG (" loadThemeConfig: Attempting to open /themes/theme.cfg" );
125113 lfs_file_t file;
126114 if (filesystem->FileOpen (&file, " /themes/theme.cfg" , LFS_O_RDONLY) != LFS_ERR_OK) {
127- THEME_LOG (" loadThemeConfig: Failed to open /themes/theme.cfg" );
115+ NRF_LOG_INFO (" loadThemeConfig: Failed to open /themes/theme.cfg" );
128116 return ;
129117 }
130118
@@ -184,18 +172,7 @@ namespace {
184172
185173 lineStart = lineEnd + 1 ; // Skip the newline character
186174 }
187-
188- // Log color summary
189- THEME_LOG (" === Color Configuration Summary (Hex Values) ===" );
190- THEME_LOG (" accent_light = 0x%06X" , Colors::accent_light.full );
191- THEME_LOG (" accent = 0x%06X" , Colors::accent.full );
192- THEME_LOG (" accent_dark = 0x%06X" , Colors::accent_dark.full );
193- THEME_LOG (" highlight = 0x%06X" , Colors::highlight.full );
194- THEME_LOG (" text_primary = 0x%06X" , Colors::text_primary.full );
195- THEME_LOG (" text_header = 0x%06X" , Colors::text_header.full );
196- THEME_LOG (" page_bg = 0x%06X" , Colors::page_bg.full );
197- THEME_LOG (" icon = 0x%06X" , Colors::icon.full );
198- }
175+ }
199176}
200177
201178static Pinetime::Controllers::FS* themeFilesystem = nullptr ;
@@ -205,10 +182,10 @@ static void refresh_object_tree(lv_obj_t* obj) {
205182 if (obj == nullptr ) {
206183 return ;
207184 }
208-
185+
209186 // Refresh this object
210187 lv_obj_refresh_style (obj, LV_OBJ_PART_ALL, LV_STYLE_PROP_ALL);
211-
188+
212189 // Recursively refresh all children
213190 lv_obj_t * child = lv_obj_get_child (obj, nullptr );
214191 while (child != nullptr ) {
@@ -413,21 +390,13 @@ static void basic_init() {
413390 * @return a pointer to reference this theme later
414391 */
415392lv_theme_t * lv_pinetime_theme_init (Pinetime::Controllers::FS* filesystem) {
416- THEME_LOG (" === lv_pinetime_theme_init() called ===" );
417-
393+
418394 // Set the filesystem pointer if provided
419395 if (filesystem != nullptr ) {
420- THEME_LOG (" Filesystem provided, loading custom theme config" );
421396 themeFilesystem = filesystem;
422397 loadThemeConfig (filesystem);
423- } else {
424- THEME_LOG (" No filesystem provided, using default colors" );
425398 }
426399
427- THEME_LOG (" === Initializing theme with colors ===" );
428- THEME_LOG (" primary = 0x%06X" , Colors::text_primary.full );
429- THEME_LOG (" secondary = 0x%06X" , Colors::text_header.full );
430-
431400 theme.color_primary = Colors::text_primary;
432401 theme.color_secondary = Colors::text_header;
433402 theme.font_small = &jetbrains_mono_bold_20;
@@ -446,81 +415,32 @@ lv_theme_t* lv_pinetime_theme_init(Pinetime::Controllers::FS* filesystem) {
446415}
447416
448417void lv_pinetime_theme_set_filesystem (Pinetime::Controllers::FS* filesystem) {
449- THEME_LOG (" lv_pinetime_theme_set_filesystem() called with filesystem=%p" , (void *)filesystem);
450- if (filesystem == nullptr ) {
451- THEME_LOG (" lv_pinetime_theme_set_filesystem() called with NULL" );
452- } else {
453- THEME_LOG (" lv_pinetime_theme_set_filesystem() called with valid filesystem pointer" );
454- }
418+
455419 themeFilesystem = filesystem;
456- THEME_LOG (" themeFilesystem set to %p" , (void *)themeFilesystem);
457-
420+
458421 // If theme was already initialized and we now have a filesystem, try to reload colors
459422 if (inited && filesystem != nullptr ) {
460- THEME_LOG (" Theme already initialized, attempting to load config now" );
461423 loadThemeConfig (filesystem);
462424 }
463425}
464426
465427void lv_pinetime_theme_reload_config () {
466- THEME_LOG (" lv_pinetime_theme_reload_config() called" );
467428 if (themeFilesystem != nullptr ) {
468- THEME_LOG (" Attempting to reload theme config from filesystem" );
469429 loadThemeConfig (themeFilesystem);
470-
430+
471431 // Update the theme struct with new colors
472- THEME_LOG (" Updating theme colors: primary=0x%06X secondary=0x%06X" ,
473- Colors::text_primary.full , Colors::text_header.full );
474432 theme.color_primary = Colors::text_primary;
475433 theme.color_secondary = Colors::text_header;
476-
434+
477435 // Reinitialize the theme styles with the new colors
478- THEME_LOG (" Reinitializing theme styles with new colors" );
479436 basic_init ();
480-
437+
481438 // Refresh all objects on screen to apply the new styles
482439 lv_obj_t * scr = lv_scr_act ();
483440 if (scr != nullptr ) {
484- THEME_LOG (" Refreshing screen and all child objects recursively" );
485441 refresh_object_tree (scr);
486442 lv_obj_invalidate (scr);
487443 }
488- } else {
489- THEME_LOG (" Cannot reload config: themeFilesystem is NULL" );
490- }
491- }
492-
493- void lv_pinetime_theme_test_filesystem () {
494- THEME_LOG (" === Theme Filesystem Diagnostic Test ===" );
495- THEME_LOG (" themeFilesystem pointer: %p" , (void *)themeFilesystem);
496-
497- if (themeFilesystem == nullptr ) {
498- THEME_LOG (" ERROR: themeFilesystem is NULL, cannot test" );
499- return ;
500- }
501-
502- THEME_LOG (" Filesystem pointer is valid, attempting to open /themes/theme.cfg" );
503- lfs_file_t file;
504- int openResult = themeFilesystem->FileOpen (&file, " /themes/theme.cfg" , LFS_O_RDONLY);
505- THEME_LOG (" FileOpen result: %d (0=success, negative=error)" , openResult);
506-
507- if (openResult != LFS_ERR_OK) {
508- THEME_LOG (" Failed to open file, trying to list /themes directory" );
509- // Try to read directory structure
510- lfs_dir_t dir;
511- if (themeFilesystem->DirOpen (" /themes" , &dir) == LFS_ERR_OK) {
512- THEME_LOG (" Successfully opened /themes directory" );
513- lfs_info info;
514- while (themeFilesystem->DirRead (&dir, &info) > 0 ) {
515- THEME_LOG (" - %s (type: %d)" , info.name , info.type );
516- }
517- themeFilesystem->DirClose (&dir);
518- } else {
519- THEME_LOG (" /themes directory does not exist" );
520- }
521- } else {
522- THEME_LOG (" Successfully opened /themes/theme.cfg" );
523- themeFilesystem->FileClose (&file);
524444 }
525445}
526446
0 commit comments