feat: Allow Lua widget to override built-in widget with same name (#2208)

* Allow CPP Widgets Override with LUA

* Reset a widget option it the type differs
This commit is contained in:
David PHAM-VAN
2022-08-26 16:04:34 +10:00
committed by GitHub
parent 4b747caff9
commit dc99dd40d2
2 changed files with 14 additions and 7 deletions
+11 -5
View File
@@ -158,11 +158,6 @@ std::list<const WidgetFactory *> & getRegisteredWidgets()
return widgets;
}
void registerWidget(const WidgetFactory * factory)
{
TRACE("register widget %s", factory->getName());
getRegisteredWidgets().push_back(factory);
}
void unregisterWidget(const WidgetFactory * factory)
{
@@ -181,6 +176,17 @@ const WidgetFactory * getWidgetFactory(const char * name)
return nullptr;
}
void registerWidget(const WidgetFactory * factory)
{
auto name = factory->getName();
auto oldWidget = getWidgetFactory(name);
if (oldWidget) {
unregisterWidget(oldWidget);
}
TRACE("register widget %s", name);
getRegisteredWidgets().push_back(factory);
}
Widget* loadWidget(const char* name, Window* parent, const rect_t& rect,
WidgetPersistentData* persistentData)
{
+3 -2
View File
@@ -157,11 +157,12 @@ class WidgetFactory
TRACE("WidgetFactory::initPersistentData() setting option '%s'", option->name);
// TODO compiler bug? The CPU freezes ... persistentData->options[i++] = option->deflt;
auto optVal = &persistentData->options[i];
if (setDefault) {
auto optType = zoneValueEnumFromType(option->type);
if (setDefault || optVal->type != optType) {
// reset to default value
memcpy(&optVal->value, &option->deflt, sizeof(ZoneOptionValue));
optVal->type = optType;
}
optVal->type = zoneValueEnumFromType(option->type);
}
}
}