#pragma once #include "WidgetConfig.hpp" #include "lvgl.h" #include class WidgetManager { public: static WidgetManager& instance(); // Initialize (load config from NVS) void init(); // Build/rebuild all widgets from current config // Call this after loading or when user clicks "Save" in web editor void applyConfig(); // Get current config for web editor (JSON) void getConfigJson(char* buf, size_t bufSize) const; // Update config from web editor (JSON) - does NOT apply immediately bool updateConfigFromJson(const char* json); // Save current config to NVS and apply to display void saveAndApply(); // Reset to factory defaults void resetToDefaults(); // KNX value update (called from KnxWorker) void onKnxValue(uint16_t groupAddr, float value); void onKnxSwitch(uint16_t groupAddr, bool value); void onKnxText(uint16_t groupAddr, const char* text); // Direct config access ScreenConfig& getConfig() { return config_; } const ScreenConfig& getConfig() const { return config_; } private: WidgetManager(); ~WidgetManager() = default; WidgetManager(const WidgetManager&) = delete; WidgetManager& operator=(const WidgetManager&) = delete; void loadFromSdCard(); void saveToSdCard(); void destroyAllWidgets(); void createAllWidgets(); lv_obj_t* createWidget(const WidgetConfig& cfg); void applyStyle(lv_obj_t* obj, const WidgetConfig& cfg); const lv_font_t* getFontBySize(uint8_t sizeIndex); void createDefaultConfig(); static constexpr const char* CONFIG_FILE = "/sdcard/lvgl.json"; ScreenConfig config_; // Runtime widget references (indexed by widget ID) std::array widgetObjects_; lv_obj_t* screen_ = nullptr; };