feat(lua): allow the filename for an image object to be set via a function (#6091)
This commit is contained in:
@@ -1464,7 +1464,7 @@ void LvglWidgetArc::build(lua_State *L)
|
|||||||
void LvglWidgetImage::parseParam(lua_State *L, const char *key)
|
void LvglWidgetImage::parseParam(lua_State *L, const char *key)
|
||||||
{
|
{
|
||||||
if (!strcmp(key, "file")) {
|
if (!strcmp(key, "file")) {
|
||||||
filename = luaL_checkstring(L, -1);
|
filename.parse(L, LvglParamFuncOrValue::PTXT);
|
||||||
} else if (!strcmp(key, "fill")) {
|
} else if (!strcmp(key, "fill")) {
|
||||||
fillFrame = lua_toboolean(L, -1);
|
fillFrame = lua_toboolean(L, -1);
|
||||||
} else {
|
} 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)
|
void LvglWidgetImage::build(lua_State *L)
|
||||||
{
|
{
|
||||||
window = new StaticImage(lvglManager->getCurrentParent(), {x, y, w, h},
|
window = new StaticImage(lvglManager->getCurrentParent(), {x, y, w, h},
|
||||||
filename.c_str(), fillFrame);
|
filename.txt, fillFrame);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -456,8 +456,11 @@ class LvglWidgetImage : public LvglWidgetObject
|
|||||||
public:
|
public:
|
||||||
LvglWidgetImage() : LvglWidgetObject(LVGL_SIMPLEMETATABLE) {}
|
LvglWidgetImage() : LvglWidgetObject(LVGL_SIMPLEMETATABLE) {}
|
||||||
|
|
||||||
|
bool callRefs(lua_State *L) override;
|
||||||
|
void clearRefs(lua_State *L) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::string filename;
|
LvglParamFuncOrValue filename = { .function = LUA_REFNIL, .txt = ""};
|
||||||
bool fillFrame = false;
|
bool fillFrame = false;
|
||||||
|
|
||||||
void build(lua_State *L) override;
|
void build(lua_State *L) override;
|
||||||
|
|||||||
Reference in New Issue
Block a user