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:
@@ -158,11 +158,6 @@ std::list<const WidgetFactory *> & getRegisteredWidgets()
|
|||||||
return widgets;
|
return widgets;
|
||||||
}
|
}
|
||||||
|
|
||||||
void registerWidget(const WidgetFactory * factory)
|
|
||||||
{
|
|
||||||
TRACE("register widget %s", factory->getName());
|
|
||||||
getRegisteredWidgets().push_back(factory);
|
|
||||||
}
|
|
||||||
|
|
||||||
void unregisterWidget(const WidgetFactory * factory)
|
void unregisterWidget(const WidgetFactory * factory)
|
||||||
{
|
{
|
||||||
@@ -181,6 +176,17 @@ const WidgetFactory * getWidgetFactory(const char * name)
|
|||||||
return nullptr;
|
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,
|
Widget* loadWidget(const char* name, Window* parent, const rect_t& rect,
|
||||||
WidgetPersistentData* persistentData)
|
WidgetPersistentData* persistentData)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -157,11 +157,12 @@ class WidgetFactory
|
|||||||
TRACE("WidgetFactory::initPersistentData() setting option '%s'", option->name);
|
TRACE("WidgetFactory::initPersistentData() setting option '%s'", option->name);
|
||||||
// TODO compiler bug? The CPU freezes ... persistentData->options[i++] = option->deflt;
|
// TODO compiler bug? The CPU freezes ... persistentData->options[i++] = option->deflt;
|
||||||
auto optVal = &persistentData->options[i];
|
auto optVal = &persistentData->options[i];
|
||||||
if (setDefault) {
|
auto optType = zoneValueEnumFromType(option->type);
|
||||||
|
if (setDefault || optVal->type != optType) {
|
||||||
// reset to default value
|
// reset to default value
|
||||||
memcpy(&optVal->value, &option->deflt, sizeof(ZoneOptionValue));
|
memcpy(&optVal->value, &option->deflt, sizeof(ZoneOptionValue));
|
||||||
|
optVal->type = optType;
|
||||||
}
|
}
|
||||||
optVal->type = zoneValueEnumFromType(option->type);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user