feat(lua): allow the filename for an image object to be set via a function (#6091)

This commit is contained in:
philmoz
2025-04-16 11:40:13 +10:00
committed by GitHub
parent f82c3dea8c
commit 93c5b7fccd
2 changed files with 29 additions and 3 deletions
+25 -2
View File
@@ -1464,7 +1464,7 @@ void LvglWidgetArc::build(lua_State *L)
void LvglWidgetImage::parseParam(lua_State *L, const char *key)
{
if (!strcmp(key, "file")) {
filename = luaL_checkstring(L, -1);
filename.parse(L, LvglParamFuncOrValue::PTXT);
} else if (!strcmp(key, "fill")) {
fillFrame = lua_toboolean(L, -1);
} else {
@@ -1472,10 +1472,33 @@ void LvglWidgetImage::parseParam(lua_State *L, const char *key)
}
}
bool LvglWidgetImage::callRefs(lua_State *L)
{
int t = lua_gettop(L);
if (filename.function != LUA_REFNIL) {
if (pcallFunc(L, filename.function, 1)) {
const char *s = luaL_checkstring(L, -1);
if (filename.changedText(s)) {
((StaticImage*)window)->setSource(filename.txt);
}
lua_settop(L, t);
} else {
return false;
}
}
return LvglWidgetObject::callRefs(L);
}
void LvglWidgetImage::clearRefs(lua_State *L)
{
clearRef(L, filename.function);
LvglWidgetObject::clearRefs(L);
}
void LvglWidgetImage::build(lua_State *L)
{
window = new StaticImage(lvglManager->getCurrentParent(), {x, y, w, h},
filename.c_str(), fillFrame);
filename.txt, fillFrame);
}
//-----------------------------------------------------------------------------