mirror of
https://github.com/opentx/opentx.git
synced 2025-07-24 16:55:20 +03:00
[Horus] Widget::update added to the Lua interface (called when options are modified)
This commit is contained in:
parent
0fad67a8ea
commit
7a2c0b3b88
2 changed files with 33 additions and 2 deletions
|
@ -10,9 +10,13 @@ local function create(zone, options)
|
||||||
return pie
|
return pie
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function update(pie, options)
|
||||||
|
pie.options = options
|
||||||
|
end
|
||||||
|
|
||||||
function refresh(pie)
|
function refresh(pie)
|
||||||
pie.counter = pie.counter + 1
|
pie.counter = pie.counter + 1
|
||||||
lcd.drawNumber(pie.zone.x, pie.zone.y, pie.counter, LEFT + DBLSIZE + TEXT_COLOR);
|
lcd.drawNumber(pie.zone.x, pie.zone.y, pie.counter, LEFT + DBLSIZE + TEXT_COLOR);
|
||||||
end
|
end
|
||||||
|
|
||||||
return { name="Counter", options=options, create=create, refresh=refresh }
|
return { name="Counter", options=options, create=create, update=update, refresh=refresh }
|
||||||
|
|
|
@ -909,6 +909,8 @@ class LuaWidget: public Widget
|
||||||
luaL_unref(L, LUA_REGISTRYINDEX, widgetData);
|
luaL_unref(L, LUA_REGISTRYINDEX, widgetData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void update() const;
|
||||||
|
|
||||||
virtual void refresh();
|
virtual void refresh();
|
||||||
|
|
||||||
virtual void background();
|
virtual void background();
|
||||||
|
@ -933,6 +935,7 @@ class LuaWidgetFactory: public WidgetFactory
|
||||||
LuaWidgetFactory(const char * name, int widgetOptions, int createFunction):
|
LuaWidgetFactory(const char * name, int widgetOptions, int createFunction):
|
||||||
WidgetFactory(name, createOptionsArray(widgetOptions)),
|
WidgetFactory(name, createOptionsArray(widgetOptions)),
|
||||||
createFunction(createFunction),
|
createFunction(createFunction),
|
||||||
|
updateFunction(0),
|
||||||
refreshFunction(0),
|
refreshFunction(0),
|
||||||
backgroundFunction(0)
|
backgroundFunction(0)
|
||||||
{
|
{
|
||||||
|
@ -969,10 +972,29 @@ class LuaWidgetFactory: public WidgetFactory
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int createFunction;
|
int createFunction;
|
||||||
|
int updateFunction;
|
||||||
int refreshFunction;
|
int refreshFunction;
|
||||||
int backgroundFunction;
|
int backgroundFunction;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void LuaWidget::update() const
|
||||||
|
{
|
||||||
|
SET_LUA_INSTRUCTIONS_COUNT(PERMANENT_SCRIPTS_MAX_INSTRUCTIONS);
|
||||||
|
LuaWidgetFactory * factory = (LuaWidgetFactory *)this->factory;
|
||||||
|
lua_rawgeti(L, LUA_REGISTRYINDEX, factory->updateFunction);
|
||||||
|
lua_rawgeti(L, LUA_REGISTRYINDEX, widgetData);
|
||||||
|
|
||||||
|
lua_newtable(L);
|
||||||
|
int i = 0;
|
||||||
|
for (const ZoneOption * option = getOptions(); option->name; option++, i++) {
|
||||||
|
l_pushtableint(option->name, persistentData->options[i].signedValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lua_pcall(L, 2, 0, 0) != 0) {
|
||||||
|
TRACE("Error in widget %s: %s", factory->getName(), lua_tostring(L, -1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void LuaWidget::refresh()
|
void LuaWidget::refresh()
|
||||||
{
|
{
|
||||||
SET_LUA_INSTRUCTIONS_COUNT(PERMANENT_SCRIPTS_MAX_INSTRUCTIONS);
|
SET_LUA_INSTRUCTIONS_COUNT(PERMANENT_SCRIPTS_MAX_INSTRUCTIONS);
|
||||||
|
@ -998,7 +1020,7 @@ void LuaWidget::background()
|
||||||
void luaLoadWidgetCallback()
|
void luaLoadWidgetCallback()
|
||||||
{
|
{
|
||||||
const char * name=NULL;
|
const char * name=NULL;
|
||||||
int widgetOptions=0, createFunction=0, refreshFunction=0, backgroundFunction=0;
|
int widgetOptions=0, createFunction=0, updateFunction=0, refreshFunction=0, backgroundFunction=0;
|
||||||
|
|
||||||
luaL_checktype(L, -1, LUA_TTABLE);
|
luaL_checktype(L, -1, LUA_TTABLE);
|
||||||
|
|
||||||
|
@ -1015,6 +1037,10 @@ void luaLoadWidgetCallback()
|
||||||
createFunction = luaL_ref(L, LUA_REGISTRYINDEX);
|
createFunction = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
}
|
}
|
||||||
|
else if (!strcmp(key, "update")) {
|
||||||
|
updateFunction = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||||
|
lua_pushnil(L);
|
||||||
|
}
|
||||||
else if (!strcmp(key, "refresh")) {
|
else if (!strcmp(key, "refresh")) {
|
||||||
refreshFunction = luaL_ref(L, LUA_REGISTRYINDEX);
|
refreshFunction = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
|
@ -1027,6 +1053,7 @@ void luaLoadWidgetCallback()
|
||||||
|
|
||||||
if (name && createFunction) {
|
if (name && createFunction) {
|
||||||
LuaWidgetFactory * factory = new LuaWidgetFactory(name, widgetOptions, createFunction);
|
LuaWidgetFactory * factory = new LuaWidgetFactory(name, widgetOptions, createFunction);
|
||||||
|
factory->updateFunction = updateFunction;
|
||||||
factory->refreshFunction = refreshFunction;
|
factory->refreshFunction = refreshFunction;
|
||||||
factory->backgroundFunction = backgroundFunction;
|
factory->backgroundFunction = backgroundFunction;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue