feat(lua): add 'borderPad' property for LVGL Lua script container objects (#7095)
This commit is contained in:
@@ -539,7 +539,7 @@ LROT_BEGIN(lvgllib, NULL, 0)
|
||||
LROT_NUMENTRY(TOGGLE, ETX_TOGGLE)
|
||||
LROT_NUMENTRY(TEXT_EDIT, ETX_TEXTEDIT)
|
||||
LROT_NUMENTRY(NUMBER_EDIT, ETX_NUMBEREDIT)
|
||||
LROT_NUMENTRY(CHOIDE, ETX_CHOICE)
|
||||
LROT_NUMENTRY(CHOICE, ETX_CHOICE)
|
||||
LROT_NUMENTRY(SLIDER, ETX_SLIDER)
|
||||
LROT_NUMENTRY(VERTICAL_SLIDER, ETX_VERTICAL_SLIDER)
|
||||
LROT_NUMENTRY(PAGE, ETX_PAGE)
|
||||
|
||||
@@ -1405,6 +1405,26 @@ void LvglWidgetObject::parseParam(lua_State *L, const char *key)
|
||||
flexFlow = luaL_checkinteger(L, -1);
|
||||
} else if (!strcmp(key, "flexPad")) {
|
||||
flexPad = luaL_checkinteger(L, -1);
|
||||
} else if (!strcmp(key, "borderPad")) {
|
||||
customPad = true;
|
||||
if (lua_isinteger(L, -1)) {
|
||||
int8_t pad = luaL_checkinteger(L, -1);
|
||||
borderPadLeft = borderPadRight = borderPadTop = borderPadBottom = pad;
|
||||
} else {
|
||||
luaL_checktype(L, -1, LUA_TTABLE);
|
||||
for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 1)) {
|
||||
const char *key = lua_tostring(L, -2);
|
||||
if (!strcmp(key, "left")) {
|
||||
borderPadLeft = luaL_checkinteger(L, -1);
|
||||
} else if (!strcmp(key, "right")) {
|
||||
borderPadRight = luaL_checkinteger(L, -1);
|
||||
} else if (!strcmp(key, "top")) {
|
||||
borderPadTop = luaL_checkinteger(L, -1);
|
||||
} else if (!strcmp(key, "bottom")) {
|
||||
borderPadBottom = luaL_checkinteger(L, -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (!strcmp(key, "active")) {
|
||||
getActiveFunction = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
} else {
|
||||
@@ -1428,14 +1448,21 @@ void LvglWidgetObject::setSize(coord_t w, coord_t h)
|
||||
|
||||
bool LvglWidgetObject::setFlex()
|
||||
{
|
||||
if (customPad) {
|
||||
lv_obj_set_style_pad_left(window->getLvObj(), borderPadLeft, 0);
|
||||
lv_obj_set_style_pad_right(window->getLvObj(), borderPadRight, 0);
|
||||
lv_obj_set_style_pad_top(window->getLvObj(), borderPadTop, 0);
|
||||
lv_obj_set_style_pad_bottom(window->getLvObj(), borderPadBottom, 0);
|
||||
} else {
|
||||
window->padAll(flexFlow >= 0 ? PAD_OUTLINE : PAD_ZERO);
|
||||
}
|
||||
|
||||
if (flexFlow >= 0) {
|
||||
window->padAll(PAD_TINY);
|
||||
window->setFlexLayout((lv_flex_flow_t)flexFlow, flexPad, w, h);
|
||||
return true;
|
||||
} else {
|
||||
window->padAll(PAD_ZERO);
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool LvglWidgetObject::callRefs(lua_State *L)
|
||||
|
||||
@@ -490,7 +490,12 @@ class LvglWidgetObject : public LvglWidgetObjectBase
|
||||
protected:
|
||||
Window *window = nullptr;
|
||||
int8_t flexFlow = -1;
|
||||
int8_t flexPad = PAD_TINY;
|
||||
int8_t flexPad = PAD_OUTLINE;
|
||||
bool customPad = false;
|
||||
int8_t borderPadLeft = PAD_ZERO;
|
||||
int8_t borderPadRight = PAD_ZERO;
|
||||
int8_t borderPadTop = PAD_ZERO;
|
||||
int8_t borderPadBottom = PAD_ZERO;
|
||||
int getActiveFunction = LUA_REFNIL;
|
||||
|
||||
void parseParam(lua_State *L, const char *key) override;
|
||||
|
||||
Reference in New Issue
Block a user