fix(color): Lua LVGL object does not draw correctly when using a function (#6193)
This commit is contained in:
@@ -736,6 +736,29 @@ void LvglWidgetLine::getPt(lua_State* L, int n)
|
|||||||
lua_pop(L, 2);
|
lua_pop(L, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t LvglWidgetLine::getPts(lua_State* L)
|
||||||
|
{
|
||||||
|
luaL_checktype(L, -1, LUA_TTABLE);
|
||||||
|
size_t newPtCnt = lua_rawlen(L, -1);
|
||||||
|
if (newPtCnt > 1) {
|
||||||
|
ptCnt = newPtCnt;
|
||||||
|
if (pts && ptCnt > ptAlloc) {
|
||||||
|
delete pts;
|
||||||
|
pts = nullptr;
|
||||||
|
}
|
||||||
|
if (!pts) {
|
||||||
|
pts = new lv_point_t[ptCnt];
|
||||||
|
ptAlloc = ptCnt;
|
||||||
|
}
|
||||||
|
for (size_t i = 0; i < ptCnt; i += 1)
|
||||||
|
getPt(L, i);
|
||||||
|
return hash(pts, sizeof(ptCnt * sizeof(lv_point_t)));
|
||||||
|
} else {
|
||||||
|
ptCnt = 0;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void LvglWidgetLine::parseParam(lua_State *L, const char *key)
|
void LvglWidgetLine::parseParam(lua_State *L, const char *key)
|
||||||
{
|
{
|
||||||
if (!strcmp(key, "thickness")) {
|
if (!strcmp(key, "thickness")) {
|
||||||
@@ -746,17 +769,7 @@ void LvglWidgetLine::parseParam(lua_State *L, const char *key)
|
|||||||
if (lua_isfunction(L, -1)) {
|
if (lua_isfunction(L, -1)) {
|
||||||
getPointsFunction = luaL_ref(L, LUA_REGISTRYINDEX);
|
getPointsFunction = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||||
} else {
|
} else {
|
||||||
luaL_checktype(L, -1, LUA_TTABLE);
|
ptsHash = getPts(L);
|
||||||
ptCnt = lua_rawlen(L, -1);
|
|
||||||
if (pts) delete pts;
|
|
||||||
if (ptCnt > 1) {
|
|
||||||
pts = new lv_point_t[ptCnt];
|
|
||||||
for (size_t i = 0; i < ptCnt; i += 1)
|
|
||||||
getPt(L, i);
|
|
||||||
} else {
|
|
||||||
pts = nullptr;
|
|
||||||
ptCnt = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LvglSimpleWidgetObject::parseParam(L, key);
|
LvglSimpleWidgetObject::parseParam(L, key);
|
||||||
@@ -768,21 +781,10 @@ bool LvglWidgetLine::callRefs(lua_State *L)
|
|||||||
int t = lua_gettop(L);
|
int t = lua_gettop(L);
|
||||||
if (getPointsFunction != LUA_REFNIL) {
|
if (getPointsFunction != LUA_REFNIL) {
|
||||||
if (pcallFunc(L, getPointsFunction, 1)) {
|
if (pcallFunc(L, getPointsFunction, 1)) {
|
||||||
luaL_checktype(L, -1, LUA_TTABLE);
|
uint32_t h = getPts(L);
|
||||||
ptCnt = lua_rawlen(L, -1);
|
if (h != ptsHash) {
|
||||||
if (pts) delete pts;
|
ptsHash = h;
|
||||||
if (ptCnt > 1) {
|
setLine();
|
||||||
pts = new lv_point_t[ptCnt];
|
|
||||||
for (size_t i = 0; i < ptCnt; i += 1)
|
|
||||||
getPt(L, i);
|
|
||||||
uint32_t h = hash(pts, sizeof(ptCnt * sizeof(lv_point_t)));
|
|
||||||
if (h != ptsHash) {
|
|
||||||
ptsHash = h;
|
|
||||||
refresh();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
pts = nullptr;
|
|
||||||
ptCnt = 0;
|
|
||||||
}
|
}
|
||||||
lua_settop(L, t);
|
lua_settop(L, t);
|
||||||
} else {
|
} else {
|
||||||
@@ -830,7 +832,10 @@ void LvglWidgetLine::setSize(coord_t w, coord_t h)
|
|||||||
|
|
||||||
void LvglWidgetLine::setLine()
|
void LvglWidgetLine::setLine()
|
||||||
{
|
{
|
||||||
if (lvobj && pts) {
|
if (pts) {
|
||||||
|
if (!lvobj)
|
||||||
|
lvobj = lv_line_create(parent);
|
||||||
|
|
||||||
x = pts[0].x;
|
x = pts[0].x;
|
||||||
y = pts[0].y;
|
y = pts[0].y;
|
||||||
for (size_t i = 1; i < ptCnt; i += 1) {
|
for (size_t i = 1; i < ptCnt; i += 1) {
|
||||||
@@ -847,7 +852,6 @@ void LvglWidgetLine::setLine()
|
|||||||
void LvglWidgetLine::build(lua_State *L)
|
void LvglWidgetLine::build(lua_State *L)
|
||||||
{
|
{
|
||||||
if (pts) {
|
if (pts) {
|
||||||
lvobj = lv_line_create(parent);
|
|
||||||
setColor(color.flags);
|
setColor(color.flags);
|
||||||
setOpacity(opacity.value);
|
setOpacity(opacity.value);
|
||||||
setLine();
|
setLine();
|
||||||
@@ -856,10 +860,6 @@ void LvglWidgetLine::build(lua_State *L)
|
|||||||
|
|
||||||
void LvglWidgetLine::refresh()
|
void LvglWidgetLine::refresh()
|
||||||
{
|
{
|
||||||
if (lvobj) {
|
|
||||||
lv_obj_del(lvobj);
|
|
||||||
lvobj = nullptr;
|
|
||||||
}
|
|
||||||
color.currVal = -1;
|
color.currVal = -1;
|
||||||
build(nullptr);
|
build(nullptr);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -243,6 +243,7 @@ class LvglWidgetLine : public LvglSimpleWidgetObject
|
|||||||
coord_t thickness = 1;
|
coord_t thickness = 1;
|
||||||
bool rounded = false;
|
bool rounded = false;
|
||||||
size_t ptCnt = 0;
|
size_t ptCnt = 0;
|
||||||
|
size_t ptAlloc = 0;
|
||||||
lv_point_t* pts = nullptr;
|
lv_point_t* pts = nullptr;
|
||||||
uint32_t ptsHash = -1;
|
uint32_t ptsHash = -1;
|
||||||
lv_obj_t* parent = nullptr;
|
lv_obj_t* parent = nullptr;
|
||||||
@@ -250,6 +251,7 @@ class LvglWidgetLine : public LvglSimpleWidgetObject
|
|||||||
|
|
||||||
void setLine();
|
void setLine();
|
||||||
|
|
||||||
|
uint32_t getPts(lua_State* L);
|
||||||
void getPt(lua_State* L, int n);
|
void getPt(lua_State* L, int n);
|
||||||
void build(lua_State *L) override;
|
void build(lua_State *L) override;
|
||||||
void parseParam(lua_State *L, const char *key) override;
|
void parseParam(lua_State *L, const char *key) override;
|
||||||
|
|||||||
Reference in New Issue
Block a user