diff --git a/.gitignore b/.gitignore index 89cc49c..da79ca3 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ .vscode/c_cpp_properties.json .vscode/launch.json .vscode/ipch +/img +*prefs.txt diff --git a/.vscode/settings.json b/.vscode/settings.json index 0ffe3cd..8ed0f31 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,6 +2,14 @@ "files.associations": { "*.embeddedhtml": "html", "random": "c", - "limits": "c" + "limits": "c", + "ui.h": "c", + "prefs.h": "c", + "array": "c", + "memory": "c", + "functional": "c", + "tuple": "c", + "utility": "c", + "system_error": "c" } } \ No newline at end of file diff --git a/hal/esp32/app_hal.cpp b/hal/esp32/app_hal.cpp index cd1fcd8..209deec 100644 --- a/hal/esp32/app_hal.cpp +++ b/hal/esp32/app_hal.cpp @@ -1,8 +1,9 @@ #include #include #include "PanelLan.h" -// #include +#include #include +#include #include "app_hal.h" #include "ui/ui.h" @@ -18,7 +19,8 @@ #endif PanelLan tft(BOARD); -// ChronosESP32 watch(NAME); +ChronosESP32 watch(NAME); +Preferences prefs; static const uint32_t screenWidth = 320; static const uint32_t screenHeight = 480; @@ -57,6 +59,35 @@ void my_touchpad_read(lv_indev_drv_t *indev_driver, lv_indev_data_t *data) } } + +void setPrefBool(const char *key, bool value) +{ + prefs.putBool(key, value); +} +void setPrefInt(const char *key, uint32_t value) +{ + prefs.putULong(key, value); +} + +uint32_t getPrefInt(const char *key, uint32_t def) +{ + return prefs.getULong(key, def); +} +bool getPrefBool(const char *key, bool def) +{ + return prefs.getBool(key, def); +} + +void onBrightnessChange(int32_t value) +{ + tft.setBrightness(value); + prefs.putInt("brightness", value); +} +void onTimeoutChange(int16_t selected) +{ + +} + void logCallback(Level level, unsigned long time, String message) { Serial.print(message); @@ -72,6 +103,8 @@ void hal_setup() tft.initDMA(); tft.startWrite(); + prefs.begin("my-app"); + lv_init(); Timber.i("Width %d\tHeight %d", screenWidth, screenHeight); @@ -96,6 +129,9 @@ void hal_setup() ui_init(); + watch.begin(); + tft.setBrightness(prefs.getInt("brightness", 200)); + Timber.i("Setup done"); } @@ -104,4 +140,10 @@ void hal_loop() { lv_timer_handler(); /* let the GUI do its work */ delay(5); + + watch.loop(); + + lv_label_set_text(ui_statusPanelTime, watch.getTime("%H:%M").c_str()); + lv_label_set_text(ui_Label41, watch.getTime("%H:%M").c_str()); + lv_label_set_text(ui_Label39, watch.getTime("%A, %B %d").c_str()); } diff --git a/hal/sdl2/app_hal.cpp b/hal/sdl2/app_hal.cpp index 7980341..1a039b9 100644 --- a/hal/sdl2/app_hal.cpp +++ b/hal/sdl2/app_hal.cpp @@ -2,6 +2,8 @@ #include #include #include +#include +#include #define SDL_MAIN_HANDLED /*To fix SDL's "undefined reference to WinMain" issue*/ #include SDL_INCLUDE_PATH #include "display/monitor.h" @@ -14,6 +16,7 @@ #include #include "ui/ui.h" +#include "prefs.h" static const uint32_t screenWidth = SDL_HOR_RES; @@ -40,8 +43,119 @@ static int tick_thread(void *data) return 0; } +/* Mouse read callback for SDL */ +void sdl_mouse_read2(lv_indev_drv_t *indev_drv, lv_indev_data_t *data) +{ + /*Get the current position and the state of the mouse*/ + int32_t x, y; + uint32_t state = SDL_GetMouseState(&x, &y); + + /*Set the coordinates and the pressed state*/ + data->point.x = x; + data->point.y = y; + + /*Button state: 1: pressed, 0: released*/ + data->state = state ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL; + + // return false; /*No buffering now so no more data read*/ +} + +void takeScreenshot(int width, int height) { + // Create a surface to hold the screenshot + SDL_Surface *surface = SDL_CreateRGBSurface(0, width, height, 32, + 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000); + if (surface == NULL) { + fprintf(stderr, "Failed to create surface for screenshot: %s\n", SDL_GetError()); + show_alert("Error", "Failed to create surface for screenshot"); + return; + } + + // Read pixels from the current framebuffer + if (SDL_RenderReadPixels(SDL_GetRenderer(SDL_GetWindowFromID(1)), NULL, SDL_PIXELFORMAT_ARGB8888, surface->pixels, surface->pitch) != 0) { + fprintf(stderr, "Failed to read pixels for screenshot: %s\n", SDL_GetError()); + show_alert("Error", "Failed to read pixels for screenshot"); + SDL_FreeSurface(surface); + return; + } + + const char* folder_name = "img"; + + // Create the folder if it doesn't exist + struct stat st = {0}; + if (stat(folder_name, &st) == -1) { + if (mkdir(folder_name) != 0) { + fprintf(stderr, "Failed to create directory: %s\n", folder_name); + show_alert("Error", "Failed to create directory"); + SDL_FreeSurface(surface); + return; + } + } + + // Create a filename for the screenshot + time_t now = time(0); + tm *ltm = localtime(&now); + + char filename[50]; + snprintf(filename, sizeof(filename), "%s/screenshot-%02d-%02d-%02d.bmp", folder_name, ltm->tm_hour, ltm->tm_min, ltm->tm_sec); + + // Save the surface as a BMP image + if (SDL_SaveBMP(surface, filename) != 0) { + fprintf(stderr, "Failed to save screenshot: %s\n", SDL_GetError()); + show_alert("Error", "Failed to save screenshot"); + SDL_FreeSurface(surface); + return; + } + + printf("Screenshot saved as %s\n", filename); + show_alert("Screenshot", "Screenshot saved to img folder"); + + // Free the surface + SDL_FreeSurface(surface); +} + + +void setPrefBool(const char *key, bool value) +{ + savePrefBool(key, value); +} +void setPrefInt(const char *key, uint32_t value) +{ + savePrefInt(key, value); +} + +uint32_t getPrefInt(const char *key, uint32_t def) +{ + uint32_t v; + if (readPrefInt(key, &v)){ + return v; + } + return def; +} +bool getPrefBool(const char *key, bool def) +{ + bool v; + if (readPrefBool(key, &v)){ + return v; + } + return def; + +} + +void onBrightnessChange(int32_t value) +{ + savePrefInt("brightness", value); +} +void onTimeoutChange(int16_t selected) +{ + savePrefInt("timeout", selected); +} + void hal_setup(void) { + if (SDL_Init(SDL_INIT_VIDEO) != 0) { + fprintf(stderr, "SDL_Init Error: %s\n", SDL_GetError()); + return; + } // Workaround for sdl2 `-m32` crash // https://bugs.launchpad.net/ubuntu/+source/libsdl2/+bug/1775067/comments/7 #ifndef WIN32 @@ -72,7 +186,7 @@ void hal_setup(void) static lv_indev_drv_t indev_drv; lv_indev_drv_init(&indev_drv); /*Basic initialization*/ indev_drv.type = LV_INDEV_TYPE_POINTER; - indev_drv.read_cb = sdl_mouse_read; /*This function will be called periodically (by the library) to get the mouse position and state*/ + indev_drv.read_cb = sdl_mouse_read2; /*This function will be called periodically (by the library) to get the mouse position and state*/ lv_indev_drv_register(&indev_drv); sdl_init(); @@ -87,9 +201,44 @@ void hal_setup(void) void hal_loop(void) { + SDL_Event event; + while (1) { SDL_Delay(5); + while (SDL_PollEvent(&event)) + { + switch (event.type) + { + case SDL_QUIT: + // Handle quit event (e.g., user closes the window) + // You might want to add code to gracefully exit your program here + break; + case SDL_KEYDOWN: + // Handle key press event + // SDL_KEYDOWN event occurs when a key is pressed + // You can get the pressed key using event.key.keysym.sym + switch (event.key.keysym.sym) + { + // Example for handling specific keys + case SDLK_UP: + // Handle the up arrow key press + break; + case SDLK_DOWN: + // Handle the down arrow key press + break; + case SDLK_s: + takeScreenshot(SDL_HOR_RES, SDL_VER_RES); + break; + } + break; + case SDL_KEYUP: + // Handle key release event if needed + // SDL_KEYUP event occurs when a key is released + break; + } + } + lv_task_handler(); time_t now = time(0); diff --git a/hal/sdl2/prefs.c b/hal/sdl2/prefs.c new file mode 100644 index 0000000..9ace002 --- /dev/null +++ b/hal/sdl2/prefs.c @@ -0,0 +1,111 @@ + + +#include "prefs.h" + + + +void savePref(const char *key, const char *value) +{ + FILE *file = fopen(PREF_FILE, "r+"); // Open file for reading and writing + if (file == NULL) + { + // If the file does not exist, create it + file = fopen(PREF_FILE, "w+"); + if (file == NULL) + { + printf("Error opening file!\n"); + return; + } + } + + char line[MAX_LINE_LENGTH]; + long pos = 0; + bool found = false; + + while (fgets(line, sizeof(line), file)) + { + char currentKey[50]; + sscanf(line, "%[^:]:", currentKey); + + if (strcmp(currentKey, key) == 0) + { + found = true; + break; + } + pos = ftell(file); + } + + if (found) + { + fseek(file, pos, SEEK_SET); + fprintf(file, "%s:%s\n", key, value); + } + else + { + fseek(file, 0, SEEK_END); + fprintf(file, "%s:%s\n", key, value); + } + + fclose(file); +} + +void savePrefBool(const char *key, bool value) +{ + savePrefInt(key, value ? 1 : 0); // Convert boolean to string +} + +void savePrefInt(const char *key, uint32_t value) +{ + char strValue[50]; + sprintf(strValue, "%08d", value); // Convert integer to string + savePref(key, strValue); +} + +bool readPref(const char *key, char *value) +{ + FILE *file = fopen(PREF_FILE, "r"); // Open file for reading + if (file == NULL) + { + printf("Error opening file!\n"); + return false; + } + + char line[MAX_LINE_LENGTH]; + while (fgets(line, sizeof(line), file)) + { + char currentKey[50], currentValue[50]; + sscanf(line, "%[^:]:%s", currentKey, currentValue); + + if (strcmp(currentKey, key) == 0) + { + strcpy(value, currentValue); + fclose(file); + return true; + } + } + + fclose(file); + return false; +} + +bool readPrefInt(const char *key, uint32_t *value) +{ + char strValue[50]; + if (readPref(key, strValue)) + { + *value = atoi(strValue); // Convert string to integer + return true; + } + return false; +} + +bool readPrefBool(const char *key, bool *value) +{ + char strValue[50]; + if (readPref(key, strValue)) + { + *value = atoi(strValue) != 0; // Convert string to integer + return true; + } + return false; +} \ No newline at end of file diff --git a/hal/sdl2/prefs.h b/hal/sdl2/prefs.h new file mode 100644 index 0000000..2a652fd --- /dev/null +++ b/hal/sdl2/prefs.h @@ -0,0 +1,31 @@ +#ifndef PREFS_H +#define PREFS_H + +#ifdef __cplusplus +extern "C" { +#endif + + +#include +#include +#include +#include + +#define MAX_LINE_LENGTH 100 + +#define PREF_FILE "prefs.txt" + +void savePref(const char *key, const char *value); +void savePrefBool(const char *key, bool value); +void savePrefInt(const char *key, uint32_t value); + +bool readPref(const char *key, char *value); +bool readPrefInt(const char *key, uint32_t *value); +bool readPrefBool(const char *key, bool *value); + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index f1e2043..561772a 100644 --- a/platformio.ini +++ b/platformio.ini @@ -90,7 +90,7 @@ extra_scripts = lib_deps = ${env.lib_deps} lovyan03/LovyanGFX@^1.1.16 - ; fbiego/ChronosESP32@^1.4.0 + fbiego/ChronosESP32@^1.4.0 fbiego/Timber@^1.0.0 build_flags = @@ -99,6 +99,7 @@ build_flags = !python -c "import os; print(' '.join(['-I {}'.format(i[0].replace('\x5C','/')) for i in os.walk('hal/esp32')]))" -D LV_TICK_CUSTOM=1 -D LV_MEM_CUSTOM=0 + -D MIN_BG_IMG=1 build_src_filter = +<*> @@ -140,3 +141,4 @@ build_flags = build_src_filter = ${esp32.build_src_filter} + diff --git a/screenshots/stars.png b/screenshots/stars.png index 2457f86..5539c08 100644 Binary files a/screenshots/stars.png and b/screenshots/stars.png differ diff --git a/src/ui/images/ui_img_img0_png.c b/src/ui/images/ui_img_img0_png.c index 3c26369..71700f5 100644 --- a/src/ui/images/ui_img_img0_png.c +++ b/src/ui/images/ui_img_img0_png.c @@ -3,6 +3,8 @@ // LVGL version: 8.3.11 // Project name: W10M +#ifndef MIN_BG_IMG + #include "../ui.h" #ifndef LV_ATTRIBUTE_MEM_ALIGN @@ -2867,3 +2869,4 @@ const lv_img_dsc_t ui_img_img0_png = { .data = ui_img_img0_png_data }; +#endif \ No newline at end of file diff --git a/src/ui/images/ui_img_img3_png.c b/src/ui/images/ui_img_img3_png.c index e83d17d..cf602e5 100644 --- a/src/ui/images/ui_img_img3_png.c +++ b/src/ui/images/ui_img_img3_png.c @@ -3,6 +3,8 @@ // LVGL version: 8.3.11 // Project name: W10M +#ifndef MIN_BG_IMG + #include "../ui.h" #ifndef LV_ATTRIBUTE_MEM_ALIGN @@ -2867,3 +2869,4 @@ const lv_img_dsc_t ui_img_img3_png = { .data = ui_img_img3_png_data }; +#endif diff --git a/src/ui/images/ui_img_img4_png.c b/src/ui/images/ui_img_img4_png.c index fb9d9c3..0ffc5fa 100644 --- a/src/ui/images/ui_img_img4_png.c +++ b/src/ui/images/ui_img_img4_png.c @@ -3,6 +3,9 @@ // LVGL version: 8.3.11 // Project name: W10M + +#ifndef MIN_BG_IMG + #include "../ui.h" #ifndef LV_ATTRIBUTE_MEM_ALIGN @@ -2867,3 +2870,4 @@ const lv_img_dsc_t ui_img_img4_png = { .data = ui_img_img4_png_data }; +#endif diff --git a/src/ui/images/ui_img_img7_png.c b/src/ui/images/ui_img_img7_png.c index 24b1087..48f869a 100644 --- a/src/ui/images/ui_img_img7_png.c +++ b/src/ui/images/ui_img_img7_png.c @@ -3,6 +3,8 @@ // LVGL version: 8.3.11 // Project name: W10M +#ifndef MIN_BG_IMG + #include "../ui.h" #ifndef LV_ATTRIBUTE_MEM_ALIGN @@ -2867,3 +2869,4 @@ const lv_img_dsc_t ui_img_img7_png = { .data = ui_img_img7_png_data }; +#endif \ No newline at end of file diff --git a/src/ui/images/ui_img_img9_png.c b/src/ui/images/ui_img_img9_png.c index dc31f51..53932e8 100644 --- a/src/ui/images/ui_img_img9_png.c +++ b/src/ui/images/ui_img_img9_png.c @@ -3,6 +3,9 @@ // LVGL version: 8.3.11 // Project name: W10M + +#ifndef MIN_BG_IMG + #include "../ui.h" #ifndef LV_ATTRIBUTE_MEM_ALIGN @@ -2867,3 +2870,4 @@ const lv_img_dsc_t ui_img_img9_png = { .data = ui_img_img9_png_data }; +#endif \ No newline at end of file diff --git a/src/ui/screens/ui_homeScreen.c b/src/ui/screens/ui_homeScreen.c index 4c8a15b..b846c99 100644 --- a/src/ui/screens/ui_homeScreen.c +++ b/src/ui/screens/ui_homeScreen.c @@ -330,20 +330,31 @@ void ui_homeScreen_screen_init(void) lv_obj_set_style_bg_opa(ui_statusPanelLeft, 0, LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_border_width(ui_statusPanelLeft, 0, LV_PART_MAIN | LV_STATE_DEFAULT); - ui_statusPanelCellular = lv_img_create(ui_statusPanelLeft); - lv_img_set_src(ui_statusPanelCellular, &ui_img_cellular_ic_png); - lv_obj_set_width(ui_statusPanelCellular, LV_SIZE_CONTENT); /// 1 - lv_obj_set_height(ui_statusPanelCellular, LV_SIZE_CONTENT); /// 1 - lv_obj_set_align(ui_statusPanelCellular, LV_ALIGN_CENTER); - lv_obj_add_flag(ui_statusPanelCellular, LV_OBJ_FLAG_ADV_HITTEST); /// Flags - lv_obj_clear_flag(ui_statusPanelCellular, LV_OBJ_FLAG_SCROLLABLE); /// Flags + ui_statusCellularBar = lv_bar_create(ui_statusPanelLeft); + lv_bar_set_range(ui_statusCellularBar, 0, 10); + lv_bar_set_value(ui_statusCellularBar, 4, LV_ANIM_OFF); + lv_bar_set_start_value(ui_statusCellularBar, 0, LV_ANIM_OFF); + lv_obj_set_width(ui_statusCellularBar, 16); + lv_obj_set_height(ui_statusCellularBar, 16); + lv_obj_set_align(ui_statusCellularBar, LV_ALIGN_CENTER); + lv_obj_set_style_radius(ui_statusCellularBar, 0, LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_bg_color(ui_statusCellularBar, lv_color_hex(0xFFFFFF), LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_bg_opa(ui_statusCellularBar, 0, LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_bg_img_src(ui_statusCellularBar, &ui_img_cellular_ic_png, LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_bg_img_recolor(ui_statusCellularBar, lv_color_hex(0x383838), LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_bg_img_recolor_opa(ui_statusCellularBar, 255, LV_PART_MAIN | LV_STATE_DEFAULT); + + lv_obj_set_style_radius(ui_statusCellularBar, 0, LV_PART_INDICATOR | LV_STATE_DEFAULT); + lv_obj_set_style_bg_color(ui_statusCellularBar, lv_color_hex(0xFFFFFF), LV_PART_INDICATOR | LV_STATE_DEFAULT); + lv_obj_set_style_bg_opa(ui_statusCellularBar, 0, LV_PART_INDICATOR | LV_STATE_DEFAULT); + lv_obj_set_style_bg_img_src(ui_statusCellularBar, &ui_img_cellular_ic_png, LV_PART_INDICATOR | LV_STATE_DEFAULT); ui_statusPanelWifi = lv_img_create(ui_statusPanelLeft); lv_img_set_src(ui_statusPanelWifi, &ui_img_wifi_ic_png); lv_obj_set_width(ui_statusPanelWifi, LV_SIZE_CONTENT); /// 1 lv_obj_set_height(ui_statusPanelWifi, LV_SIZE_CONTENT); /// 1 lv_obj_set_align(ui_statusPanelWifi, LV_ALIGN_CENTER); - lv_obj_add_flag(ui_statusPanelWifi, LV_OBJ_FLAG_ADV_HITTEST); /// Flags + lv_obj_add_flag(ui_statusPanelWifi, LV_OBJ_FLAG_ADV_HITTEST | LV_OBJ_FLAG_HIDDEN); /// Flags lv_obj_clear_flag(ui_statusPanelWifi, LV_OBJ_FLAG_SCROLLABLE); /// Flags ui_statusPanelBluetooth = lv_img_create(ui_statusPanelLeft); @@ -351,7 +362,7 @@ void ui_homeScreen_screen_init(void) lv_obj_set_width(ui_statusPanelBluetooth, LV_SIZE_CONTENT); /// 1 lv_obj_set_height(ui_statusPanelBluetooth, LV_SIZE_CONTENT); /// 1 lv_obj_set_align(ui_statusPanelBluetooth, LV_ALIGN_CENTER); - lv_obj_add_flag(ui_statusPanelBluetooth, LV_OBJ_FLAG_ADV_HITTEST); /// Flags + lv_obj_add_flag(ui_statusPanelBluetooth, LV_OBJ_FLAG_ADV_HITTEST | LV_OBJ_FLAG_HIDDEN); /// Flags lv_obj_clear_flag(ui_statusPanelBluetooth, LV_OBJ_FLAG_SCROLLABLE); /// Flags ui_statusPanelRight = lv_obj_create(ui_statusPanel); diff --git a/src/ui/screens/ui_settingsScreen.c b/src/ui/screens/ui_settingsScreen.c index 1f4e753..615726f 100644 --- a/src/ui/screens/ui_settingsScreen.c +++ b/src/ui/screens/ui_settingsScreen.c @@ -96,10 +96,30 @@ void ui_settingsScreen_screen_init(void) lv_obj_set_style_pad_top(ui_personalizationPanel, 10, LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_pad_bottom(ui_personalizationPanel, 50, LV_PART_MAIN | LV_STATE_DEFAULT); + ui_systemPanel = lv_obj_create(ui_settingsScreen); + lv_obj_set_width(ui_systemPanel, 320); + lv_obj_set_height(ui_systemPanel, 410); + lv_obj_set_x(ui_systemPanel, 0); + lv_obj_set_y(ui_systemPanel, 70); + lv_obj_set_align(ui_systemPanel, LV_ALIGN_TOP_MID); + lv_obj_set_flex_flow(ui_systemPanel, LV_FLEX_FLOW_COLUMN); + lv_obj_add_flag(ui_systemPanel, LV_OBJ_FLAG_ADV_HITTEST | LV_OBJ_FLAG_HIDDEN); /// Flags + lv_obj_set_flex_align(ui_systemPanel, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_START); + lv_obj_set_scrollbar_mode(ui_systemPanel, LV_SCROLLBAR_MODE_OFF); + lv_obj_set_scroll_dir(ui_systemPanel, LV_DIR_VER); + lv_obj_set_style_radius(ui_systemPanel, 0, LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_bg_color(ui_systemPanel, lv_color_hex(0x000000), LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_bg_opa(ui_systemPanel, 0, LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_border_width(ui_systemPanel, 0, LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_pad_left(ui_systemPanel, 20, LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_pad_right(ui_systemPanel, 20, LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_pad_top(ui_systemPanel, 10, LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_pad_bottom(ui_systemPanel, 50, LV_PART_MAIN | LV_STATE_DEFAULT); + ui_themePanel = lv_obj_create(ui_personalizationPanel); lv_obj_set_width(ui_themePanel, 225); - lv_obj_set_height(ui_themePanel, 280); + lv_obj_set_height(ui_themePanel, LV_SIZE_CONTENT); lv_obj_set_align(ui_themePanel, LV_ALIGN_CENTER); lv_obj_set_flex_flow(ui_themePanel, LV_FLEX_FLOW_ROW_WRAP); lv_obj_set_flex_align(ui_themePanel, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_START); @@ -118,7 +138,7 @@ void ui_settingsScreen_screen_init(void) ui_backgroundSelect = lv_obj_create(ui_personalizationPanel); lv_obj_set_width(ui_backgroundSelect, 280); - lv_obj_set_height(ui_backgroundSelect, 215); + lv_obj_set_height(ui_backgroundSelect, LV_SIZE_CONTENT); lv_obj_set_x(ui_backgroundSelect, 0); lv_obj_set_y(ui_backgroundSelect, 23); lv_obj_set_align(ui_backgroundSelect, LV_ALIGN_CENTER); @@ -138,7 +158,7 @@ void ui_settingsScreen_screen_init(void) ui_lockscreenSelect = lv_obj_create(ui_personalizationPanel); lv_obj_set_width(ui_lockscreenSelect, 280); - lv_obj_set_height(ui_lockscreenSelect, 215); + lv_obj_set_height(ui_lockscreenSelect, LV_SIZE_CONTENT); lv_obj_set_x(ui_lockscreenSelect, 0); lv_obj_set_y(ui_lockscreenSelect, 23); lv_obj_set_align(ui_lockscreenSelect, LV_ALIGN_CENTER); diff --git a/src/ui/screens/ui_starsScreen.c b/src/ui/screens/ui_starsScreen.c index 19a87b6..313001b 100644 --- a/src/ui/screens/ui_starsScreen.c +++ b/src/ui/screens/ui_starsScreen.c @@ -61,13 +61,13 @@ void ui_starsScreen_screen_init(void) lv_obj_set_style_pad_row(ui_starsMainPanel, 10, LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_pad_column(ui_starsMainPanel, 0, LV_PART_MAIN | LV_STATE_DEFAULT); - ui_Label23 = lv_label_create(ui_starsMainPanel); - lv_obj_set_width(ui_Label23, 280); - lv_obj_set_height(ui_Label23, LV_SIZE_CONTENT); /// 1 - lv_obj_set_align(ui_Label23, LV_ALIGN_CENTER); - lv_label_set_text(ui_Label23, + ui_starsInfo = lv_label_create(ui_starsMainPanel); + lv_obj_set_width(ui_starsInfo, 280); + lv_obj_set_height(ui_starsInfo, LV_SIZE_CONTENT); /// 1 + lv_obj_set_align(ui_starsInfo, LV_ALIGN_CENTER); + lv_label_set_text(ui_starsInfo, "The list below is generated before compilation from Github stars API using a pre-build script on PlatformIO IDE."); - lv_obj_set_style_text_font(ui_Label23, &lv_font_montserrat_14, LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_text_font(ui_starsInfo, &lv_font_montserrat_14, LV_PART_MAIN | LV_STATE_DEFAULT); ui_Label7 = lv_label_create(ui_starsMainPanel); lv_obj_set_width(ui_Label7, 280); diff --git a/src/ui/stars.h b/src/ui/stars.h index e7c5204..1d64501 100644 --- a/src/ui/stars.h +++ b/src/ui/stars.h @@ -10,16 +10,18 @@ extern "C" { #include "ui_common.h" -// TODO (add github avatars) default: ui_img_stars_ic_png +// TODO (add github avatars) default: NULL user_info_t users[] = { {"Bamamou", NULL}, - {"HanksJCTsai", NULL}, - {"WDC56", NULL}, {"betamoojw", NULL}, {"fbiego", NULL}, + {"HanksJCTsai", NULL}, {"hugo0406", NULL}, + {"MojzisekJan", NULL}, {"nccchirag", NULL}, {"the-this-pointer", NULL}, + {"TommyChou9567", NULL}, + {"WDC56", NULL}, }; diff --git a/src/ui/ui.c b/src/ui/ui.c index ef540c4..4c9c297 100644 --- a/src/ui/ui.c +++ b/src/ui/ui.c @@ -115,7 +115,7 @@ lv_obj_t *ui_Panel30; lv_obj_t *ui_Label38; lv_obj_t *ui_statusPanel; lv_obj_t *ui_statusPanelLeft; -lv_obj_t *ui_statusPanelCellular; +lv_obj_t *ui_statusCellularBar; lv_obj_t *ui_statusPanelWifi; lv_obj_t *ui_statusPanelBluetooth; void ui_event_statusPanelRight(lv_event_t *e); @@ -149,6 +149,7 @@ lv_obj_t *ui_settingsBack; lv_obj_t *ui_settingsAppIcon; lv_obj_t *ui_settingsAppTitle; lv_obj_t *ui_personalizationPanel; +lv_obj_t *ui_systemPanel; lv_obj_t *ui_themePanel; lv_obj_t *ui_backgroundSelect; lv_obj_t *ui_lockscreenSelect; @@ -162,7 +163,7 @@ lv_obj_t *ui_starsTitleName; lv_obj_t *ui_starsTitleIcon; lv_obj_t *ui_starsMainPanel; lv_obj_t *ui_stargazersPanel; -lv_obj_t *ui_Label23; +lv_obj_t *ui_starsInfo; lv_obj_t *ui_Label7; lv_obj_t *ui_Panel28; lv_obj_t *ui_userPanel; @@ -237,7 +238,11 @@ lv_obj_t *ui____initial_actions0; void init_custom(void); +#ifdef MIN_BG_IMG +const lv_img_dsc_t *ui_imgset_img[5] = {&ui_img_img1_png, &ui_img_img2_png, &ui_img_img5_png, &ui_img_img6_png, &ui_img_img8_png}; +#else const lv_img_dsc_t *ui_imgset_img[10] = {&ui_img_img0_png, &ui_img_img1_png, &ui_img_img2_png, &ui_img_img3_png, &ui_img_img4_png, &ui_img_img5_png, &ui_img_img6_png, &ui_img_img7_png, &ui_img_img8_png, &ui_img_img9_png}; +#endif app_info_t apps[] = { {0xAC00, "Camera", &ui_img_camera_ic_png}, @@ -284,6 +289,19 @@ settings_info_t settings[] = { {0xA708, "Privacy", "Location, camera, microphone", &ui_img_wp_privacy_png}, {0xA709, "About", "Serial, version, reset", &ui_img_wp_about_png}}; +quick_action actions[] = { + {0x00C1, "Airplane", &ui_img_airplane_ic_png, true}, + {0x00C2, "Cellular", &ui_img_cellular_ic_png, true}, + {0x00C3, "WiFi", &ui_img_wifi_ic_png, true}, + {0x00C4, "Bluetooth", &ui_img_bluetooth_ic_png, true}, + {0x00C5, "Brightness", &ui_img_brightness_ic_png, false}, + {0x00C6, "Battery", &ui_img_battery_ic_png, true}, + {0x00C7, "Hotspot", &ui_img_hotspot_ic_png, true}, + {0x00C8, "Settings", &ui_img_settings_ic_png, false}, + {0x00C9, "VPN", &ui_img_vpn_ic_png, true}, + {0x00CA, "Location", &ui_img_location_ic_png, true}, +}; + accent_color_t colors[] = { {"Lime", 0xA4C400}, {"Green", 0x60A917}, @@ -324,6 +342,12 @@ int current_txta = 0; bool tint_navbar = false; +lv_obj_t *bar; +lv_obj_t *bgSel; +lv_obj_t *startSl; +lv_obj_t *navSl; +lv_obj_t *navSw; + ///////////////////// TEST LVGL SETTINGS //////////////////// #if LV_COLOR_DEPTH != 16 #error "LV_COLOR_DEPTH should be 16bit to match SquareLine Studio's settings" @@ -798,19 +822,25 @@ void launch_settings(lv_event_t *e) { uint64_t code = (uint64_t)lv_event_get_user_data(e); + + lv_obj_add_flag(ui_personalizationPanel, LV_OBJ_FLAG_HIDDEN); + lv_obj_add_flag(ui_systemPanel, LV_OBJ_FLAG_HIDDEN); + lv_obj_add_flag(ui_settingsMainPanel, LV_OBJ_FLAG_HIDDEN); + switch (code) { - case 0xA700: /* code */ lv_obj_clear_flag(ui_settingsMainPanel, LV_OBJ_FLAG_HIDDEN); - lv_obj_add_flag(ui_personalizationPanel, LV_OBJ_FLAG_HIDDEN); + break; + case 0xA701: + lv_obj_clear_flag(ui_systemPanel, LV_OBJ_FLAG_HIDDEN); break; case 0xA704: lv_obj_clear_flag(ui_personalizationPanel, LV_OBJ_FLAG_HIDDEN); - lv_obj_add_flag(ui_settingsMainPanel, LV_OBJ_FLAG_HIDDEN); break; default: + lv_obj_clear_flag(ui_settingsMainPanel, LV_OBJ_FLAG_HIDDEN); show_alert("Settings error", "This setting is not available at the moment"); return; break; @@ -837,10 +867,49 @@ void launch_settings(lv_event_t *e) } } +void action_event(lv_event_t *e) +{ + uint64_t code = (uint64_t)lv_event_get_user_data(e); + lv_event_code_t event_code = lv_event_get_code(e); + lv_obj_t *target = lv_event_get_target(e); + + switch (code) + { + case 0x00C3: + // wifi + if (lv_obj_has_state(target, LV_STATE_CHECKED)){ + lv_obj_add_flag(ui_statusPanelWifi, LV_OBJ_FLAG_HIDDEN); + } else { + lv_obj_clear_flag(ui_statusPanelWifi, LV_OBJ_FLAG_HIDDEN); + } + break; + case 0x00C4: + // bt + if (lv_obj_has_state(target, LV_STATE_CHECKED)){ + lv_obj_add_flag(ui_statusPanelBluetooth, LV_OBJ_FLAG_HIDDEN); + } else { + lv_obj_clear_flag(ui_statusPanelBluetooth, LV_OBJ_FLAG_HIDDEN); + } + break; + case 0x00C8: + // settings + closeNotificationPanel_Animation(ui_notificationPanel, 0); + lv_obj_clear_state(ui_notificationPanel, LV_STATE_CHECKED); + _ui_screen_change(&ui_settingsScreen, LV_SCR_LOAD_ANIM_FADE_ON, 500, 0, &ui_settingsScreen_screen_init); + break; + + default: + break; + } + +} + void theme_change(lv_event_t *e) { uint32_t color = (uint32_t)((uint64_t)lv_event_get_user_data(e)); + setPrefInt("theme_color", color); + lv_disp_t *display = lv_disp_get_default(); lv_theme_t *theme = lv_theme_default_init(display, lv_color_hex(color), lv_palette_main(LV_PALETTE_GREY), true, LV_FONT_DEFAULT); lv_disp_set_theme(display, theme); @@ -881,6 +950,8 @@ void start_opacity(lv_event_t *e) int32_t value = lv_slider_get_value(target); int32_t max = lv_slider_get_max_value(target); + setPrefInt("start_opa", value); + for (int i = 0; i < current_start; i++) { lv_obj_set_style_bg_opa(start[i], max - value, LV_PART_MAIN | LV_STATE_DEFAULT); @@ -893,7 +964,7 @@ void navbar_opacity(lv_event_t *e) int32_t value = lv_slider_get_value(target); int32_t max = lv_slider_get_max_value(target); int32_t min = lv_slider_get_min_value(target); - + setPrefInt("nav_opa", value); lv_obj_set_style_bg_opa(ui_navPanel, max - value + min, LV_PART_MAIN | LV_STATE_DEFAULT); } @@ -901,6 +972,7 @@ void navbar_tint(lv_event_t *e) { lv_obj_t *target = lv_event_get_target(e); tint_navbar = lv_obj_has_state(target, LV_STATE_CHECKED); + setPrefBool("nav_tint", tint_navbar); if (tint_navbar) { @@ -915,13 +987,15 @@ void navbar_tint(lv_event_t *e) void background_img(lv_event_t *e) { uint64_t code = (uint64_t)lv_event_get_user_data(e); - lv_obj_set_style_bg_img_src(ui_homeScreen, ui_imgset_img[code % 10], LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_bg_img_src(ui_homeScreen, ui_imgset_img[code % (sizeof(ui_imgset_img) / sizeof(ui_imgset_img[0]))], LV_PART_MAIN | LV_STATE_DEFAULT); + setPrefInt("bg_img", code); } void lockscreen_img(lv_event_t *e) { uint64_t code = (uint64_t)lv_event_get_user_data(e); - lv_obj_set_style_bg_img_src(ui_lockScreenPanel, ui_imgset_img[code % 10], LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_bg_img_src(ui_lockScreenPanel, ui_imgset_img[code % (sizeof(ui_imgset_img) / sizeof(ui_imgset_img[0]))], LV_PART_MAIN | LV_STATE_DEFAULT); + setPrefInt("lock_img", code); } void background_select(lv_event_t *e) @@ -929,6 +1003,8 @@ void background_select(lv_event_t *e) lv_obj_t *target = lv_event_get_target(e); uint16_t selected = lv_dropdown_get_selected(target); + setPrefInt("bg_type", selected); + if (selected == 0) { lv_obj_add_flag(ui_backgroundSelect, LV_OBJ_FLAG_HIDDEN); @@ -937,10 +1013,36 @@ void background_select(lv_event_t *e) else { lv_obj_clear_flag(ui_backgroundSelect, LV_OBJ_FLAG_HIDDEN); - lv_obj_set_style_bg_img_src(ui_homeScreen, ui_imgset_img[5], LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_bg_img_src(ui_homeScreen, ui_imgset_img[getPrefInt("bg_img", 5) % (sizeof(ui_imgset_img) / sizeof(ui_imgset_img[0]))], LV_PART_MAIN | LV_STATE_DEFAULT); } } +void slider_val(lv_event_t *e) +{ + lv_obj_t *target = lv_event_get_target(e); + int32_t value = lv_slider_get_value(target); + + cm_set_bar(bar, value, "%d%% Slider"); + +} + +void brightness_slider(lv_event_t *e) +{ + lv_obj_t *target = lv_event_get_target(e); + int32_t value = lv_slider_get_value(target); + + onBrightnessChange(value); + +} + +void timeout_select(lv_event_t *e) +{ + lv_obj_t *target = lv_event_get_target(e); + uint16_t selected = lv_dropdown_get_selected(target); + + onTimeoutChange(selected); +} + ///////////////////// FUNCTIONS //////////////////// void ui_event_cortanaPanel(lv_event_t *e) { @@ -1119,6 +1221,7 @@ void ui_event_notificationPanel(lv_event_t *e) { lv_indev_wait_release(lv_indev_get_act()); closeNotificationPanel_Animation(ui_notificationPanel, 0); + lv_obj_clear_state(ui_notificationPanel, LV_STATE_CHECKED); } } @@ -1128,7 +1231,10 @@ void ui_event_statusPanelRight(lv_event_t *e) lv_obj_t *target = lv_event_get_target(e); if (event_code == LV_EVENT_CLICKED) { - openNotificationPanel_Animation(ui_notificationPanel, 0); + if (!lv_obj_has_state(ui_notificationPanel, LV_STATE_CHECKED)){ + openNotificationPanel_Animation(ui_notificationPanel, 0); + lv_obj_add_state(ui_notificationPanel, LV_STATE_CHECKED); + } } } @@ -1241,54 +1347,58 @@ void init_custom(void) } // quick actions - cm_quick_action(ui_quickActionPanel, "Airplane", &ui_img_airplane_ic_png, true); - cm_quick_action(ui_quickActionPanel, "Cellular", &ui_img_cellular_ic_png, true); - cm_quick_action(ui_quickActionPanel, "WiFi", &ui_img_wifi_ic_png, true); - cm_quick_action(ui_quickActionPanel, "Bluetooth", &ui_img_bluetooth_ic_png, true); - cm_quick_action(ui_quickActionPanel, "Brightness", &ui_img_brightness_ic_png, false); - cm_quick_action(ui_quickActionPanel, "Battery", &ui_img_battery_ic_png, true); - cm_quick_action(ui_quickActionPanel, "Hotspot", &ui_img_hotspot_ic_png, true); - cm_quick_action(ui_quickActionPanel, "Settings", &ui_img_settings_ic_png, false); - cm_quick_action(ui_quickActionPanel, "VPN", &ui_img_vpn_ic_png, true); - cm_quick_action(ui_quickActionPanel, "Location", &ui_img_location_ic_png, true); + for (int a = 0; a < (sizeof(actions) / sizeof(actions[0])); a++) + { + cm_quick_action(ui_quickActionPanel, actions[a], action_event); + } // settings main - cm_text_area(ui_settingsMainPanel, "Find a setting", register_txta); + cm_create_text_area(ui_settingsMainPanel, "Find a setting", register_txta); for (int a = 0; a < (sizeof(settings) / sizeof(settings[0])); a++) { cm_settings_list(ui_settingsMainPanel, settings[a], launch_settings, register_img); } lv_obj_add_event_cb(ui_settingsBack, launch_settings, LV_EVENT_CLICKED, (void *)0xA700); + // settings system + cm_create_panel_space(ui_systemPanel, 10); + cm_create_title(ui_systemPanel, "Display"); + cm_create_text(ui_systemPanel, "Brightness"); + cm_create_panel_space(ui_systemPanel, 5); + cm_create_slider(ui_systemPanel, 200, 1, 255, brightness_slider); + cm_create_panel_space(ui_systemPanel, 10); + cm_create_text(ui_systemPanel, "Timeout"); + cm_create_dropdown(ui_systemPanel, "5 Seconds\n10 Seconds\n20 Seconds\n30 Seconds\nAlways On", 1, 150, timeout_select); + // settings personalization - cm_panel_space(ui_personalizationPanel); - cm_text(ui_personalizationPanel, "Accent Color"); + cm_create_panel_space(ui_personalizationPanel, 10); + cm_create_text(ui_personalizationPanel, "Accent Color"); lv_obj_set_parent(ui_themePanel, ui_personalizationPanel); for (int a = 0; a < (sizeof(colors) / sizeof(colors[0])); a++) { cm_accent_color(ui_themePanel, colors[a], theme_change); } - cm_panel_space(ui_personalizationPanel); - cm_text(ui_personalizationPanel, "Tile Opacity"); - cm_panel_space(ui_personalizationPanel); - cm_slider(ui_personalizationPanel, 200, 0, 255, start_opacity); - cm_panel_space(ui_personalizationPanel); - cm_text(ui_personalizationPanel, "Background"); - cm_dropdown(ui_personalizationPanel, "None\nPicture", 1, 150, background_select); + cm_create_panel_space(ui_personalizationPanel, 10); + cm_create_text(ui_personalizationPanel, "Tile Opacity"); + cm_create_panel_space(ui_personalizationPanel, 5); + startSl = cm_create_slider(ui_personalizationPanel, getPrefInt("start_opa", 200), 0, 255, start_opacity); + cm_create_panel_space(ui_personalizationPanel, 10); + cm_create_text(ui_personalizationPanel, "Background"); + bgSel = cm_create_dropdown(ui_personalizationPanel, "None\nPicture", getPrefInt("bg_type", 1), 150, background_select); lv_obj_set_parent(ui_backgroundSelect, ui_personalizationPanel); for (int a = 0; a < (sizeof(ui_imgset_img) / sizeof(ui_imgset_img[0])); a++) { cm_image_select(ui_backgroundSelect, ui_imgset_img[a], a, background_img); } - cm_panel_space(ui_personalizationPanel); - cm_text(ui_personalizationPanel, "NavBar Opacity"); - cm_panel_space(ui_personalizationPanel); - cm_slider(ui_personalizationPanel, 200, 20, 255, navbar_opacity); - cm_panel_space(ui_personalizationPanel); - cm_switch(ui_personalizationPanel, "Navbar accent color", false, navbar_tint); - cm_panel_space(ui_personalizationPanel); - - cm_text(ui_personalizationPanel, "Lockscreen"); + cm_create_panel_space(ui_personalizationPanel, 10); + cm_create_text(ui_personalizationPanel, "NavBar Opacity"); + cm_create_panel_space(ui_personalizationPanel, 5); + navSl = cm_create_slider(ui_personalizationPanel, getPrefInt("nav_opa", 200), 20, 255, navbar_opacity); + cm_create_panel_space(ui_personalizationPanel, 10); + navSw = cm_create_switch(ui_personalizationPanel, "Navbar accent color", getPrefBool("nav_tint", false), navbar_tint); + cm_create_panel_space(ui_personalizationPanel, 10); + + cm_create_text(ui_personalizationPanel, "Lockscreen"); lv_obj_set_parent(ui_lockscreenSelect, ui_personalizationPanel); for (int a = 0; a < (sizeof(ui_imgset_img) / sizeof(ui_imgset_img[0])); a++) { @@ -1311,4 +1421,45 @@ void init_custom(void) register_img(ui_appTitleIcon); register_panel(ui_Panel30); register_txta(ui_alertDialogPanel); + + bar = cm_create_bar(ui_appMainPanel, 25, "%d%% Percent"); + cm_create_panel_space(ui_appMainPanel, 10); + cm_create_slider(ui_appMainPanel, 0, 0, 100, slider_val); + + + + // Load saved preferences + + lv_obj_set_style_bg_img_src(ui_homeScreen, ui_imgset_img[getPrefInt("bg_img", 5) % (sizeof(ui_imgset_img) / sizeof(ui_imgset_img[0]))], LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_bg_img_src(ui_lockScreenPanel, ui_imgset_img[getPrefInt("lock_img", 2) % (sizeof(ui_imgset_img) / sizeof(ui_imgset_img[0]))], LV_PART_MAIN | LV_STATE_DEFAULT); + + + lv_event_t e; + e.user_data = (void*)(uint64_t)getPrefInt("theme_color", 0x0050EF); + theme_change(&e); + + e.target = navSl; + e.user_data = (void*)(uint64_t)getPrefInt("nav_opa", 200); + navbar_opacity(&e); + + e.target = startSl; + e.user_data = (void*)(uint64_t)getPrefInt("start_opa", 200); + start_opacity(&e); + + lv_dropdown_set_selected(bgSel, getPrefInt("bg_type", 1)); + e.target = bgSel; + background_select(&e); + + if (getPrefBool("nav_tint", false)){ + lv_obj_add_state(navSw, LV_STATE_CHECKED); + } else { + lv_obj_clear_state(navSw, LV_STATE_CHECKED); + } + e.target = navSw; + navbar_tint(&e); + + // e.user_data = (void*)(uint64_t)getPrefInt("start_opa", 200); + // start_opacity(&e); + + } diff --git a/src/ui/ui.h b/src/ui/ui.h index b76959c..cac07ce 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -118,7 +118,7 @@ extern lv_obj_t *ui_Panel30; extern lv_obj_t *ui_Label38; extern lv_obj_t *ui_statusPanel; extern lv_obj_t *ui_statusPanelLeft; -extern lv_obj_t *ui_statusPanelCellular; +extern lv_obj_t *ui_statusCellularBar; extern lv_obj_t *ui_statusPanelWifi; extern lv_obj_t *ui_statusPanelBluetooth; void ui_event_statusPanelRight(lv_event_t *e); @@ -151,6 +151,7 @@ extern lv_obj_t *ui_settingsBack; extern lv_obj_t *ui_settingsAppIcon; extern lv_obj_t *ui_settingsAppTitle; extern lv_obj_t *ui_personalizationPanel; +extern lv_obj_t *ui_systemPanel; extern lv_obj_t *ui_themePanel; extern lv_obj_t *ui_backgroundSelect; extern lv_obj_t *ui_lockscreenSelect; @@ -223,7 +224,7 @@ extern lv_obj_t *ui_starsTitleName; extern lv_obj_t *ui_starsTitleIcon; extern lv_obj_t *ui_starsMainPanel; extern lv_obj_t *ui_stargazersPanel; -extern lv_obj_t *ui_Label23; +extern lv_obj_t *ui_starsInfo; extern lv_obj_t *ui_Label7; extern lv_obj_t *ui_Panel28; extern lv_obj_t *ui_userPanel; @@ -239,6 +240,15 @@ void ui_event_nav_search(lv_event_t *e); void show_alert(const char *title, const char *text); +void setPrefBool(const char *key, bool value); +void setPrefInt(const char *key, uint32_t value); + +uint32_t getPrefInt(const char *key, uint32_t def); +bool getPrefBool(const char *key, bool def); + +void onBrightnessChange(int32_t value); +void onTimeoutChange(int16_t selected); + void ui_event____initial_actions0(lv_event_t *e); extern lv_obj_t *ui____initial_actions0; diff --git a/src/ui/ui_common.c b/src/ui/ui_common.c index 60946b3..64a042f 100644 --- a/src/ui/ui_common.c +++ b/src/ui/ui_common.c @@ -2,7 +2,7 @@ #include "ui_common.h" -void cm_text(lv_obj_t *parent, const char *text) +lv_obj_t *cm_create_text(lv_obj_t *parent, const char *text) { lv_obj_t *ui_cm_label = lv_label_create(parent); lv_obj_set_width(ui_cm_label, 280); @@ -10,9 +10,11 @@ void cm_text(lv_obj_t *parent, const char *text) lv_obj_set_align(ui_cm_label, LV_ALIGN_CENTER); lv_label_set_text(ui_cm_label, text); lv_obj_set_style_text_font(ui_cm_label, &lv_font_montserrat_14, LV_PART_MAIN | LV_STATE_DEFAULT); + + return ui_cm_label; } -void cm_switch(lv_obj_t *parent, const char* text, bool active, void (*callback)(lv_event_t *e)) +lv_obj_t *cm_create_switch(lv_obj_t *parent, const char *text, bool active, void (*callback)(lv_event_t *e)) { lv_obj_t *ui_cm_panel = lv_obj_create(parent); lv_obj_set_width(ui_cm_panel, 280); @@ -34,7 +36,8 @@ void cm_switch(lv_obj_t *parent, const char* text, bool active, void (*callback) lv_obj_set_width(ui_cm_switch, 50); lv_obj_set_height(ui_cm_switch, 25); lv_obj_set_align(ui_cm_switch, LV_ALIGN_CENTER); - if (active){ + if (active) + { lv_obj_add_state(ui_cm_switch, LV_STATE_CHECKED); } lv_obj_set_style_bg_color(ui_cm_switch, lv_color_hex(0xFFFFFF), LV_PART_MAIN | LV_STATE_DEFAULT); @@ -55,9 +58,10 @@ void cm_switch(lv_obj_t *parent, const char* text, bool active, void (*callback) lv_obj_add_event_cb(ui_cm_switch, callback, LV_EVENT_VALUE_CHANGED, NULL); + return ui_cm_switch; } -void cm_button(lv_obj_t *parent, const char *text) +lv_obj_t *cm_create_button(lv_obj_t *parent, const char *text) { lv_obj_t *ui_cm_button = lv_btn_create(parent); lv_obj_set_width(ui_cm_button, LV_SIZE_CONTENT); /// 100 @@ -79,9 +83,11 @@ void cm_button(lv_obj_t *parent, const char *text) lv_obj_set_align(ui_cm_label, LV_ALIGN_CENTER); lv_label_set_text(ui_cm_label, text); lv_obj_set_style_text_font(ui_cm_label, &lv_font_montserrat_12, LV_PART_MAIN | LV_STATE_DEFAULT); + + return ui_cm_button; } -void cm_title(lv_obj_t *parent, const char *text) +lv_obj_t *cm_create_title(lv_obj_t *parent, const char *text) { lv_obj_t *ui_cm_label = lv_label_create(parent); lv_obj_set_width(ui_cm_label, 280); @@ -89,9 +95,11 @@ void cm_title(lv_obj_t *parent, const char *text) lv_obj_set_align(ui_cm_label, LV_ALIGN_CENTER); lv_label_set_text(ui_cm_label, text); lv_obj_set_style_text_font(ui_cm_label, &lv_font_montserrat_20, LV_PART_MAIN | LV_STATE_DEFAULT); + + return ui_cm_label; } -void cm_text_area(lv_obj_t *parent, const char *placeholder, void (*color)(lv_obj_t *obj)) +lv_obj_t *cm_create_text_area(lv_obj_t *parent, const char *placeholder, void (*color)(lv_obj_t *obj)) { lv_obj_t *ui_cm_text_area = lv_textarea_create(parent); lv_obj_set_width(ui_cm_text_area, 300); @@ -108,9 +116,10 @@ void cm_text_area(lv_obj_t *parent, const char *placeholder, void (*color)(lv_ob color(ui_cm_text_area); + return ui_cm_text_area; } -void cm_slider(lv_obj_t *parent, int value, int min, int max, void (*callback)(lv_event_t *e)) +lv_obj_t *cm_create_slider(lv_obj_t *parent, int value, int min, int max, void (*callback)(lv_event_t *e)) { lv_obj_t *ui_cm_slider = lv_slider_create(parent); lv_slider_set_range(ui_cm_slider, min, max); @@ -125,13 +134,14 @@ void cm_slider(lv_obj_t *parent, int value, int min, int max, void (*callback)(l lv_obj_add_event_cb(ui_cm_slider, callback, LV_EVENT_VALUE_CHANGED, NULL); + return ui_cm_slider; } -void cm_panel_space(lv_obj_t *parent) +lv_obj_t *cm_create_panel_space(lv_obj_t *parent, int height) { lv_obj_t *ui_cm_panel = lv_obj_create(parent); lv_obj_set_width(ui_cm_panel, 280); - lv_obj_set_height(ui_cm_panel, 10); + lv_obj_set_height(ui_cm_panel, height); lv_obj_set_align(ui_cm_panel, LV_ALIGN_CENTER); lv_obj_set_flex_flow(ui_cm_panel, LV_FLEX_FLOW_ROW); lv_obj_set_flex_align(ui_cm_panel, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_START); @@ -144,9 +154,11 @@ void cm_panel_space(lv_obj_t *parent) lv_obj_set_style_pad_right(ui_cm_panel, 0, LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_pad_top(ui_cm_panel, 0, LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_pad_bottom(ui_cm_panel, 0, LV_PART_MAIN | LV_STATE_DEFAULT); + + return ui_cm_panel; } -void cm_bar(lv_obj_t *parent, int value) +lv_obj_t *cm_create_bar(lv_obj_t *parent, int value, const char *format) { lv_obj_t *ui_cm_panel = lv_obj_create(parent); lv_obj_set_width(ui_cm_panel, 280); @@ -168,8 +180,8 @@ void cm_bar(lv_obj_t *parent, int value) lv_obj_set_width(ui_label, LV_SIZE_CONTENT); /// 1 lv_obj_set_height(ui_label, LV_SIZE_CONTENT); /// 1 lv_obj_set_align(ui_label, LV_ALIGN_CENTER); - lv_label_set_text_fmt(ui_label, "%d%%", value); - lv_obj_set_style_text_font(ui_label, &lv_font_montserrat_20, LV_PART_MAIN | LV_STATE_DEFAULT); + lv_label_set_text_fmt(ui_label, format, value); + lv_obj_set_style_text_font(ui_label, &lv_font_montserrat_14, LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_pad_left(ui_label, 0, LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_pad_right(ui_label, 0, LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_pad_top(ui_label, 0, LV_PART_MAIN | LV_STATE_DEFAULT); @@ -185,17 +197,28 @@ void cm_bar(lv_obj_t *parent, int value) lv_obj_set_style_bg_color(ui_bar, lv_color_hex(0x3F3F3F), LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_bg_opa(ui_bar, 255, LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_radius(ui_bar, 0, LV_PART_INDICATOR | LV_STATE_DEFAULT); + + return ui_cm_panel; } -void cm_dropdown(lv_obj_t *parent, const char* options, int selected, int width, void (*callback)(lv_event_t *e)) +void cm_set_bar(lv_obj_t *obj, int value, const char *format) +{ + uint32_t ch = lv_obj_get_child_cnt(obj); + lv_obj_t *t = lv_obj_get_child(obj, 0); + lv_obj_t *b = lv_obj_get_child(obj, 1); + lv_bar_set_value(b, value, LV_ANIM_OFF); + lv_label_set_text_fmt(t, format, value); +} + +lv_obj_t *cm_create_dropdown(lv_obj_t *parent, const char *options, int selected, int width, void (*callback)(lv_event_t *e)) { lv_obj_t *ui_cm_dropdown = lv_dropdown_create(parent); lv_dropdown_set_options(ui_cm_dropdown, options); lv_dropdown_set_selected(ui_cm_dropdown, selected); lv_obj_set_width(ui_cm_dropdown, width); - lv_obj_set_height(ui_cm_dropdown, LV_SIZE_CONTENT); /// 1 + lv_obj_set_height(ui_cm_dropdown, LV_SIZE_CONTENT); /// 1 lv_obj_set_align(ui_cm_dropdown, LV_ALIGN_CENTER); - lv_obj_add_flag(ui_cm_dropdown, LV_OBJ_FLAG_SCROLL_ON_FOCUS); /// Flags + lv_obj_add_flag(ui_cm_dropdown, LV_OBJ_FLAG_SCROLL_ON_FOCUS); /// Flags lv_obj_set_style_radius(ui_cm_dropdown, 0, LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_bg_color(ui_cm_dropdown, lv_color_hex(0xFFFFFF), LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_bg_opa(ui_cm_dropdown, 0, LV_PART_MAIN | LV_STATE_DEFAULT); @@ -203,22 +226,23 @@ void cm_dropdown(lv_obj_t *parent, const char* options, int selected, int width, lv_obj_set_style_border_opa(ui_cm_dropdown, 255, LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_border_width(ui_cm_dropdown, 1, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_radius(lv_dropdown_get_list(ui_cm_dropdown), 0, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_bg_color(lv_dropdown_get_list(ui_cm_dropdown), lv_color_hex(0x000000), LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_bg_opa(lv_dropdown_get_list(ui_cm_dropdown), 255, LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_radius(lv_dropdown_get_list(ui_cm_dropdown), 0, LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_bg_color(lv_dropdown_get_list(ui_cm_dropdown), lv_color_hex(0x000000), LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_bg_opa(lv_dropdown_get_list(ui_cm_dropdown), 255, LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_add_event_cb(ui_cm_dropdown, callback, LV_EVENT_VALUE_CHANGED, NULL); -} + return ui_cm_dropdown; +} void cm_user_list(lv_obj_t *parent, user_info_t user) { lv_obj_t *ui_cm_user = lv_label_create(parent); - lv_obj_set_width(ui_cm_user, LV_SIZE_CONTENT); /// 1 - lv_obj_set_height(ui_cm_user, LV_SIZE_CONTENT); /// 1 + lv_obj_set_width(ui_cm_user, LV_SIZE_CONTENT); /// 1 + lv_obj_set_height(ui_cm_user, LV_SIZE_CONTENT); /// 1 lv_obj_set_align(ui_cm_user, LV_ALIGN_CENTER); lv_label_set_text(ui_cm_user, user.username); - lv_obj_add_flag(ui_cm_user, LV_OBJ_FLAG_CLICKABLE); /// Flags + lv_obj_add_flag(ui_cm_user, LV_OBJ_FLAG_CLICKABLE); /// Flags lv_obj_set_style_text_font(ui_cm_user, &lv_font_montserrat_14, LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_radius(ui_cm_user, 10, LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_border_color(ui_cm_user, lv_color_hex(0xFFFFFF), LV_PART_MAIN | LV_STATE_DEFAULT); @@ -230,10 +254,9 @@ void cm_user_list(lv_obj_t *parent, user_info_t user) lv_obj_set_style_pad_bottom(ui_cm_user, 2, LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_bg_color(ui_cm_user, lv_color_hex(0xFFFFFF), LV_PART_MAIN | LV_STATE_PRESSED); lv_obj_set_style_bg_opa(ui_cm_user, 150, LV_PART_MAIN | LV_STATE_PRESSED); - } -void cm_quick_action(lv_obj_t *parent, const char* name, const lv_img_dsc_t *icon, bool checkable) +void cm_quick_action(lv_obj_t *parent, quick_action action, void (*callback)(lv_event_t *e)) { lv_obj_t *ui_cm_button = lv_btn_create(parent); lv_obj_set_width(ui_cm_button, 58); @@ -243,12 +266,13 @@ void cm_quick_action(lv_obj_t *parent, const char* name, const lv_img_dsc_t *ico lv_obj_set_align(ui_cm_button, LV_ALIGN_CENTER); lv_obj_set_flex_flow(ui_cm_button, LV_FLEX_FLOW_COLUMN); lv_obj_set_flex_align(ui_cm_button, LV_FLEX_ALIGN_SPACE_AROUND, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_START); - lv_obj_add_flag(ui_cm_button, LV_OBJ_FLAG_SCROLL_ON_FOCUS); /// Flags - if (checkable){ - lv_obj_add_flag(ui_cm_button, LV_OBJ_FLAG_CHECKABLE ); /// Flags - lv_obj_add_state(ui_cm_button, LV_STATE_CHECKED); + lv_obj_add_flag(ui_cm_button, LV_OBJ_FLAG_SCROLL_ON_FOCUS); /// Flags + if (action.checkable) + { + lv_obj_add_flag(ui_cm_button, LV_OBJ_FLAG_CHECKABLE); /// Flags } - lv_obj_clear_flag(ui_cm_button, LV_OBJ_FLAG_SCROLLABLE); /// Flags + lv_obj_add_state(ui_cm_button, LV_STATE_CHECKED); + lv_obj_clear_flag(ui_cm_button, LV_OBJ_FLAG_SCROLLABLE); /// Flags lv_obj_set_style_radius(ui_cm_button, 0, LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_border_width(ui_cm_button, 0, LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_pad_left(ui_cm_button, 5, LV_PART_MAIN | LV_STATE_DEFAULT); @@ -261,22 +285,24 @@ void cm_quick_action(lv_obj_t *parent, const char* name, const lv_img_dsc_t *ico lv_obj_set_style_border_width(ui_cm_button, 0, LV_PART_MAIN | LV_STATE_CHECKED); lv_obj_t *ui_cm_image = lv_img_create(ui_cm_button); - lv_img_set_src(ui_cm_image, icon); - lv_obj_set_width(ui_cm_image, LV_SIZE_CONTENT); /// 1 - lv_obj_set_height(ui_cm_image, LV_SIZE_CONTENT); /// 1 + lv_img_set_src(ui_cm_image, action.icon); + lv_obj_set_width(ui_cm_image, LV_SIZE_CONTENT); /// 1 + lv_obj_set_height(ui_cm_image, LV_SIZE_CONTENT); /// 1 lv_obj_set_align(ui_cm_image, LV_ALIGN_CENTER); - lv_obj_add_flag(ui_cm_image, LV_OBJ_FLAG_ADV_HITTEST); /// Flags - lv_obj_clear_flag(ui_cm_image, LV_OBJ_FLAG_SCROLLABLE); /// Flags + lv_obj_add_flag(ui_cm_image, LV_OBJ_FLAG_ADV_HITTEST); /// Flags + lv_obj_clear_flag(ui_cm_image, LV_OBJ_FLAG_SCROLLABLE); /// Flags lv_obj_t *ui_Label30 = lv_label_create(ui_cm_button); - lv_obj_set_width(ui_Label30, LV_SIZE_CONTENT); /// 1 - lv_obj_set_height(ui_Label30, LV_SIZE_CONTENT); /// 1 + lv_obj_set_width(ui_Label30, LV_SIZE_CONTENT); /// 1 + lv_obj_set_height(ui_Label30, LV_SIZE_CONTENT); /// 1 lv_obj_set_align(ui_Label30, LV_ALIGN_CENTER); - lv_label_set_text(ui_Label30, name); + lv_label_set_text(ui_Label30, action.name); lv_obj_set_style_text_font(ui_Label30, &lv_font_montserrat_10, LV_PART_MAIN | LV_STATE_DEFAULT); + + lv_obj_add_event_cb(ui_cm_button, callback, action.checkable ? LV_EVENT_VALUE_CHANGED : LV_EVENT_CLICKED, (void *)action.code); } -void cm_start_tile(start_tile_t tile, void(*callback)(live_obj_t l), void(*launcher)(lv_event_t *e), void(*start)(lv_obj_t *obj)) +void cm_start_tile(start_tile_t tile, void (*callback)(live_obj_t l), void (*launcher)(lv_event_t *e), void (*start)(lv_obj_t *obj)) { lv_obj_t *ui_cm_panel = lv_obj_create(ui_startPanel); lv_obj_set_width(ui_cm_panel, tile.wide ? 205 : 100); @@ -322,12 +348,10 @@ void cm_start_tile(start_tile_t tile, void(*callback)(live_obj_t l), void(*launc start(ui_cm_panel); - lv_obj_add_event_cb(ui_cm_panel, launcher, LV_EVENT_CLICKED, (void*)tile.app.code); - - + lv_obj_add_event_cb(ui_cm_panel, launcher, LV_EVENT_CLICKED, (void *)tile.app.code); } -void cm_app_list(app_info_t app, void (*launcher)(lv_event_t * e), void(*panel)(lv_obj_t *obj)) +void cm_app_list(app_info_t app, void (*launcher)(lv_event_t *e), void (*panel)(lv_obj_t *obj)) { lv_obj_t *ui_cm_panel = lv_obj_create(ui_appsListPanel); lv_obj_set_width(ui_cm_panel, 320); @@ -361,11 +385,10 @@ void cm_app_list(app_info_t app, void (*launcher)(lv_event_t * e), void(*panel)( panel(ui_cm_panel_icon); - lv_obj_add_event_cb(ui_cm_panel, launcher, LV_EVENT_CLICKED, (void*)app.code); - + lv_obj_add_event_cb(ui_cm_panel, launcher, LV_EVENT_CLICKED, (void *)app.code); } -void cm_settings_list(lv_obj_t *parent, settings_info_t setting, void (*launcher)(lv_event_t * e), void(*img)(lv_obj_t *obj)) +void cm_settings_list(lv_obj_t *parent, settings_info_t setting, void (*launcher)(lv_event_t *e), void (*img)(lv_obj_t *obj)) { lv_obj_t *ui_cm_panel = lv_obj_create(parent); lv_obj_set_width(ui_cm_panel, 320); @@ -409,7 +432,7 @@ void cm_settings_list(lv_obj_t *parent, settings_info_t setting, void (*launcher img(ui_cm_icon); - lv_obj_add_event_cb(ui_cm_panel, launcher, LV_EVENT_CLICKED, (void*)setting.code); + lv_obj_add_event_cb(ui_cm_panel, launcher, LV_EVENT_CLICKED, (void *)setting.code); } void cm_accent_color(lv_obj_t *parent, accent_color_t color, void (*callback)(lv_event_t *e)) @@ -418,7 +441,7 @@ void cm_accent_color(lv_obj_t *parent, accent_color_t color, void (*callback)(lv lv_obj_set_width(ui_cm_color, 50); lv_obj_set_height(ui_cm_color, 50); lv_obj_set_align(ui_cm_color, LV_ALIGN_CENTER); - lv_obj_clear_flag(ui_cm_color, LV_OBJ_FLAG_SCROLLABLE); /// Flags + lv_obj_clear_flag(ui_cm_color, LV_OBJ_FLAG_SCROLLABLE); /// Flags lv_obj_set_style_radius(ui_cm_color, 0, LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_bg_color(ui_cm_color, lv_color_hex(color.color), LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_bg_opa(ui_cm_color, 255, LV_PART_MAIN | LV_STATE_DEFAULT); @@ -429,7 +452,7 @@ void cm_accent_color(lv_obj_t *parent, accent_color_t color, void (*callback)(lv lv_obj_set_style_outline_width(ui_cm_color, 5, LV_PART_MAIN | LV_STATE_PRESSED); lv_obj_set_style_outline_pad(ui_cm_color, 0, LV_PART_MAIN | LV_STATE_PRESSED); - lv_obj_add_event_cb(ui_cm_color, callback, LV_EVENT_CLICKED, (void*)(uint64_t)color.color); + lv_obj_add_event_cb(ui_cm_color, callback, LV_EVENT_CLICKED, (void *)(uint64_t)color.color); } void cm_image_select(lv_obj_t *parent, const lv_img_dsc_t *img, uint64_t index, void (*callback)(lv_event_t *e)) @@ -440,7 +463,7 @@ void cm_image_select(lv_obj_t *parent, const lv_img_dsc_t *img, uint64_t index, lv_obj_set_x(ui_cm_panel, 0); lv_obj_set_y(ui_cm_panel, 32); lv_obj_set_align(ui_cm_panel, LV_ALIGN_CENTER); - lv_obj_clear_flag(ui_cm_panel, LV_OBJ_FLAG_SCROLLABLE); /// Flags + lv_obj_clear_flag(ui_cm_panel, LV_OBJ_FLAG_SCROLLABLE); /// Flags lv_obj_set_style_radius(ui_cm_panel, 0, LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_bg_color(ui_cm_panel, lv_color_hex(0xFFFFFF), LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_bg_opa(ui_cm_panel, 255, LV_PART_MAIN | LV_STATE_DEFAULT); @@ -453,14 +476,14 @@ void cm_image_select(lv_obj_t *parent, const lv_img_dsc_t *img, uint64_t index, lv_obj_t *ui_cm_image = lv_img_create(ui_cm_panel); lv_img_set_src(ui_cm_image, img); - lv_obj_set_width(ui_cm_image, LV_SIZE_CONTENT); /// 1 - lv_obj_set_height(ui_cm_image, LV_SIZE_CONTENT); /// 1 + lv_obj_set_width(ui_cm_image, LV_SIZE_CONTENT); /// 1 + lv_obj_set_height(ui_cm_image, LV_SIZE_CONTENT); /// 1 lv_obj_set_align(ui_cm_image, LV_ALIGN_CENTER); - lv_obj_add_flag(ui_cm_image, LV_OBJ_FLAG_ADV_HITTEST); /// Flags - lv_obj_clear_flag(ui_cm_image, LV_OBJ_FLAG_SCROLLABLE); /// Flags + lv_obj_add_flag(ui_cm_image, LV_OBJ_FLAG_ADV_HITTEST); /// Flags + lv_obj_clear_flag(ui_cm_image, LV_OBJ_FLAG_SCROLLABLE); /// Flags lv_img_set_zoom(ui_cm_image, 50); - lv_obj_add_event_cb(ui_cm_panel, callback, LV_EVENT_CLICKED, (void*)index); + lv_obj_add_event_cb(ui_cm_panel, callback, LV_EVENT_CLICKED, (void *)index); } void set_parent(lv_obj_t *parent) @@ -472,4 +495,3 @@ void set_parent(lv_obj_t *parent) lv_obj_set_parent(ui_statusPanel, parent); lv_obj_set_parent(ui_alertPanel, parent); } - diff --git a/src/ui/ui_common.h b/src/ui/ui_common.h index d9a5df5..465e0c7 100644 --- a/src/ui/ui_common.h +++ b/src/ui/ui_common.h @@ -53,6 +53,14 @@ typedef struct _live_obj_t cm_live_dir_t dir; } live_obj_t; +typedef struct _quick_action +{ + uint64_t code; + const char *name; + const lv_img_dsc_t *icon; + bool checkable; +} quick_action; + typedef struct _settings_info_t { uint64_t code; @@ -73,18 +81,21 @@ typedef struct _themeable_t theme_type_t type; } themeable_t; -void cm_text(lv_obj_t *parent, const char *text); -void cm_switch(lv_obj_t *parent, const char* text, bool active, void (*callback)(lv_event_t *e)); -void cm_button(lv_obj_t *parent, const char *text); -void cm_title(lv_obj_t *parent, const char *text); -void cm_text_area(lv_obj_t *parent, const char *placeholder, void (*color)(lv_obj_t *obj)); -void cm_slider(lv_obj_t *parent, int value, int min, int max, void (*callback)(lv_event_t *e)); -void cm_panel_space(lv_obj_t *parent); -void cm_bar(lv_obj_t *parent, int value); -void cm_dropdown(lv_obj_t *parent, const char* options, int selected, int width, void (*callback)(lv_event_t *e)); +lv_obj_t *cm_create_text(lv_obj_t *parent, const char *text); +lv_obj_t *cm_create_switch(lv_obj_t *parent, const char* text, bool active, void (*callback)(lv_event_t *e)); +lv_obj_t *cm_create_button(lv_obj_t *parent, const char *text); +lv_obj_t *cm_create_title(lv_obj_t *parent, const char *text); +lv_obj_t *cm_create_text_area(lv_obj_t *parent, const char *placeholder, void (*color)(lv_obj_t *obj)); +lv_obj_t *cm_create_slider(lv_obj_t *parent, int value, int min, int max, void (*callback)(lv_event_t *e)); +lv_obj_t *cm_create_panel_space(lv_obj_t *parent, int height); +lv_obj_t *cm_create_bar(lv_obj_t *parent, int value, const char* format); +void cm_set_bar(lv_obj_t *obj, int value, const char* format); +lv_obj_t *cm_create_dropdown(lv_obj_t *parent, const char* options, int selected, int width, void (*callback)(lv_event_t *e)); + + void cm_user_list(lv_obj_t *parent, user_info_t user); -void cm_quick_action(lv_obj_t *parent, const char *name, const lv_img_dsc_t *icon, bool checkable); +void cm_quick_action(lv_obj_t *parent, quick_action action, void (*callback)(lv_event_t *e)); void cm_start_tile(start_tile_t tile, void(*callback)(live_obj_t l), void (*launcher)(lv_event_t * e), void(*start)(lv_obj_t *obj)); void cm_app_list(app_info_t app, void(*launcher)(lv_event_t *e), void(*panel)(lv_obj_t *obj));