Skip to content

Commit

Permalink
Fix 'page' object for full screen widgets.
Browse files Browse the repository at this point in the history
  • Loading branch information
philmoz committed Jan 22, 2025
1 parent 7f8c362 commit 8f861ec
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
12 changes: 6 additions & 6 deletions radio/src/lua/api_colorlcd_lvgl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@

LuaLvglManager *luaLvglManager = nullptr;

static int luaLvglObj(lua_State *L, std::function<LvglWidgetObject*()> create, bool standalone = false)
static int luaLvglObj(lua_State *L, std::function<LvglWidgetObject*()> create, bool fullscreenOnly = false)
{
if (luaLvglManager && (!standalone || !luaLvglManager->isWidget())) {
if (luaLvglManager && (!fullscreenOnly || luaLvglManager->isFullscreen())) {
auto obj = create();
obj->getParams(L, 1);
obj->build(L);
Expand All @@ -44,9 +44,9 @@ static int luaLvglObj(lua_State *L, std::function<LvglWidgetObject*()> create, b
return 1;
}

static int luaLvglObjEx(lua_State *L, std::function<LvglWidgetObjectBase*()> create, bool standalone = false)
static int luaLvglObjEx(lua_State *L, std::function<LvglWidgetObjectBase*()> create, bool fullscreenOnly = false)
{
if (luaLvglManager && (!standalone || !luaLvglManager->isWidget())) {
if (luaLvglManager && (!fullscreenOnly || !luaLvglManager->isFullscreen())) {
LvglWidgetObjectBase* p = nullptr;
LvglWidgetObjectBase* prevParent = nullptr;
if (lua_gettop(L) == 2) {
Expand Down Expand Up @@ -345,7 +345,7 @@ LROT_BEGIN(lvgl_mt, NULL, LROT_MASK_GC_INDEX)
LROT_TABENTRY(__index, lvgl_mt)
LROT_FUNCENTRY(clear, luaLvglClear)
LROT_FUNCENTRY(build, luaLvglBuild)
// Objects - widgets and standalone
// Objects - widgets and standalone scripts
LROT_FUNCENTRY(label, [](lua_State* L) { return luaLvglObjEx(L, []() { return new LvglWidgetLabel(); }); })
LROT_FUNCENTRY(rectangle, [](lua_State* L) { return luaLvglObjEx(L, []() { return new LvglWidgetRectangle(); }); })
LROT_FUNCENTRY(hline, [](lua_State* L) { return luaLvglObjEx(L, []() { return new LvglWidgetHLine(); }); })
Expand All @@ -356,7 +356,7 @@ LROT_BEGIN(lvgl_mt, NULL, LROT_MASK_GC_INDEX)
LROT_FUNCENTRY(arc, [](lua_State* L) { return luaLvglObjEx(L, []() { return new LvglWidgetArc(); }); })
LROT_FUNCENTRY(image, [](lua_State* L) { return luaLvglObjEx(L, []() { return new LvglWidgetImage(); }); })
LROT_FUNCENTRY(qrcode, [](lua_State* L) { return luaLvglObjEx(L, []() { return new LvglWidgetQRCode(); }); })
// Objects - standalone scripts only
// Objects - standalone scripts and full screen widgets only
LROT_FUNCENTRY(button, [](lua_State* L) { return luaLvglObjEx(L, []() { return new LvglWidgetTextButton(); }, true); })
LROT_FUNCENTRY(toggle, [](lua_State* L) { return luaLvglObjEx(L, []() { return new LvglWidgetToggleSwitch(); }, true); })
LROT_FUNCENTRY(textEdit, [](lua_State* L) { return luaLvglObjEx(L, []() { return new LvglWidgetTextEdit(); }, true); })
Expand Down
28 changes: 22 additions & 6 deletions radio/src/lua/lua_lvgl_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,11 @@ void LvglWidgetObjectBase::pcallSimpleFunc(lua_State *L, int funcRef)
if (funcRef != LUA_REFNIL) {
PROTECT_LUA()
{
luaLvglManager = lvglManager;
if (!pcallFunc(L, funcRef, 0)) {
lvglManager->luaShowError();
}
luaLvglManager = nullptr;
}
UNPROTECT_LUA();
}
Expand All @@ -137,56 +139,66 @@ void LvglWidgetObjectBase::pcallSimpleFunc(lua_State *L, int funcRef)
bool LvglWidgetObjectBase::pcallUpdateBool(lua_State *L, int getFuncRef,
std::function<void(bool)> update)
{
bool res = true;
if (getFuncRef != LUA_REFNIL) {
luaLvglManager = lvglManager;
int t = lua_gettop(L);
if (pcallFunc(L, getFuncRef, 1)) {
bool val = lua_toboolean(L, -1);
update(val);
lua_settop(L, t);
} else {
return false;
res = false;
}
lvglManager = nullptr;
}
return true;
return res;
}

bool LvglWidgetObjectBase::pcallUpdate1Int(lua_State *L, int getFuncRef,
std::function<void(int)> update)
{
bool res = true;
if (getFuncRef != LUA_REFNIL) {
luaLvglManager = lvglManager;
int t = lua_gettop(L);
if (pcallFunc(L, getFuncRef, 1)) {
int val = luaL_checkunsigned(L, -1);
update(val);
lua_settop(L, t);
} else {
return false;
res = false;
}
lvglManager = nullptr;
}
return true;
return res;
}

bool LvglWidgetObjectBase::pcallUpdate2Int(lua_State *L, int getFuncRef,
std::function<void(int, int)> update)
{
bool res = true;
if (getFuncRef != LUA_REFNIL) {
luaLvglManager = lvglManager;
int t = lua_gettop(L);
if (pcallFunc(L, getFuncRef, 2)) {
int v1 = luaL_checkunsigned(L, -2);
int v2 = luaL_checkunsigned(L, -1);
update(v1, v2);
lua_settop(L, t);
} else {
return false;
res = false;
}
lvglManager = nullptr;
}
return true;
return res;
}

int LvglWidgetObjectBase::pcallGetIntVal(lua_State *L, int getFuncRef)
{
int val = 0;
if (getFuncRef != LUA_REFNIL) {
luaLvglManager = lvglManager;
int t = lua_gettop(L);
PROTECT_LUA()
{
Expand All @@ -202,13 +214,15 @@ int LvglWidgetObjectBase::pcallGetIntVal(lua_State *L, int getFuncRef)
}
UNPROTECT_LUA();
lua_settop(L, t);
lvglManager = nullptr;
}
return val;
}

void LvglWidgetObjectBase::pcallSetIntVal(lua_State *L, int setFuncRef, int val)
{
if (setFuncRef != LUA_REFNIL) {
luaLvglManager = lvglManager;
int t = lua_gettop(L);
PROTECT_LUA()
{
Expand All @@ -222,6 +236,7 @@ void LvglWidgetObjectBase::pcallSetIntVal(lua_State *L, int setFuncRef, int val)
}
UNPROTECT_LUA();
lua_settop(L, t);
lvglManager = nullptr;
}
}

Expand Down Expand Up @@ -1515,6 +1530,7 @@ class WidgetPage : public NavWindow, public LuaEventHandler
void onEvent(event_t evt) override
{
LuaEventHandler::onEvent(evt);
parent->onEvent(evt);
}

protected:
Expand Down

0 comments on commit 8f861ec

Please sign in to comment.