44#include " widgets/light_switch_wide_widget.h"
55#include " widgets/temperature_widget.h"
66#include " widgets/scenario_widget.h"
7+ #include " widgets/clock_widget.h"
78#include " logging.h"
89#include < sstream>
910
@@ -31,10 +32,18 @@ void WidgetFactory::registerWidget(const std::string& typeName,
3132 ESP_LOGI (TAG , " Registered widget: %s" , key.c_str ());
3233}
3334
35+ void WidgetFactory::registerWidgetAnySize (const std::string& typeName, WidgetCreator creator)
36+ {
37+ anySizeCreators[typeName] = creator;
38+ ESP_LOGI (TAG , " Registered any-size widget: %s" , typeName.c_str ());
39+ }
40+
3441bool WidgetFactory::isRegistered (const std::string& typeName, int width, int height) const
3542{
3643 std::string key = makeKey (typeName, width, height);
37- return creators.find (key) != creators.end ();
44+ if (creators.find (key) != creators.end ())
45+ return true ;
46+ return anySizeCreators.find (typeName) != anySizeCreators.end ();
3847}
3948
4049std::string WidgetFactory::makeKey (const std::string& type, int w, int h) const
@@ -53,14 +62,22 @@ std::unique_ptr<CalaosWidget> WidgetFactory::createWidget(
5362
5463 ESP_LOGI (TAG , " Creating widget: %s (io_id=%s)" , key.c_str (), config.io_id .c_str ());
5564
56- // Look up creator
65+ // Look up creator - first try exact Type_WxH match
5766 auto it = creators.find (key);
5867 if (it != creators.end ())
5968 {
60- // Found - create the widget
69+ // Found exact match - create the widget
6170 return it->second (parent, config, gridInfo);
6271 }
6372
73+ // Try any-size fallback for this type
74+ auto anyIt = anySizeCreators.find (config.type );
75+ if (anyIt != anySizeCreators.end ())
76+ {
77+ ESP_LOGI (TAG , " Using any-size creator for type: %s" , config.type .c_str ());
78+ return anyIt->second (parent, config, gridInfo);
79+ }
80+
6481 // Not found - create WidgetError
6582 ESP_LOGW (TAG , " Widget type/size not supported: %s - creating WidgetError" , key.c_str ());
6683
@@ -110,5 +127,13 @@ void WidgetFactory::registerBuiltinWidgets()
110127 }
111128 );
112129
113- ESP_LOGI (TAG , " Built-in widgets registered: %zu" , creators.size ());
130+ // Register Clock for any size (dynamically adapts to grid dimensions)
131+ registerWidgetAnySize (" Clock" ,
132+ [](lv_obj_t * parent, const auto & config, const auto & gridInfo) {
133+ return std::make_unique<ClockWidget>(parent, config, gridInfo);
134+ }
135+ );
136+
137+ ESP_LOGI (TAG , " Built-in widgets registered: %zu sized + %zu any-size" ,
138+ creators.size (), anySizeCreators.size ());
114139}
0 commit comments