fix(lua): Store and update the 'zone' rectangle for Lua widgets. (#3060)
* Store 'zone' rectangle dat in Lua registry and update it when the screen layout changes or full screen mode changes. Allows Lua widgets to adjust to layout changes. * Call widget 'update' function is layout has changed.
This commit is contained in:
@@ -70,6 +70,7 @@ Widget* LuaWidgetFactory::create(Window* parent, const rect_t& rect,
|
||||
luaSetInstructionsLimit(lsWidgets, MAX_INSTRUCTIONS);
|
||||
lua_rawgeti(lsWidgets, LUA_REGISTRYINDEX, createFunction);
|
||||
|
||||
// Make 'zone' table for 'create' call
|
||||
lua_newtable(lsWidgets);
|
||||
l_pushtableint("x", 0);
|
||||
l_pushtableint("y", 0);
|
||||
@@ -78,6 +79,11 @@ Widget* LuaWidgetFactory::create(Window* parent, const rect_t& rect,
|
||||
l_pushtableint("xabs", rect.x);
|
||||
l_pushtableint("yabs", rect.y);
|
||||
|
||||
// Store the zone data in registry for later updates
|
||||
int zoneRectDataRef = luaL_ref(lsWidgets, LUA_REGISTRYINDEX);
|
||||
// Push stored zone for 'create' call
|
||||
lua_rawgeti(lsWidgets, LUA_REGISTRYINDEX, zoneRectDataRef);
|
||||
|
||||
lua_newtable(lsWidgets);
|
||||
int i = 0;
|
||||
for (const ZoneOption* option = options; option->name; option++, i++) {
|
||||
@@ -100,7 +106,7 @@ Widget* LuaWidgetFactory::create(Window* parent, const rect_t& rect,
|
||||
|
||||
bool err = lua_pcall(lsWidgets, 2, 1, 0);
|
||||
int widgetData = err ? LUA_NOREF : luaL_ref(lsWidgets, LUA_REGISTRYINDEX);
|
||||
LuaWidget* lw = new LuaWidget(this, parent, rect, persistentData, widgetData);
|
||||
LuaWidget* lw = new LuaWidget(this, parent, rect, persistentData, widgetData, zoneRectDataRef);
|
||||
if (err) lw->setErrorMessage("create()");
|
||||
return lw;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user