WIP bump luavgl to latest
This commit is contained in:
+22
-18
@@ -27,7 +27,7 @@ static luavgl_anim_t *luavgl_check_anim(lua_State *L, int index)
|
||||
luavgl_anim_t *a = luaL_checkudata(L, index, "lv_anim");
|
||||
|
||||
if (a->deleted) {
|
||||
luaL_argerror(L, index, "anim already deleted.");
|
||||
luaL_argerror(L, index, "anim already deleted");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -40,8 +40,8 @@ static void luavgl_anim_exec_cb(void *var, int32_t value)
|
||||
lua_State *L = a->L;
|
||||
|
||||
if (a->exec_cb == LUA_NOREF || a->obj_ref == LUA_NOREF) {
|
||||
debug("anim error, callback or obj not found.\n");
|
||||
luaL_error(L, "anim founds no callback or obj.");
|
||||
LV_LOG_ERROR("anim error, callback or obj not found");
|
||||
luaL_error(L, "anim founds no callback or obj");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -94,19 +94,19 @@ static void _lv_anim_set_path(void *obj, lua_State *L)
|
||||
}
|
||||
|
||||
a->path_cb = lv_anim_path_linear;
|
||||
if (path == NULL || strcmp(path, "linear") == 0) {
|
||||
if (path == NULL || lv_strcmp(path, "linear") == 0) {
|
||||
; /* use default linear path */
|
||||
} else if (strcmp(path, "ease_in") == 0) {
|
||||
} else if (lv_strcmp(path, "ease_in") == 0) {
|
||||
a->path_cb = lv_anim_path_ease_in;
|
||||
} else if (strcmp(path, "ease_out") == 0) {
|
||||
} else if (lv_strcmp(path, "ease_out") == 0) {
|
||||
a->path_cb = lv_anim_path_ease_out;
|
||||
} else if (strcmp(path, "ease_in_out") == 0) {
|
||||
} else if (lv_strcmp(path, "ease_in_out") == 0) {
|
||||
a->path_cb = lv_anim_path_ease_in_out;
|
||||
} else if (strcmp(path, "overshoot") == 0) {
|
||||
} else if (lv_strcmp(path, "overshoot") == 0) {
|
||||
a->path_cb = lv_anim_path_overshoot;
|
||||
} else if (strcmp(path, "bounce") == 0) {
|
||||
} else if (lv_strcmp(path, "bounce") == 0) {
|
||||
a->path_cb = lv_anim_path_bounce;
|
||||
} else if (strcmp(path, "step") == 0) {
|
||||
} else if (lv_strcmp(path, "step") == 0) {
|
||||
a->path_cb = lv_anim_path_step;
|
||||
}
|
||||
}
|
||||
@@ -135,7 +135,7 @@ static int anim_set_para_cb(lua_State *L, void *data)
|
||||
int ret = luavgl_set_property(L, data, anim_property_table);
|
||||
|
||||
if (ret != 0) {
|
||||
debug("failed\n");
|
||||
LV_LOG_ERROR("failed");
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -146,7 +146,7 @@ static int luavgl_anim_stop(lua_State *L)
|
||||
luavgl_anim_t *a = luavgl_check_anim(L, 1);
|
||||
|
||||
if (a->aa == NULL || a->self_ref == LUA_NOREF) {
|
||||
debug("already stopped");
|
||||
LV_LOG_INFO("already stopped");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -179,13 +179,13 @@ static int luavgl_anim_start(lua_State *L)
|
||||
luavgl_anim_t *a = luavgl_check_anim(L, 1);
|
||||
|
||||
if (a->aa) {
|
||||
debug("we have an anim ongoing, stop it.");
|
||||
LV_LOG_INFO("we have an anim ongoing, stop it");
|
||||
luavgl_anim_stop(L);
|
||||
}
|
||||
|
||||
lv_anim_t *new_a = lv_anim_start(&a->cfg);
|
||||
a->aa = new_a;
|
||||
debug("anim %p, aa: %p\n", a, a->aa);
|
||||
LV_LOG_INFO("anim %p, aa: %p", a, a->aa);
|
||||
|
||||
if (a->self_ref == LUA_NOREF) {
|
||||
/* it's started, thus cannot be gc'ed */
|
||||
@@ -248,11 +248,11 @@ static int luavgl_anim_set(lua_State *L)
|
||||
static int luavgl_anim_create(lua_State *L)
|
||||
{
|
||||
if (lua_isnoneornil(L, 1)) {
|
||||
return luaL_argerror(L, 1, "anim var must not be nil or none.");
|
||||
return luaL_argerror(L, 1, "anim var must not be nil or none");
|
||||
}
|
||||
|
||||
if (!lua_istable(L, 2)) {
|
||||
return luaL_argerror(L, 2, "expect anim para table.");
|
||||
return luaL_argerror(L, 2, "expect anim para table");
|
||||
}
|
||||
|
||||
luavgl_anim_t *a = lua_newuserdata(L, sizeof(luavgl_anim_t));
|
||||
@@ -271,7 +271,11 @@ static int luavgl_anim_create(lua_State *L)
|
||||
lv_anim_t *cfg = &a->cfg;
|
||||
lv_anim_init(cfg);
|
||||
cfg->var = a;
|
||||
#if LV_VERSION_CHECK(8, 3, 0)
|
||||
cfg->deleted_cb = luavgl_anim_delete_cb;
|
||||
#else
|
||||
cfg->completed_cb = luavgl_anim_delete_cb;
|
||||
#endif
|
||||
cfg->exec_cb = luavgl_anim_exec_cb;
|
||||
|
||||
/* leave only anim userdata and para table on stack */
|
||||
@@ -281,13 +285,13 @@ static int luavgl_anim_create(lua_State *L)
|
||||
luavgl_anim_set(L);
|
||||
lua_pop(L, 1); /* anim */
|
||||
|
||||
debug("create anim: %p, aa: %p\n", a, a->aa);
|
||||
LV_LOG_INFO("create anim: %p, aa: %p", a, a->aa);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int luavgl_anim_gc(lua_State *L)
|
||||
{
|
||||
debug("\n");
|
||||
LV_LOG_INFO("enter");
|
||||
luavgl_anim_t *a = luaL_checkudata(L, 1, "lv_anim");
|
||||
if (a->deleted)
|
||||
return 0;
|
||||
|
||||
@@ -31,8 +31,6 @@ static void luavgl_event_code_init(lua_State* L)
|
||||
lua_pushstring(L, "DRAW_POST_BEGIN"); lua_pushinteger(L, LV_EVENT_DRAW_POST_BEGIN); lua_settable(L, -3);
|
||||
lua_pushstring(L, "DRAW_POST"); lua_pushinteger(L, LV_EVENT_DRAW_POST); lua_settable(L, -3);
|
||||
lua_pushstring(L, "DRAW_POST_END"); lua_pushinteger(L, LV_EVENT_DRAW_POST_END); lua_settable(L, -3);
|
||||
lua_pushstring(L, "DRAW_PART_BEGIN"); lua_pushinteger(L, LV_EVENT_DRAW_PART_BEGIN); lua_settable(L, -3);
|
||||
lua_pushstring(L, "DRAW_PART_END"); lua_pushinteger(L, LV_EVENT_DRAW_PART_END); lua_settable(L, -3);
|
||||
lua_pushstring(L, "VALUE_CHANGED"); lua_pushinteger(L, LV_EVENT_VALUE_CHANGED); lua_settable(L, -3);
|
||||
lua_pushstring(L, "INSERT"); lua_pushinteger(L, LV_EVENT_INSERT); lua_settable(L, -3);
|
||||
lua_pushstring(L, "REFRESH"); lua_pushinteger(L, LV_EVENT_REFRESH); lua_settable(L, -3);
|
||||
@@ -117,7 +115,6 @@ static void luavgl_part_init(lua_State* L)
|
||||
lua_pushstring(L, "KNOB"); lua_pushinteger(L, LV_PART_KNOB); lua_settable(L, -3);
|
||||
lua_pushstring(L, "SELECTED"); lua_pushinteger(L, LV_PART_SELECTED); lua_settable(L, -3);
|
||||
lua_pushstring(L, "ITEMS"); lua_pushinteger(L, LV_PART_ITEMS); lua_settable(L, -3);
|
||||
lua_pushstring(L, "TICKS"); lua_pushinteger(L, LV_PART_TICKS); lua_settable(L, -3);
|
||||
lua_pushstring(L, "CURSOR"); lua_pushinteger(L, LV_PART_CURSOR); lua_settable(L, -3);
|
||||
lua_pushstring(L, "CUSTOM_FIRST"); lua_pushinteger(L, LV_PART_CUSTOM_FIRST); lua_settable(L, -3);
|
||||
lua_pushstring(L, "ANY"); lua_pushinteger(L, LV_PART_ANY); lua_settable(L, -3);
|
||||
@@ -316,13 +313,15 @@ static void luavgl_scr_load_anim_init(lua_State* L)
|
||||
lua_pushstring(L, "MOVE_RIGHT"); lua_pushinteger(L, LV_SCR_LOAD_ANIM_MOVE_RIGHT); lua_settable(L, -3);
|
||||
lua_pushstring(L, "MOVE_TOP"); lua_pushinteger(L, LV_SCR_LOAD_ANIM_MOVE_TOP); lua_settable(L, -3);
|
||||
lua_pushstring(L, "MOVE_BOTTOM"); lua_pushinteger(L, LV_SCR_LOAD_ANIM_MOVE_BOTTOM); lua_settable(L, -3);
|
||||
lua_pushstring(L, "FADE_IN"); lua_pushinteger(L, LV_SCR_LOAD_ANIM_FADE_IN); lua_settable(L, -3);
|
||||
lua_pushstring(L, "FADE_ON"); lua_pushinteger(L, LV_SCR_LOAD_ANIM_FADE_ON); lua_settable(L, -3);
|
||||
#if LV_VERSION_CHECK(8, 3, 0)
|
||||
lua_pushstring(L, "FADE_IN"); lua_pushinteger(L, LV_SCR_LOAD_ANIM_FADE_IN); lua_settable(L, -3);
|
||||
lua_pushstring(L, "FADE_OUT"); lua_pushinteger(L, LV_SCR_LOAD_ANIM_FADE_OUT); lua_settable(L, -3);
|
||||
lua_pushstring(L, "OUT_LEFT"); lua_pushinteger(L, LV_SCR_LOAD_ANIM_OUT_LEFT); lua_settable(L, -3);
|
||||
lua_pushstring(L, "OUT_RIGHT"); lua_pushinteger(L, LV_SCR_LOAD_ANIM_OUT_RIGHT); lua_settable(L, -3);
|
||||
lua_pushstring(L, "OUT_TOP"); lua_pushinteger(L, LV_SCR_LOAD_ANIM_OUT_TOP); lua_settable(L, -3);
|
||||
lua_pushstring(L, "OUT_BOTTOM"); lua_pushinteger(L, LV_SCR_LOAD_ANIM_OUT_BOTTOM); lua_settable(L, -3);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void luavgl_scrollbar_mode_init(lua_State* L)
|
||||
@@ -347,6 +346,7 @@ static void luavgl_dir_init(lua_State* L)
|
||||
lua_pushstring(L, "ALL"); lua_pushinteger(L, LV_DIR_ALL); lua_settable(L, -3);
|
||||
}
|
||||
|
||||
#if LV_USE_KEYBOARD
|
||||
static void luavgl_keyboard_mode_init(lua_State* L)
|
||||
{
|
||||
lua_newtable(L);
|
||||
@@ -363,6 +363,7 @@ static void luavgl_keyboard_mode_init(lua_State* L)
|
||||
lua_pushstring(L, "TEXT_ARABIC"); lua_pushinteger(L, LV_KEYBOARD_MODE_TEXT_ARABIC); lua_settable(L, -3);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
static void luavgl_flex_flow_init(lua_State* L)
|
||||
{
|
||||
@@ -401,12 +402,14 @@ static void luavgl_grid_align_init(lua_State* L)
|
||||
lua_pushstring(L, "SPACE_BETWEEN"); lua_pushinteger(L, LV_GRID_ALIGN_SPACE_BETWEEN); lua_settable(L, -3);
|
||||
}
|
||||
|
||||
#if LV_USE_ROLLER
|
||||
static void luavgl_roller_mode_init(lua_State* L)
|
||||
{
|
||||
lua_newtable(L);
|
||||
lua_pushstring(L, "NORMAL"); lua_pushinteger(L, LV_ROLLER_MODE_NORMAL); lua_settable(L, -3);
|
||||
lua_pushstring(L, "INFINITE"); lua_pushinteger(L, LV_ROLLER_MODE_INFINITE); lua_settable(L, -3);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void luavgl_key_init(lua_State* L)
|
||||
{
|
||||
@@ -479,16 +482,22 @@ static void luavgl_constants_init(lua_State *L)
|
||||
lua_setfield(L, -2, "SCROLLBAR_MODE");
|
||||
luavgl_dir_init(L);
|
||||
lua_setfield(L, -2, "DIR");
|
||||
|
||||
#if LV_USE_KEYBOARD
|
||||
luavgl_keyboard_mode_init(L);
|
||||
lua_setfield(L, -2, "KEYBOARD_MODE");
|
||||
#endif
|
||||
|
||||
luavgl_flex_flow_init(L);
|
||||
lua_setfield(L, -2, "FLEX_FLOW");
|
||||
luavgl_flex_align_init(L);
|
||||
lua_setfield(L, -2, "FLEX_ALIGN");
|
||||
luavgl_grid_align_init(L);
|
||||
lua_setfield(L, -2, "GRID_ALIGN");
|
||||
#if LV_USE_ROLLER
|
||||
luavgl_roller_mode_init(L);
|
||||
lua_setfield(L, -2, "ROLLER_MODE");
|
||||
#endif
|
||||
luavgl_key_init(L);
|
||||
lua_setfield(L, -2, "KEY");
|
||||
/* miscellaneous. */
|
||||
@@ -515,8 +524,8 @@ static void luavgl_constants_init(lua_State *L)
|
||||
lua_pushinteger(L, LV_COORD_MIN);
|
||||
lua_setfield(L, -2, "COORD_MIN");
|
||||
|
||||
lua_pushinteger(L, LV_IMG_ZOOM_NONE);
|
||||
lua_setfield(L, -2, "IMG_ZOOM_NONE");
|
||||
lua_pushinteger(L, LV_ZOOM_NONE);
|
||||
lua_setfield(L, -2, "LV_ZOOM_NONE");
|
||||
|
||||
lua_pushinteger(L, LV_BTNMATRIX_BTN_NONE);
|
||||
lua_setfield(L, -2, "BTNMATRIX_BTN_NONE");
|
||||
@@ -524,8 +533,10 @@ static void luavgl_constants_init(lua_State *L)
|
||||
lua_pushinteger(L, LV_CHART_POINT_NONE);
|
||||
lua_setfield(L, -2, "CHART_POINT_NONE");
|
||||
|
||||
#if LV_USE_DROPDOWN
|
||||
lua_pushinteger(L, LV_DROPDOWN_POS_LAST);
|
||||
lua_setfield(L, -2, "DROPDOWN_POS_LAST");
|
||||
#endif
|
||||
|
||||
lua_pushinteger(L, LV_LABEL_DOT_NUM);
|
||||
lua_setfield(L, -2, "LABEL_DOT_NUM");
|
||||
@@ -537,8 +548,10 @@ static void luavgl_constants_init(lua_State *L)
|
||||
lua_pushinteger(L, LV_TABLE_CELL_NONE);
|
||||
lua_setfield(L, -2, "TABLE_CELL_NONE");
|
||||
|
||||
#if LV_USE_TEXTAREA
|
||||
lua_pushinteger(L, LV_TEXTAREA_CURSOR_LAST);
|
||||
lua_setfield(L, -2, "TEXTAREA_CURSOR_LAST");
|
||||
#endif
|
||||
|
||||
lua_pushinteger(L, LV_LAYOUT_FLEX);
|
||||
lua_setfield(L, -2, "LAYOUT_FLEX");
|
||||
|
||||
+40
-78
@@ -48,7 +48,10 @@ static int luavgl_disp_get_default(lua_State *L)
|
||||
|
||||
static int luavgl_disp_get_scr_act(lua_State *L)
|
||||
{
|
||||
lv_disp_t *disp = luavgl_to_disp(L, 1);
|
||||
lv_disp_t *disp = NULL;
|
||||
if (!lua_isnoneornil(L, 1))
|
||||
disp = luavgl_to_disp(L, 1);
|
||||
|
||||
lv_obj_t *obj = lv_disp_get_scr_act(disp);
|
||||
if (obj == NULL) {
|
||||
lua_pushnil(L);
|
||||
@@ -102,8 +105,7 @@ static int luavgl_disp_load_scr(lua_State *L)
|
||||
}
|
||||
|
||||
/* has parameter table */
|
||||
|
||||
lv_scr_load_anim_t anim = LV_SCR_LOAD_ANIM_NONE;
|
||||
lv_screen_load_anim_t anim = LV_SCR_LOAD_ANIM_NONE;
|
||||
uint32_t time = 0;
|
||||
uint32_t delay = 0;
|
||||
bool auto_del = false;
|
||||
@@ -111,38 +113,40 @@ static int luavgl_disp_load_scr(lua_State *L)
|
||||
const char *str;
|
||||
lua_getfield(L, 2, "anim");
|
||||
str = lua_tostring(L, -1);
|
||||
if (str == NULL || strcmp(str, "none") == 0) {
|
||||
if (str == NULL || lv_strcmp(str, "none") == 0) {
|
||||
; /* use default */
|
||||
} else if (strcmp(str, "over_left") == 0) {
|
||||
} else if (lv_strcmp(str, "over_left") == 0) {
|
||||
anim = LV_SCR_LOAD_ANIM_OVER_LEFT;
|
||||
} else if (strcmp(str, "over_right") == 0) {
|
||||
} else if (lv_strcmp(str, "over_right") == 0) {
|
||||
anim = LV_SCR_LOAD_ANIM_OVER_RIGHT;
|
||||
} else if (strcmp(str, "over_top") == 0) {
|
||||
} else if (lv_strcmp(str, "over_top") == 0) {
|
||||
anim = LV_SCR_LOAD_ANIM_OVER_TOP;
|
||||
} else if (strcmp(str, "over_botto") == 0) {
|
||||
} else if (lv_strcmp(str, "over_botto") == 0) {
|
||||
anim = LV_SCR_LOAD_ANIM_OVER_BOTTOM;
|
||||
} else if (strcmp(str, "move_left") == 0) {
|
||||
} else if (lv_strcmp(str, "move_left") == 0) {
|
||||
anim = LV_SCR_LOAD_ANIM_MOVE_LEFT;
|
||||
} else if (strcmp(str, "move_right") == 0) {
|
||||
} else if (lv_strcmp(str, "move_right") == 0) {
|
||||
anim = LV_SCR_LOAD_ANIM_MOVE_RIGHT;
|
||||
} else if (strcmp(str, "move_top") == 0) {
|
||||
} else if (lv_strcmp(str, "move_top") == 0) {
|
||||
anim = LV_SCR_LOAD_ANIM_MOVE_TOP;
|
||||
} else if (strcmp(str, "move_botto") == 0) {
|
||||
} else if (lv_strcmp(str, "move_botto") == 0) {
|
||||
anim = LV_SCR_LOAD_ANIM_MOVE_BOTTOM;
|
||||
} else if (strcmp(str, "fade_in") == 0) {
|
||||
anim = LV_SCR_LOAD_ANIM_FADE_IN;
|
||||
} else if (strcmp(str, "fade_on") == 0) {
|
||||
} else if (lv_strcmp(str, "fade_on") == 0) {
|
||||
anim = LV_SCR_LOAD_ANIM_FADE_ON;
|
||||
} else if (strcmp(str, "fade_out") == 0) {
|
||||
#if LV_VERSION_CHECK(8, 3, 0)
|
||||
} else if (lv_strcmp(str, "fade_in") == 0) {
|
||||
anim = LV_SCR_LOAD_ANIM_FADE_IN;
|
||||
} else if (lv_strcmp(str, "fade_out") == 0) {
|
||||
anim = LV_SCR_LOAD_ANIM_FADE_OUT;
|
||||
} else if (strcmp(str, "out_left") == 0) {
|
||||
} else if (lv_strcmp(str, "out_left") == 0) {
|
||||
anim = LV_SCR_LOAD_ANIM_OUT_LEFT;
|
||||
} else if (strcmp(str, "out_right") == 0) {
|
||||
} else if (lv_strcmp(str, "out_right") == 0) {
|
||||
anim = LV_SCR_LOAD_ANIM_OUT_RIGHT;
|
||||
} else if (strcmp(str, "out_top") == 0) {
|
||||
} else if (lv_strcmp(str, "out_top") == 0) {
|
||||
anim = LV_SCR_LOAD_ANIM_OUT_TOP;
|
||||
} else if (strcmp(str, "out_bottom") == 0) {
|
||||
} else if (lv_strcmp(str, "out_bottom") == 0) {
|
||||
anim = LV_SCR_LOAD_ANIM_OUT_BOTTOM;
|
||||
#endif
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
|
||||
@@ -158,7 +162,7 @@ static int luavgl_disp_load_scr(lua_State *L)
|
||||
auto_del = luavgl_tointeger(L, -1);
|
||||
lua_pop(L, 1);
|
||||
|
||||
lv_scr_load_anim(obj, anim, time, delay, auto_del);
|
||||
lv_screen_load_anim(obj, anim, time, delay, auto_del);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -202,47 +206,6 @@ static int luavgl_disp_get_layer_sys(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int luavgl_disp_set_bg_color(lua_State *L)
|
||||
{
|
||||
luavgl_disp_t *d = luavgl_check_disp(L, 1);
|
||||
lv_color_t c = luavgl_tocolor(L, 2);
|
||||
|
||||
lv_disp_set_bg_color(d->disp, c);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int luavgl_disp_set_bg_image(lua_State *L)
|
||||
{
|
||||
luavgl_disp_t *d = luavgl_check_disp(L, 1);
|
||||
const char *img = luavgl_toimgsrc(L, 2);
|
||||
|
||||
lv_disp_set_bg_image(d->disp, img);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int luavgl_disp_set_bg_opa(lua_State *L)
|
||||
{
|
||||
luavgl_disp_t *d = luavgl_check_disp(L, 1);
|
||||
lv_opa_t opa = luavgl_tointeger(L, 2);
|
||||
lv_disp_set_bg_opa(d->disp, opa);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int luavgl_disp_get_chroma_key_color(lua_State *L)
|
||||
{
|
||||
#if LVGL_VERSION_MAJOR >= 9
|
||||
luavgl_disp_t *d = luavgl_check_disp(L, 1);
|
||||
lv_color_t c = lv_disp_get_chroma_key_color(d->disp);
|
||||
lua_pushinteger(L, c.full);
|
||||
#else
|
||||
lua_pushinteger(L, 0);
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int luavgl_disp_get_next(lua_State *L)
|
||||
{
|
||||
lv_disp_t *disp = NULL;
|
||||
@@ -272,20 +235,20 @@ static int luavgl_disp_set_rotation(lua_State *L)
|
||||
luavgl_disp_t *d = luavgl_check_disp(L, 1);
|
||||
uint32_t r = lua_tointeger(L, 2);
|
||||
|
||||
lv_disp_rot_t rot;
|
||||
lv_display_rotation_t rot;
|
||||
if (r == 0)
|
||||
rot = LV_DISP_ROT_NONE;
|
||||
rot = LV_DISPLAY_ROTATION_0;
|
||||
else if (r == 90)
|
||||
rot = LV_DISP_ROT_90;
|
||||
rot = LV_DISPLAY_ROTATION_90;
|
||||
else if (r == 180)
|
||||
rot = LV_DISP_ROT_180;
|
||||
rot = LV_DISPLAY_ROTATION_180;
|
||||
else if (r == 270)
|
||||
rot = LV_DISP_ROT_270;
|
||||
rot = LV_DISPLAY_ROTATION_270;
|
||||
else {
|
||||
return luaL_argerror(L, 2, "invalid rotation value");
|
||||
}
|
||||
|
||||
lv_disp_set_rotation(d->disp, rot);
|
||||
lv_display_set_rotation(d->disp, rot);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -306,17 +269,16 @@ static const luaL_Reg disp_lib[] = {
|
||||
** methods for disp handles
|
||||
*/
|
||||
static const luaL_Reg disp_methods[] = {
|
||||
{"get_layer_top", luavgl_disp_get_layer_top },
|
||||
{"get_layer_sys", luavgl_disp_get_layer_sys },
|
||||
{"set_bg_color", luavgl_disp_set_bg_color },
|
||||
{"set_bg_image", luavgl_disp_set_bg_image },
|
||||
{"set_bg_opa", luavgl_disp_set_bg_opa },
|
||||
{"get_chroma_key_color", luavgl_disp_get_chroma_key_color},
|
||||
{"get_next", luavgl_disp_get_next },
|
||||
{"set_rotation", luavgl_disp_set_rotation },
|
||||
{"get_res", luavgl_disp_get_res },
|
||||
{"get_layer_top", luavgl_disp_get_layer_top},
|
||||
{"get_layer_sys", luavgl_disp_get_layer_sys},
|
||||
{"get_next", luavgl_disp_get_next },
|
||||
{"set_rotation", luavgl_disp_set_rotation },
|
||||
{"get_res", luavgl_disp_get_res },
|
||||
|
||||
{NULL, NULL },
|
||||
{"get_scr_act", luavgl_disp_get_scr_act },
|
||||
{"get_scr_prev", luavgl_disp_get_scr_prev },
|
||||
|
||||
{NULL, NULL },
|
||||
};
|
||||
|
||||
static const luaL_Reg disp_meta[] = {
|
||||
|
||||
+85
-95
@@ -1,36 +1,29 @@
|
||||
#include "luavgl.h"
|
||||
#include "private.h"
|
||||
|
||||
#include "esp_heap_caps.h"
|
||||
|
||||
static void luavgl_obj_event_cb(lv_event_t *e)
|
||||
{
|
||||
lua_State *L = e->user_data;
|
||||
if (L == NULL) {
|
||||
debug("Null user data, should be L.\n");
|
||||
}
|
||||
struct event_callback_s *event = e->user_data;
|
||||
if (event == NULL)
|
||||
return;
|
||||
|
||||
lua_State *L = event->L;
|
||||
int top = lua_gettop(L);
|
||||
lv_obj_t *obj = e->current_target;
|
||||
|
||||
lua_pushlightuserdata(L, obj);
|
||||
lua_rawget(L, LUA_REGISTRYINDEX);
|
||||
luavgl_obj_t *lobj = luavgl_to_lobj(L, -1);
|
||||
if (lobj == NULL || lobj->obj == NULL)
|
||||
goto event_exit;
|
||||
|
||||
int ref = LUA_NOREF;
|
||||
for (int i = 0; i < lobj->n_events; i++) {
|
||||
if (lobj->events[i].code == LV_EVENT_ALL ||
|
||||
lobj->events[i].code == e->code) {
|
||||
ref = lobj->events[i].ref;
|
||||
break;
|
||||
}
|
||||
if (lobj == NULL || lobj->obj == NULL) {
|
||||
lua_settop(L, top);
|
||||
return;
|
||||
}
|
||||
|
||||
int ref = event->ref;
|
||||
if (ref == LUA_NOREF) {
|
||||
/* nobody cares this event, something went wrong but can be ignored. */
|
||||
goto event_exit;
|
||||
lua_settop(L, top);
|
||||
return;
|
||||
}
|
||||
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, ref);
|
||||
@@ -41,27 +34,13 @@ static void luavgl_obj_event_cb(lv_event_t *e)
|
||||
|
||||
/* args: obj, code */
|
||||
luavgl_pcall_int(L, 2, 0);
|
||||
|
||||
event_exit:
|
||||
lua_settop(L, top);
|
||||
}
|
||||
|
||||
static void luavgl_obj_remove_event(lua_State *L, lv_obj_t *obj,
|
||||
struct event_callback_s *event)
|
||||
{
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, event->ref);
|
||||
event->code = -1; /* mark it as unused. */
|
||||
event->ref = LUA_NOREF;
|
||||
lv_obj_remove_event_dsc(obj, event->dsc);
|
||||
event->dsc = NULL;
|
||||
}
|
||||
|
||||
/* obj:onevent(luavgl.EVENT.PRESSED, function(code, value) -- end) */
|
||||
static int luavgl_obj_on_event(lua_State *L)
|
||||
{
|
||||
bool remove_all; /* if third parameter is noneornil, remove all events. */
|
||||
|
||||
luavgl_obj_t *lobj = luavgl_to_lobj(L, 1);
|
||||
|
||||
lv_obj_t *obj = lobj->obj;
|
||||
if (obj == NULL) {
|
||||
luaL_argerror(L, 1, "expect obj userdata.\n");
|
||||
@@ -74,68 +53,68 @@ static int luavgl_obj_on_event(lua_State *L)
|
||||
return 0;
|
||||
}
|
||||
|
||||
remove_all = lua_isnoneornil(L, 3);
|
||||
int size = lv_array_size(&lobj->events);
|
||||
struct event_callback_s *event = NULL;
|
||||
struct event_callback_s **events = lv_array_front(&lobj->events);
|
||||
|
||||
/* check if event code already added, find a slot to store this callback */
|
||||
int slot = 0;
|
||||
if (lobj && lobj->events) {
|
||||
for (; slot < lobj->n_events; slot++) {
|
||||
struct event_callback_s *event = &lobj->events[slot];
|
||||
if (event->code == code) { /* same event can only be added once. */
|
||||
luavgl_obj_remove_event(L, obj, event);
|
||||
if (remove_all)
|
||||
continue; /* continue to remove all events associated. */
|
||||
else
|
||||
break; /* use this slot for our new event callback */
|
||||
}
|
||||
/* if third parameter is none or nil, remove this events */
|
||||
if (lua_isnoneornil(L, 3)) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
event = events[i];
|
||||
if (event->code == code) {
|
||||
events[i] = NULL; /* Remove it from array */
|
||||
lv_result_t res = lv_obj_remove_event_dsc(lobj->obj, event->dsc);
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, event->ref);
|
||||
event->dsc = NULL;
|
||||
event->L = NULL;
|
||||
event->ref = LUA_NOREF;
|
||||
event->code = _LV_EVENT_LAST;
|
||||
if (res != LV_RESULT_OK) {
|
||||
return luaL_error(L, "Failed to remove event dsc: %d\n", res);
|
||||
}
|
||||
|
||||
if (event->code == -1) {
|
||||
/* this callback has been removed, thus, we can use this slot */
|
||||
break;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return luaL_error(L, "No such event to remove: %d", code);
|
||||
}
|
||||
|
||||
/* Check if the event code already exists, only one callback per code. */
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (events[i]->code == code) {
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, event->ref);
|
||||
event = events[i];
|
||||
break;
|
||||
}
|
||||
|
||||
if (events[i]->code == _LV_EVENT_LAST) {
|
||||
/* code marked as _LV_EVENT_LAST means this event has been removed, we can
|
||||
* reuse it. */
|
||||
event = events[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (remove_all) /* no need to add, just return */
|
||||
return 0;
|
||||
|
||||
struct event_callback_s *events = lobj->events;
|
||||
|
||||
/* create obj->lobj->events, if NULL, realloc if existing and find no slot
|
||||
*/
|
||||
if (events == NULL) {
|
||||
events =
|
||||
heap_caps_calloc(sizeof(struct event_callback_s), 1, MALLOC_CAP_SPIRAM);
|
||||
if (events == NULL) {
|
||||
return luaL_error(L, "No memory.");
|
||||
if (event == NULL) {
|
||||
/* Create a new one if not exist */
|
||||
event = lv_malloc_zeroed(sizeof(*event));
|
||||
if (event == NULL) {
|
||||
return luaL_error(L, "No memory");
|
||||
}
|
||||
|
||||
lobj->events = events;
|
||||
lobj->n_events = 1;
|
||||
} else {
|
||||
/* realloc? */
|
||||
if (slot && slot == lobj->n_events) {
|
||||
struct event_callback_s *_events;
|
||||
_events = heap_caps_realloc(lobj->events,
|
||||
(lobj->n_events + 1) * sizeof(*_events),
|
||||
MALLOC_CAP_SPIRAM);
|
||||
if (_events == NULL) {
|
||||
return luaL_error(L, "No memory.");
|
||||
}
|
||||
events = _events;
|
||||
lobj->n_events++; /* now we have +1 event */
|
||||
lobj->events = events;
|
||||
}
|
||||
/* else: we have found a slot to reuse, use it. */
|
||||
lv_array_push_back(&lobj->events, &event);
|
||||
LV_LOG_INFO("obj: %p, push back event: %d", obj, code);
|
||||
}
|
||||
|
||||
/* setup event callback */
|
||||
|
||||
void *dsc = lv_obj_add_event_cb(obj, luavgl_obj_event_cb, code, L);
|
||||
struct event_callback_s *event = &events[slot];
|
||||
event->code = code;
|
||||
event->L = L;
|
||||
event->ref = luavgl_check_continuation(L, 3);
|
||||
event->dsc = dsc;
|
||||
event->dsc = lv_obj_add_event_cb(obj, luavgl_obj_event_cb, code, event);
|
||||
if (event->dsc == NULL) {
|
||||
lv_free(event);
|
||||
return luaL_error(L, "Failed to add event callback");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -169,28 +148,39 @@ static int luavgl_obj_on_pressed(lua_State *L)
|
||||
return luavgl_obj_on_event(L);
|
||||
}
|
||||
|
||||
static void luavgl_obj_event_init(luavgl_obj_t *lobj) { lobj->n_events = 0; }
|
||||
|
||||
/**
|
||||
* Remove all events added, and free memory of events
|
||||
*/
|
||||
static void luavgl_obj_remove_event_all(lua_State *L, luavgl_obj_t *lobj)
|
||||
{
|
||||
if (lobj == NULL || lobj->events == NULL) {
|
||||
if (lobj == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct event_callback_s *events = lobj->events;
|
||||
|
||||
int i = 0;
|
||||
for (; i < lobj->n_events; i++) {
|
||||
struct event_callback_s *event = &lobj->events[i];
|
||||
if (event->code != -1) {
|
||||
luavgl_obj_remove_event(L, lobj->obj, event);
|
||||
int size = lv_array_size(&lobj->events);
|
||||
struct event_callback_s *event;
|
||||
struct event_callback_s **events = lv_array_front(&lobj->events);
|
||||
for (int i = 0; i < size; i++) {
|
||||
event = events[i];
|
||||
if (event == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
events[i] = NULL;
|
||||
|
||||
if (event->dsc == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
lv_result_t res = lv_obj_remove_event_dsc(lobj->obj, event->dsc);
|
||||
if (res != LV_RESULT_OK) {
|
||||
LV_LOG_WARN("Failed to remove event dsc: %d", res);
|
||||
/* Ignore this error, remove from it anyway */
|
||||
}
|
||||
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, event->ref);
|
||||
lv_free(event);
|
||||
}
|
||||
|
||||
free(events);
|
||||
lobj->n_events = 0;
|
||||
lobj->events = NULL;
|
||||
lv_array_deinit(&lobj->events);
|
||||
}
|
||||
|
||||
+59
-18
@@ -5,6 +5,8 @@
|
||||
|
||||
#define _ARRAY_LEN(a) (sizeof(a) / sizeof(a[0]))
|
||||
|
||||
#define NAMED_WEIGHT_MAX_CHARS 16
|
||||
|
||||
/**
|
||||
* Follow css style, specify the name by name family, name size,
|
||||
* name weight. Font weight can be numeric value or 'bold'. Alls strings
|
||||
@@ -159,7 +161,7 @@ static int luavgl_get_named_weight(const char *name)
|
||||
}
|
||||
|
||||
for (int i = 0; i < _ARRAY_LEN(g_named_weight); i++) {
|
||||
if (strcmp(name, g_named_weight[i].name) == 0) {
|
||||
if (lv_strcmp(name, g_named_weight[i].name) == 0) {
|
||||
return g_named_weight[i].value;
|
||||
}
|
||||
}
|
||||
@@ -178,7 +180,7 @@ static const lv_font_t *_luavgl_font_create(lua_State *L, const char *name,
|
||||
int size, int weight)
|
||||
{
|
||||
/* check builtin font firstly. */
|
||||
if (strcmp(name, "montserrat") == 0) {
|
||||
if (lv_strcmp(name, "montserrat") == 0) {
|
||||
if (FONT_WEIGHT_NORMAL != weight)
|
||||
return NULL;
|
||||
|
||||
@@ -187,7 +189,7 @@ static const lv_font_t *_luavgl_font_create(lua_State *L, const char *name,
|
||||
return g_builtin_montserrat[i].font;
|
||||
}
|
||||
}
|
||||
} else if (strcmp(name, "unscii") == 0) {
|
||||
} else if (lv_strcmp(name, "unscii") == 0) {
|
||||
if (FONT_WEIGHT_NORMAL != weight)
|
||||
return NULL;
|
||||
#if LV_FONT_UNSCII_8
|
||||
@@ -200,21 +202,15 @@ static const lv_font_t *_luavgl_font_create(lua_State *L, const char *name,
|
||||
return &lv_font_unscii_16;
|
||||
#endif
|
||||
}
|
||||
#if LV_FONT_MONTSERRAT_12_SUBPX
|
||||
else if (strcmp(name, "montserrat_subpx") == 0) {
|
||||
if (size == 12)
|
||||
return &lv_font_montserrat_12_subpx;
|
||||
}
|
||||
#endif
|
||||
#if LV_FONT_DEJAVU_16_PERSIAN_HEBREW
|
||||
else if (strcmp(name, "dejavu_persian_hebrew") == 0) {
|
||||
else if (lv_strcmp(name, "dejavu_persian_hebrew") == 0) {
|
||||
if (size == 16)
|
||||
return &lv_font_dejavu_16_persian_hebrew;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if LV_FONT_SIMSUN_16_CJK
|
||||
else if (strcmp(name, "dejavu_persian_hebrew") == 0) {
|
||||
else if (lv_strcmp(name, "dejavu_persian_hebrew") == 0) {
|
||||
if (size == 16)
|
||||
return &lv_font_simsun_16_cjk;
|
||||
}
|
||||
@@ -229,6 +225,17 @@ static const lv_font_t *_luavgl_font_create(lua_State *L, const char *name,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static char *luavgl_strchr(const char *s, char c)
|
||||
{
|
||||
while (*s) {
|
||||
if (c == *s) {
|
||||
return (char *)s;
|
||||
}
|
||||
s++;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamic font family fallback is not supported.
|
||||
* The fallback only happen when font creation fails and continue to try next
|
||||
@@ -240,7 +247,7 @@ static int luavgl_font_create(lua_State *L)
|
||||
{
|
||||
int weight;
|
||||
int size;
|
||||
const char *name;
|
||||
char *str, *name;
|
||||
const lv_font_t *font = NULL;
|
||||
|
||||
if (!lua_isstring(L, 1)) {
|
||||
@@ -258,26 +265,60 @@ static int luavgl_font_create(lua_State *L)
|
||||
weight = lua_tointeger(L, 3);
|
||||
} else {
|
||||
char *luastr = (char *)lua_tostring(L, 3);
|
||||
int len = strlen(luastr);
|
||||
int len = lv_strlen(luastr);
|
||||
if (len > 128) {
|
||||
/* not likely to happen */
|
||||
return luaL_argerror(L, 3, "too long");
|
||||
}
|
||||
char s[len + 1];
|
||||
strcpy(s, luastr);
|
||||
char s[NAMED_WEIGHT_MAX_CHARS];
|
||||
if (len + 1 > NAMED_WEIGHT_MAX_CHARS) {
|
||||
return luaL_argerror(L, 3, "too long");
|
||||
}
|
||||
|
||||
lv_strcpy(s, luastr);
|
||||
weight = luavgl_get_named_weight(to_lower(s));
|
||||
}
|
||||
} else {
|
||||
weight = FONT_WEIGHT_NORMAL;
|
||||
}
|
||||
|
||||
name = lua_tostring(L, 1);
|
||||
font = _luavgl_font_create(L, name, size, weight);
|
||||
str = lv_strdup(lua_tostring(L, 1));
|
||||
if (str == NULL) {
|
||||
return luaL_error(L, "no memory");
|
||||
}
|
||||
|
||||
name = to_lower(str);
|
||||
while (*name) {
|
||||
if (*name == ' ') {
|
||||
name++;
|
||||
continue;
|
||||
}
|
||||
|
||||
char *end = luavgl_strchr(name, ',');
|
||||
if (end != NULL) {
|
||||
*end = '\0';
|
||||
} else {
|
||||
end = name + lv_strlen(name);
|
||||
}
|
||||
|
||||
char *trim = end - 1;
|
||||
while (*trim == ' ') {
|
||||
*trim-- = '\0'; /* trailing space. */
|
||||
}
|
||||
|
||||
font = _luavgl_font_create(L, name, size, weight);
|
||||
if (font) {
|
||||
break;
|
||||
}
|
||||
|
||||
name = end + 1; /* next */
|
||||
}
|
||||
|
||||
lv_free(str);
|
||||
if (font) {
|
||||
lua_pushlightuserdata(L, (void *)font);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return luaL_error(L, "cannot create font.");
|
||||
return luaL_error(L, "cannot create font");
|
||||
}
|
||||
|
||||
+10
-10
@@ -47,15 +47,15 @@ static int luavgl_fs_open(lua_State *L)
|
||||
f->closed = false;
|
||||
|
||||
lv_fs_mode_t lmode = 0;
|
||||
if (strchr(mode, 'r'))
|
||||
if (luavgl_strchr(mode, 'r'))
|
||||
lmode |= LV_FS_MODE_RD;
|
||||
|
||||
if (strchr(mode, 'w'))
|
||||
if (luavgl_strchr(mode, 'w'))
|
||||
lmode |= LV_FS_MODE_WR;
|
||||
|
||||
lv_fs_res_t res = lv_fs_open(&f->file, path, lmode);
|
||||
if (res != LV_FS_RES_OK) {
|
||||
debug("open failed: %s\n", path);
|
||||
LV_LOG_ERROR("open failed: %s", path);
|
||||
lua_pushnil(L);
|
||||
lua_pushfstring(L, "open failed: %s\n", path);
|
||||
lua_pushinteger(L, res); /* return lv_fs error number */
|
||||
@@ -152,7 +152,7 @@ static int luavgl_fs_write(lua_State *L)
|
||||
int arg = 2;
|
||||
int nargs = lua_gettop(L) - arg;
|
||||
int status = 1;
|
||||
lv_fs_res_t res = 0;
|
||||
lv_fs_res_t res;
|
||||
size_t l;
|
||||
uint32_t nw;
|
||||
const char *s;
|
||||
@@ -183,7 +183,7 @@ static int luavgl_fs_close(lua_State *L)
|
||||
{
|
||||
luavgl_fs_t *f = luavgl_to_fs(L, 1);
|
||||
|
||||
debug("\n");
|
||||
LV_LOG_INFO("enter");
|
||||
f->closed = true;
|
||||
lv_fs_close(&f->file);
|
||||
|
||||
@@ -228,7 +228,7 @@ static int luavgl_fs_tostring(lua_State *L)
|
||||
|
||||
static int luavgl_fs_gc(lua_State *L)
|
||||
{
|
||||
debug("\n");
|
||||
LV_LOG_INFO("enter");
|
||||
|
||||
luavgl_fs_t *v = luaL_checkudata(L, 1, "lv_fs");
|
||||
if (!v->closed) {
|
||||
@@ -251,7 +251,7 @@ static int luavgl_dir_open(lua_State *L)
|
||||
|
||||
lv_fs_res_t res = lv_fs_dir_open(&d->dir, path);
|
||||
if (res != LV_FS_RES_OK) {
|
||||
debug("open failed: %s\n", path);
|
||||
LV_LOG_ERROR("open failed: %s", path);
|
||||
lua_pushnil(L);
|
||||
lua_pushfstring(L, "open failed: %s\n", path);
|
||||
lua_pushinteger(L, res); /* return lv_fs error number */
|
||||
@@ -268,7 +268,7 @@ static int luavgl_dir_read(lua_State *L)
|
||||
{
|
||||
luavgl_dir_t *d = luavgl_to_dir(L, 1);
|
||||
char buffer[PATH_MAX];
|
||||
lv_fs_res_t res = lv_fs_dir_read(&d->dir, buffer);
|
||||
lv_fs_res_t res = lv_fs_dir_read(&d->dir, buffer, sizeof(buffer));
|
||||
if (res != LV_FS_RES_OK || buffer[0] == '\0') {
|
||||
lua_pushnil(L);
|
||||
} else {
|
||||
@@ -280,7 +280,7 @@ static int luavgl_dir_read(lua_State *L)
|
||||
|
||||
static int luavgl_dir_close(lua_State *L)
|
||||
{
|
||||
debug("\n");
|
||||
LV_LOG_INFO("error");
|
||||
luavgl_dir_t *d = luavgl_to_dir(L, 1);
|
||||
d->closed = true;
|
||||
lv_fs_dir_close(&d->dir);
|
||||
@@ -295,7 +295,7 @@ static int luavgl_dir_tostring(lua_State *L)
|
||||
|
||||
static int luavgl_dir_gc(lua_State *L)
|
||||
{
|
||||
debug("\n");
|
||||
LV_LOG_INFO("enter");
|
||||
|
||||
luavgl_dir_t *v = luaL_checkudata(L, 1, "lv_dir");
|
||||
if (!v->closed) {
|
||||
|
||||
@@ -87,7 +87,7 @@ static int luavgl_group_delete(lua_State *L)
|
||||
g->group = NULL;
|
||||
#endif
|
||||
|
||||
debug("delete group:%p\n", g);
|
||||
LV_LOG_INFO("delete group:%p", g);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -289,7 +289,7 @@ static int luavgl_group_gc(lua_State *L)
|
||||
g->group = NULL;
|
||||
#endif
|
||||
|
||||
debug("gc group: %p\n", g);
|
||||
LV_LOG_INFO("gc group: %p", g);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
#include "draw/lv_img_buf.h"
|
||||
#include "draw/lv_img_decoder.h"
|
||||
#include "draw/lv_image_decoder.h"
|
||||
#include "lauxlib.h"
|
||||
#include "lua.h"
|
||||
#include "luavgl.h"
|
||||
#include "misc/lv_color.h"
|
||||
#include "misc/lv_mem.h"
|
||||
#include "misc/lv_types.h"
|
||||
#include "private.h"
|
||||
#include "stdlib/lv_mem.h"
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -16,22 +15,21 @@ static int luavgl_imgdata_create(lua_State *L)
|
||||
return luaL_argerror(L, 1, "expect string");
|
||||
}
|
||||
|
||||
lv_img_decoder_dsc_t descriptor;
|
||||
lv_res_t res =
|
||||
lv_img_decoder_open(&descriptor, lua_tostring(L, 1), lv_color_black(), 0);
|
||||
lv_image_decoder_dsc_t descriptor;
|
||||
lv_res_t res = lv_image_decoder_open(&descriptor, lua_tostring(L, 1), NULL);
|
||||
if (res != LV_RES_OK) {
|
||||
return luaL_error(L, "failed to decode image.");
|
||||
}
|
||||
|
||||
lv_img_dsc_t *data = lv_mem_alloc(sizeof(lv_img_dsc_t));
|
||||
lv_image_dsc_t *data = lv_malloc(sizeof(lv_image_dsc_t));
|
||||
data->header = descriptor.header;
|
||||
data->data_size = data->header.w * data->header.h * sizeof(uint32_t); // ???
|
||||
data->data_size = descriptor.decoded->data_size;
|
||||
|
||||
uint8_t *data_copy = lv_mem_alloc(data->data_size);
|
||||
memcpy(data_copy, descriptor.img_data, data->data_size);
|
||||
uint8_t *data_copy = lv_malloc(data->data_size);
|
||||
memcpy(data_copy, descriptor.decoded->data, data->data_size);
|
||||
data->data = data_copy;
|
||||
|
||||
lv_img_decoder_close(&descriptor);
|
||||
lv_image_decoder_close(&descriptor);
|
||||
|
||||
lua_pushlightuserdata(L, data);
|
||||
return 1;
|
||||
|
||||
+13
-4
@@ -55,6 +55,7 @@ static int luavgl_indev_get_act(lua_State *L)
|
||||
return luavgl_indev_get(L, indev);
|
||||
}
|
||||
|
||||
#if 0
|
||||
static int luavgl_indev_get_obj_act(lua_State *L)
|
||||
{
|
||||
lv_obj_t *obj = lv_indev_get_obj_act();
|
||||
@@ -73,6 +74,7 @@ static int luavgl_indev_get_obj_act(lua_State *L)
|
||||
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int luavgl_indev_get_next(lua_State *L)
|
||||
{
|
||||
@@ -201,6 +203,7 @@ static int luavgl_indev_wait_release(lua_State *L)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static void indev_feedback_cb(lv_indev_drv_t *driver, uint8_t code)
|
||||
{
|
||||
lua_State *L = driver->user_data;
|
||||
@@ -249,8 +252,8 @@ static int luavgl_indev_on_event(lua_State *L)
|
||||
lua_setuservalue(L, 1);
|
||||
}
|
||||
|
||||
debug("add feedback_cb code %d, for indev->driver: %p\n", code,
|
||||
i->indev->driver);
|
||||
LV_LOG_INFO("add feedback_cb code %d, for indev->driver: %p\n", code,
|
||||
i->indev->driver);
|
||||
lua_pushvalue(L, 3);
|
||||
lua_rawseti(L, -2, code);
|
||||
|
||||
@@ -259,6 +262,7 @@ static int luavgl_indev_on_event(lua_State *L)
|
||||
lua_settop(L, 1);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int luavgl_indev_tostring(lua_State *L)
|
||||
{
|
||||
@@ -268,8 +272,9 @@ static int luavgl_indev_tostring(lua_State *L)
|
||||
|
||||
static int luavgl_indev_gc(lua_State *L)
|
||||
{
|
||||
debug("\n");
|
||||
LV_LOG_INFO("enter");
|
||||
|
||||
#if 0
|
||||
/* If set_feedback_cb is used, then the indev only gets gc'ed when lua vm
|
||||
* exits.
|
||||
*/
|
||||
@@ -281,6 +286,7 @@ static int luavgl_indev_gc(lua_State *L)
|
||||
lua_rawset(L, LUA_REGISTRYINDEX);
|
||||
i->indev->driver->feedback_cb = NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -290,7 +296,9 @@ static int luavgl_indev_gc(lua_State *L)
|
||||
*/
|
||||
static const luaL_Reg indev_lib[] = {
|
||||
{"get_act", luavgl_indev_get_act },
|
||||
#if 0
|
||||
{"get_obj_act", luavgl_indev_get_obj_act},
|
||||
#endif
|
||||
{"get_next", luavgl_indev_get_next },
|
||||
|
||||
{NULL, NULL },
|
||||
@@ -312,8 +320,9 @@ static const luaL_Reg methods[] = {
|
||||
{"get_scroll_obj", luavgl_indev_get_scroll_obj },
|
||||
{"get_vect", luavgl_indev_get_vect },
|
||||
{"wait_release", luavgl_indev_wait_release },
|
||||
#if 0
|
||||
{"on_event", luavgl_indev_on_event },
|
||||
|
||||
#endif
|
||||
{NULL, NULL },
|
||||
};
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#include "font.c"
|
||||
#include "fs.c"
|
||||
#include "group.c"
|
||||
#include "imgdata.c"
|
||||
#include "indev.c"
|
||||
#include "obj.c"
|
||||
#include "timer.c"
|
||||
@@ -44,7 +43,7 @@ LUALIB_API luavgl_ctx_t *luavgl_context(lua_State *L)
|
||||
/* create it if not exist in registry */
|
||||
lua_pushstring(L, luavglgl_key);
|
||||
ctx = (luavgl_ctx_t *)lua_newuserdata(L, sizeof(*ctx));
|
||||
memset(ctx, 0, sizeof(*ctx));
|
||||
lv_memset(ctx, 0, sizeof(*ctx));
|
||||
lua_rawset(L, LUA_REGISTRYINDEX);
|
||||
} else {
|
||||
ctx = (luavgl_ctx_t *)lua_touserdata(L, -1);
|
||||
@@ -76,7 +75,7 @@ LUALIB_API void luavgl_set_font_extension(lua_State *L, make_font_cb make,
|
||||
|
||||
static int root_gc(lua_State *L)
|
||||
{
|
||||
debug("enter.\n");
|
||||
LV_LOG_INFO("enter");
|
||||
luavgl_ctx_t *ctx = luavgl_context(L);
|
||||
lv_obj_del(ctx->root);
|
||||
return 0;
|
||||
@@ -84,7 +83,7 @@ static int root_gc(lua_State *L)
|
||||
|
||||
static int root_clean(lua_State *L)
|
||||
{
|
||||
debug("enter.\n");
|
||||
LV_LOG_INFO("enter");
|
||||
luavgl_ctx_t *ctx = luavgl_context(L);
|
||||
lv_obj_clean(ctx->root);
|
||||
return 0;
|
||||
@@ -104,7 +103,7 @@ LUALIB_API int luaopen_lvgl(lua_State *L)
|
||||
|
||||
lv_obj_t *root = ctx->root;
|
||||
if (root == NULL) {
|
||||
debug("create root obj for lua.\n");
|
||||
LV_LOG_INFO("create root obj for lua");
|
||||
root = lv_obj_create(lv_scr_act());
|
||||
ctx->root = root;
|
||||
}
|
||||
|
||||
+14
-10
@@ -14,7 +14,7 @@ extern "C" {
|
||||
|
||||
typedef const lv_font_t *(*make_font_cb)(const char *name, int size,
|
||||
int weight);
|
||||
typedef void (*delete_font_cb)(lv_font_t *);
|
||||
typedef void (*delete_font_cb)(const lv_font_t *);
|
||||
typedef int (*luavgl_pcall_t)(lua_State *L, int nargs, int nresults);
|
||||
|
||||
typedef struct {
|
||||
@@ -48,13 +48,17 @@ typedef struct {
|
||||
};
|
||||
} luavgl_value_setter_t;
|
||||
|
||||
struct event_callback_s {
|
||||
lua_State *L;
|
||||
int ref; /* ref to callback */
|
||||
lv_event_code_t code;
|
||||
lv_event_dsc_t *dsc;
|
||||
};
|
||||
|
||||
typedef struct luavgl_obj_s {
|
||||
lv_obj_t *obj; /* NULL means obj deleted, but not gc'ed in lua */
|
||||
bool lua_created; /* this object is created from lua */
|
||||
|
||||
/* internally used variables */
|
||||
int n_events;
|
||||
struct event_callback_s *events;
|
||||
lv_array_t events; /* events added from lua, need it to distinguish between lua */
|
||||
} luavgl_obj_t;
|
||||
|
||||
#define luavgl_obj_newmetatable(L, clz, name, l) \
|
||||
@@ -123,6 +127,11 @@ LUALIB_API luavgl_obj_t *luavgl_add_lobj(lua_State *L, lv_obj_t *obj);
|
||||
*/
|
||||
LUALIB_API luavgl_obj_t *luavgl_to_lobj(lua_State *L, int idx);
|
||||
|
||||
/**
|
||||
* @brief Get lvgl style from stack
|
||||
*/
|
||||
LUALIB_API lv_style_t *luavgl_to_style(lua_State *L, int idx);
|
||||
|
||||
/**
|
||||
* @brief Create metatable for specified object class
|
||||
*
|
||||
@@ -157,11 +166,6 @@ LUALIB_API int luavgl_obj_getuserdatauv(lua_State *L, int idx);
|
||||
*/
|
||||
LUALIB_API lv_obj_t *luavgl_to_obj(lua_State *L, int idx);
|
||||
|
||||
/**
|
||||
* @brief Get lvgl style from stack
|
||||
*/
|
||||
LUALIB_API lv_style_t *luavgl_to_style(lua_State *L, int idx);
|
||||
|
||||
/**
|
||||
* @brief Convert value to integer
|
||||
*
|
||||
|
||||
+268
-172
@@ -1,5 +1,3 @@
|
||||
#include "core/lv_group.h"
|
||||
#include "core/lv_obj.h"
|
||||
#include "luavgl.h"
|
||||
#include "private.h"
|
||||
|
||||
@@ -10,16 +8,18 @@
|
||||
|
||||
static int luavgl_anim_create(lua_State *L);
|
||||
static int luavgl_obj_delete(lua_State *L);
|
||||
static int luavgl_obj_clean(lua_State *L);
|
||||
|
||||
static void _lv_obj_set_align(void *obj, lua_State *L) {
|
||||
static void _lv_obj_set_align(void *obj, lua_State *L)
|
||||
{
|
||||
if (lua_isinteger(L, -1)) {
|
||||
lv_obj_align(obj, lua_tointeger(L, -1), 0, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!lua_istable(L, -1)) {
|
||||
luaL_argerror(L, -1, "should be table.");
|
||||
debug("para should be table.");
|
||||
luaL_argerror(L, -1, "should be table");
|
||||
LV_LOG_ERROR("para should be table");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -43,11 +43,13 @@ static void _lv_obj_set_align(void *obj, lua_State *L) {
|
||||
*
|
||||
* Internally used.
|
||||
*/
|
||||
static inline void luavgl_setup_obj(lua_State *L, lv_obj_t *obj) {
|
||||
static inline void luavgl_setup_obj(lua_State *L, lv_obj_t *obj)
|
||||
{
|
||||
luavgl_iterate(L, -1, luavgl_obj_set_property_kv, obj);
|
||||
}
|
||||
|
||||
static void obj_delete_cb(lv_event_t *e) {
|
||||
static void obj_delete_cb(lv_event_t *e)
|
||||
{
|
||||
lua_State *L = e->user_data;
|
||||
lua_pushlightuserdata(L, e->current_target);
|
||||
lua_rawget(L, LUA_REGISTRYINDEX);
|
||||
@@ -67,7 +69,33 @@ static void obj_delete_cb(lv_event_t *e) {
|
||||
goto pop_exit;
|
||||
}
|
||||
|
||||
luavgl_obj_delete(L);
|
||||
/* Clean its children firstly */
|
||||
luavgl_obj_clean(L);
|
||||
|
||||
/* Remove events added from lua, but keep them unremoved */
|
||||
int size = lv_array_size(&lobj->events);
|
||||
struct event_callback_s *event;
|
||||
struct event_callback_s **events = lv_array_front(&lobj->events);
|
||||
for (int i = 0; i < size; i++) {
|
||||
event = events[i];
|
||||
if (event == NULL || event->dsc == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, event->ref);
|
||||
lv_free(event);
|
||||
}
|
||||
|
||||
lv_array_deinit(&lobj->events);
|
||||
|
||||
/* remove userdata from registry. */
|
||||
lua_checkstack(L, 2);
|
||||
lua_pushlightuserdata(L, lobj->obj);
|
||||
lua_pushnil(L);
|
||||
lua_rawset(L, LUA_REGISTRYINDEX);
|
||||
|
||||
LV_LOG_INFO("delete obj: %p", lobj->obj);
|
||||
lobj->obj = NULL;
|
||||
return;
|
||||
|
||||
pop_exit:
|
||||
@@ -80,7 +108,8 @@ pop_exit:
|
||||
* one. result stack: table(from uservalue)
|
||||
* return uservalue type: LUA_TTABLE
|
||||
*/
|
||||
LUALIB_API int luavgl_obj_getuserdatauv(lua_State *L, int idx) {
|
||||
LUALIB_API int luavgl_obj_getuserdatauv(lua_State *L, int idx)
|
||||
{
|
||||
int type = lua_getuservalue(L, idx);
|
||||
if (type == LUA_TTABLE)
|
||||
return type;
|
||||
@@ -99,11 +128,13 @@ LUALIB_API int luavgl_obj_getuserdatauv(lua_State *L, int idx) {
|
||||
return LUA_TTABLE;
|
||||
}
|
||||
|
||||
static int luavgl_obj_create(lua_State *L) {
|
||||
static int luavgl_obj_create(lua_State *L)
|
||||
{
|
||||
return luavgl_obj_create_helper(L, lv_obj_create);
|
||||
}
|
||||
|
||||
static int luavgl_obj_delete(lua_State *L) {
|
||||
static int luavgl_obj_delete(lua_State *L)
|
||||
{
|
||||
luavgl_obj_t *lobj;
|
||||
|
||||
/**
|
||||
@@ -146,14 +177,15 @@ static int luavgl_obj_delete(lua_State *L) {
|
||||
lua_pushnil(L);
|
||||
lua_rawset(L, LUA_REGISTRYINDEX);
|
||||
|
||||
debug("delete obj: %p\n", lobj->obj);
|
||||
LV_LOG_INFO("delete obj: %p", lobj->obj);
|
||||
lobj->obj = NULL;
|
||||
|
||||
lua_pop(L, 1); /* remove the userdata para */
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int luavgl_obj_clean(lua_State *L) {
|
||||
static int luavgl_obj_clean(lua_State *L)
|
||||
{
|
||||
luavgl_obj_t *lobj = luavgl_to_lobj(L, -1);
|
||||
if (lobj == NULL || lobj->obj == NULL)
|
||||
return 0;
|
||||
@@ -170,31 +202,36 @@ static int luavgl_obj_clean(lua_State *L) {
|
||||
luavgl_obj_delete(L);
|
||||
}
|
||||
|
||||
lua_pop(L, 1); /* remove the userdata para */
|
||||
return 0;
|
||||
lua_settop(L, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int luavgl_obj_set(lua_State *L) {
|
||||
static int luavgl_obj_set(lua_State *L)
|
||||
{
|
||||
lv_obj_t *obj = luavgl_to_obj(L, 1);
|
||||
|
||||
if (!lua_istable(L, -1)) {
|
||||
luaL_error(L, "expect a table on 2nd para.");
|
||||
return 0;
|
||||
luaL_error(L, "expect a table on 2nd para");
|
||||
lua_settop(L, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
luavgl_setup_obj(L, obj);
|
||||
return 0;
|
||||
|
||||
lua_settop(L, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* obj:align_to({base=base, type=type, x_ofs=0, y_ofs=0})
|
||||
*/
|
||||
static int luavgl_obj_align_to(lua_State *L) {
|
||||
static int luavgl_obj_align_to(lua_State *L)
|
||||
{
|
||||
lv_obj_t *obj = luavgl_to_obj(L, 1);
|
||||
|
||||
if (!lua_istable(L, 2)) {
|
||||
debug("para should be table.");
|
||||
return luaL_argerror(L, 2, "should be table.");
|
||||
LV_LOG_ERROR("para should be table");
|
||||
return luaL_argerror(L, 2, "should be table");
|
||||
}
|
||||
|
||||
lua_getfield(L, 2, "type");
|
||||
@@ -205,7 +242,7 @@ static int luavgl_obj_align_to(lua_State *L) {
|
||||
lv_obj_t *base = luavgl_to_lobj(L, -1)->obj;
|
||||
lua_pop(L, 1);
|
||||
if (base == NULL) {
|
||||
debug("base is not lua obj");
|
||||
LV_LOG_ERROR("base is not lua obj");
|
||||
return luaL_argerror(L, -1, "base is not lua obj");
|
||||
}
|
||||
|
||||
@@ -218,17 +255,22 @@ static int luavgl_obj_align_to(lua_State *L) {
|
||||
lua_pop(L, 1);
|
||||
|
||||
lv_obj_align_to(obj, base, align, x_ofs, y_ofs);
|
||||
return 0;
|
||||
|
||||
lua_settop(L, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int luavgl_obj_set_parent(lua_State *L) {
|
||||
static int luavgl_obj_set_parent(lua_State *L)
|
||||
{
|
||||
lv_obj_t *obj = luavgl_to_obj(L, 1);
|
||||
lv_obj_t *parent = luavgl_to_obj(L, 2);
|
||||
lv_obj_set_parent(obj, parent);
|
||||
return 0;
|
||||
lua_pop(L, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int luavgl_obj_get_screen(lua_State *L) {
|
||||
static int luavgl_obj_get_screen(lua_State *L)
|
||||
{
|
||||
lv_obj_t *obj = luavgl_to_obj(L, 1);
|
||||
lv_obj_t *screen = lv_obj_get_screen(obj);
|
||||
|
||||
@@ -246,7 +288,8 @@ static int luavgl_obj_get_screen(lua_State *L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int luavgl_obj_get_parent(lua_State *L) {
|
||||
static int luavgl_obj_get_parent(lua_State *L)
|
||||
{
|
||||
lv_obj_t *obj = luavgl_to_obj(L, 1);
|
||||
lv_obj_t *parent = lv_obj_get_parent(obj);
|
||||
|
||||
@@ -263,7 +306,8 @@ static int luavgl_obj_get_parent(lua_State *L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int luavgl_obj_set_get_parent(lua_State *L) {
|
||||
static int luavgl_obj_set_get_parent(lua_State *L)
|
||||
{
|
||||
lv_obj_t *obj = luavgl_to_obj(L, 1);
|
||||
if (!lua_isnoneornil(L, 2)) {
|
||||
lv_obj_t *parent = luavgl_to_obj(L, 2);
|
||||
@@ -273,7 +317,8 @@ static int luavgl_obj_set_get_parent(lua_State *L) {
|
||||
return luavgl_obj_get_parent(L);
|
||||
}
|
||||
|
||||
static int luavgl_obj_get_child(lua_State *L) {
|
||||
static int luavgl_obj_get_child(lua_State *L)
|
||||
{
|
||||
lv_obj_t *obj = luavgl_to_obj(L, 1);
|
||||
|
||||
int id = luavgl_tointeger(L, 2);
|
||||
@@ -293,13 +338,15 @@ static int luavgl_obj_get_child(lua_State *L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int luavgl_obj_get_child_cnt(lua_State *L) {
|
||||
static int luavgl_obj_get_child_cnt(lua_State *L)
|
||||
{
|
||||
lv_obj_t *obj = luavgl_to_obj(L, 1);
|
||||
lua_pushinteger(L, lv_obj_get_child_cnt(obj));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int luavgl_obj_get_state(lua_State *L) {
|
||||
static int luavgl_obj_get_state(lua_State *L)
|
||||
{
|
||||
lv_obj_t *obj = luavgl_to_obj(L, 1);
|
||||
lv_state_t state = lv_obj_get_state(obj);
|
||||
lua_pushinteger(L, state);
|
||||
@@ -312,7 +359,8 @@ static int luavgl_obj_get_state(lua_State *L) {
|
||||
* obj:scroll_to({x=10, anim=true})
|
||||
* obj:scroll_to({x=10, y=100, anim=false})
|
||||
*/
|
||||
static int luavgl_obj_scroll_to(lua_State *L) {
|
||||
static int luavgl_obj_scroll_to(lua_State *L)
|
||||
{
|
||||
lv_obj_t *obj = luavgl_to_obj(L, 1);
|
||||
|
||||
if (!lua_istable(L, -1)) {
|
||||
@@ -338,176 +386,231 @@ static int luavgl_obj_scroll_to(lua_State *L) {
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
|
||||
return 0;
|
||||
lua_settop(L, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int luavgl_obj_is_visible(lua_State *L) {
|
||||
static int luavgl_obj_is_visible(lua_State *L)
|
||||
{
|
||||
lv_obj_t *obj = luavgl_to_obj(L, 1);
|
||||
lua_pushboolean(L, lv_obj_is_visible(obj));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int luavgl_obj_add_flag(lua_State *L) {
|
||||
static int luavgl_obj_add_flag(lua_State *L)
|
||||
{
|
||||
lv_obj_t *obj = luavgl_to_obj(L, 1);
|
||||
lv_obj_flag_t flag = lua_tointeger(L, 2);
|
||||
lv_obj_add_flag(obj, flag);
|
||||
|
||||
return 0;
|
||||
lua_settop(L, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int luavgl_obj_clear_flag(lua_State *L) {
|
||||
static int luavgl_obj_clear_flag(lua_State *L)
|
||||
{
|
||||
lv_obj_t *obj = luavgl_to_obj(L, 1);
|
||||
lv_obj_flag_t flag = lua_tointeger(L, 2);
|
||||
lv_obj_clear_flag(obj, flag);
|
||||
|
||||
return 0;
|
||||
lua_settop(L, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int luavgl_obj_add_state(lua_State *L) {
|
||||
static int luavgl_obj_add_state(lua_State *L)
|
||||
{
|
||||
lv_obj_t *obj = luavgl_to_obj(L, 1);
|
||||
lv_state_t state = lua_tointeger(L, 2);
|
||||
lv_obj_add_state(obj, state);
|
||||
return 0;
|
||||
|
||||
lua_settop(L, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int luavgl_obj_clear_state(lua_State *L) {
|
||||
static int luavgl_obj_clear_state(lua_State *L)
|
||||
{
|
||||
lv_obj_t *obj = luavgl_to_obj(L, 1);
|
||||
lv_state_t state = lua_tointeger(L, 2);
|
||||
lv_obj_clear_state(obj, state);
|
||||
return 0;
|
||||
|
||||
lua_settop(L, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* obj:scroll_by(x, y, anim_en)
|
||||
*/
|
||||
static int luavgl_obj_scroll_by(lua_State *L) {
|
||||
static int luavgl_obj_scroll_by(lua_State *L)
|
||||
{
|
||||
lv_obj_t *obj = luavgl_to_obj(L, 1);
|
||||
int x = luavgl_tointeger(L, 2);
|
||||
int y = luavgl_tointeger(L, 3);
|
||||
int anim_en = luavgl_tointeger(L, 4);
|
||||
|
||||
lv_obj_scroll_by(obj, x, y, anim_en);
|
||||
return 0;
|
||||
|
||||
lua_settop(L, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int luavgl_obj_scroll_by_bounded(lua_State *L) {
|
||||
static int luavgl_obj_scroll_by_bounded(lua_State *L)
|
||||
{
|
||||
lv_obj_t *obj = luavgl_to_obj(L, 1);
|
||||
int dx = luavgl_tointeger(L, 2);
|
||||
int dy = luavgl_tointeger(L, 3);
|
||||
int anim_en = luavgl_tointeger(L, 4);
|
||||
|
||||
lv_obj_scroll_by_bounded(obj, dx, dy, anim_en);
|
||||
return 0;
|
||||
lua_settop(L, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int luavgl_obj_scroll_to_view(lua_State *L) {
|
||||
static int luavgl_obj_scroll_to_view(lua_State *L)
|
||||
{
|
||||
lv_obj_t *obj = luavgl_to_obj(L, 1);
|
||||
int anim_en = luavgl_tointeger(L, 2);
|
||||
|
||||
lv_obj_scroll_to_view(obj, anim_en);
|
||||
return 0;
|
||||
lua_settop(L, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int luavgl_obj_scroll_to_view_recursive(lua_State *L) {
|
||||
static int luavgl_obj_scroll_to_view_recursive(lua_State *L)
|
||||
{
|
||||
lv_obj_t *obj = luavgl_to_obj(L, 1);
|
||||
int anim_en = luavgl_tointeger(L, 2);
|
||||
|
||||
lv_obj_scroll_to_view_recursive(obj, anim_en);
|
||||
return 0;
|
||||
|
||||
lua_settop(L, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int luavgl_obj_scroll_by_raw(lua_State *L) {
|
||||
static int luavgl_obj_scroll_by_raw(lua_State *L)
|
||||
{
|
||||
#if LV_VERSION_CHECK(8, 3, 0)
|
||||
lv_obj_t *obj = luavgl_to_obj(L, 1);
|
||||
int x = luavgl_tointeger(L, 2);
|
||||
int y = luavgl_tointeger(L, 3);
|
||||
|
||||
_lv_obj_scroll_by_raw(obj, x, y);
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
lua_settop(L, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int luavgl_obj_is_scrolling(lua_State *L) {
|
||||
static int luavgl_obj_is_scrolling(lua_State *L)
|
||||
{
|
||||
lv_obj_t *obj = luavgl_to_obj(L, 1);
|
||||
lua_pushboolean(L, lv_obj_is_scrolling(obj));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int luavgl_obj_scrollbar_invalidate(lua_State *L) {
|
||||
static int luavgl_obj_scrollbar_invalidate(lua_State *L)
|
||||
{
|
||||
lv_obj_t *obj = luavgl_to_obj(L, 1);
|
||||
lv_obj_scrollbar_invalidate(obj);
|
||||
return 0;
|
||||
|
||||
lua_settop(L, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int luavgl_obj_readjust_scroll(lua_State *L) {
|
||||
static int luavgl_obj_readjust_scroll(lua_State *L)
|
||||
{
|
||||
lv_obj_t *obj = luavgl_to_obj(L, 1);
|
||||
int anim_en = luavgl_tointeger(L, 2);
|
||||
lv_obj_readjust_scroll(obj, anim_en);
|
||||
return 0;
|
||||
|
||||
lua_settop(L, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int luavgl_obj_is_editable(lua_State *L) {
|
||||
static int luavgl_obj_is_editable(lua_State *L)
|
||||
{
|
||||
lv_obj_t *obj = luavgl_to_obj(L, 1);
|
||||
lua_pushboolean(L, lv_obj_is_editable(obj));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int luavgl_obj_is_group_def(lua_State *L) {
|
||||
static int luavgl_obj_is_group_def(lua_State *L)
|
||||
{
|
||||
lv_obj_t *obj = luavgl_to_obj(L, 1);
|
||||
lua_pushboolean(L, lv_obj_is_group_def(obj));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int luavgl_obj_is_layout_positioned(lua_State *L) {
|
||||
static int luavgl_obj_is_layout_positioned(lua_State *L)
|
||||
{
|
||||
lv_obj_t *obj = luavgl_to_obj(L, 1);
|
||||
lua_pushboolean(L, lv_obj_is_layout_positioned(obj));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int luavgl_obj_mark_layout_as_dirty(lua_State *L) {
|
||||
static int luavgl_obj_mark_layout_as_dirty(lua_State *L)
|
||||
{
|
||||
lv_obj_t *obj = luavgl_to_obj(L, 1);
|
||||
lv_obj_mark_layout_as_dirty(obj);
|
||||
return 0;
|
||||
|
||||
lua_settop(L, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int luavgl_obj_center(lua_State *L) {
|
||||
static int luavgl_obj_center(lua_State *L)
|
||||
{
|
||||
lv_obj_t *obj = luavgl_to_obj(L, 1);
|
||||
lv_obj_center(obj);
|
||||
return 0;
|
||||
|
||||
lua_settop(L, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int luavgl_obj_invalidate(lua_State *L) {
|
||||
static int luavgl_obj_invalidate(lua_State *L)
|
||||
{
|
||||
lv_obj_t *obj = luavgl_to_obj(L, 1);
|
||||
lv_obj_invalidate(obj);
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int luavgl_obj_set_flex_flow(lua_State *L) {
|
||||
static int luavgl_obj_set_flex_flow(lua_State *L)
|
||||
{
|
||||
lv_obj_t *obj = luavgl_to_obj(L, 1);
|
||||
lv_flex_flow_t flow = luavgl_tointeger(L, 2);
|
||||
|
||||
lv_obj_set_flex_flow(obj, flow);
|
||||
return 0;
|
||||
|
||||
lua_settop(L, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int luavgl_obj_set_flex_align(lua_State *L) {
|
||||
static int luavgl_obj_set_flex_align(lua_State *L)
|
||||
{
|
||||
lv_obj_t *obj = luavgl_to_obj(L, 1);
|
||||
lv_flex_align_t m = luavgl_tointeger(L, 2);
|
||||
lv_flex_align_t c = luavgl_tointeger(L, 3);
|
||||
lv_flex_align_t t = luavgl_tointeger(L, 4);
|
||||
|
||||
lv_obj_set_flex_align(obj, m, c, t);
|
||||
return 0;
|
||||
|
||||
lua_settop(L, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int luavgl_obj_set_flex_grow(lua_State *L) {
|
||||
static int luavgl_obj_set_flex_grow(lua_State *L)
|
||||
{
|
||||
lv_obj_t *obj = luavgl_to_obj(L, 1);
|
||||
uint8_t grow = luavgl_tointeger(L, 2);
|
||||
|
||||
lv_obj_set_flex_grow(obj, grow);
|
||||
return 0;
|
||||
|
||||
lua_settop(L, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int luavgl_obj_indev_search(lua_State *L) {
|
||||
static int luavgl_obj_indev_search(lua_State *L)
|
||||
{
|
||||
lv_obj_t *obj = luavgl_to_obj(L, 1);
|
||||
lv_point_t point;
|
||||
if (lua_istable(L, 2)) {
|
||||
@@ -537,7 +640,8 @@ static int luavgl_obj_indev_search(lua_State *L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int luavgl_obj_get_coords(lua_State *L) {
|
||||
static int luavgl_obj_get_coords(lua_State *L)
|
||||
{
|
||||
lv_area_t area;
|
||||
lv_obj_t *obj = luavgl_to_obj(L, 1);
|
||||
lv_obj_get_coords(obj, &area);
|
||||
@@ -561,7 +665,8 @@ static int luavgl_obj_get_coords(lua_State *L) {
|
||||
/**
|
||||
* get object real position using lv_obj_get_x/x2/y/y2
|
||||
*/
|
||||
static int luavgl_obj_get_pos(lua_State *L) {
|
||||
static int luavgl_obj_get_pos(lua_State *L)
|
||||
{
|
||||
lv_obj_t *obj = luavgl_to_obj(L, 1);
|
||||
lua_newtable(L);
|
||||
|
||||
@@ -580,39 +685,18 @@ static int luavgl_obj_get_pos(lua_State *L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* set this object as the current selection
|
||||
*/
|
||||
static int luavgl_obj_focus(lua_State *L) {
|
||||
lv_obj_t *obj = luavgl_to_obj(L, 1);
|
||||
|
||||
lv_group_t *group = lv_obj_get_group(obj);
|
||||
if (group == NULL) {
|
||||
return 0;
|
||||
}
|
||||
lv_group_focus_obj(obj);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int luavgl_obj_move_to_index(lua_State *L) {
|
||||
lv_obj_t *obj = luavgl_to_obj(L, 1);
|
||||
int idx = luavgl_tointeger(L, 2);
|
||||
|
||||
lv_obj_move_to_index(obj, idx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all animations associates to this object
|
||||
*/
|
||||
static int luavgl_obj_remove_anim_all(lua_State *L) {
|
||||
static int luavgl_obj_remove_anim_all(lua_State *L)
|
||||
{
|
||||
lv_obj_t *obj = luavgl_to_obj(L, 1);
|
||||
lv_anim_del(obj, NULL);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int luavgl_obj_gc(lua_State *L) {
|
||||
static int luavgl_obj_gc(lua_State *L)
|
||||
{
|
||||
if (lua_type(L, 1) != LUA_TUSERDATA) {
|
||||
/* If t = setmetatable({}, obj_meta_table), this will happen when t is
|
||||
* gc;ed. Currently all metatables for classes based on obj, that has no own
|
||||
@@ -621,7 +705,7 @@ static int luavgl_obj_gc(lua_State *L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
debug("\n");
|
||||
LV_LOG_INFO("enter");
|
||||
|
||||
luavgl_obj_t *lobj = lua_touserdata(L, 1);
|
||||
if (lobj == NULL || lobj->obj == NULL) {
|
||||
@@ -629,70 +713,69 @@ static int luavgl_obj_gc(lua_State *L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
debug("GC for obj: %p\n", lobj->obj);
|
||||
LV_LOG_INFO("GC for obj: %p", lobj->obj);
|
||||
luavgl_obj_delete(L);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const luaL_Reg luavgl_obj_methods[] = {
|
||||
{"set", luavgl_obj_set},
|
||||
{"set_style", luavgl_obj_set_style},
|
||||
{"align_to", luavgl_obj_align_to},
|
||||
{"delete", luavgl_obj_delete},
|
||||
{"clean", luavgl_obj_clean},
|
||||
{"set", luavgl_obj_set },
|
||||
{"set_style", luavgl_obj_set_style },
|
||||
{"align_to", luavgl_obj_align_to },
|
||||
{"delete", luavgl_obj_delete },
|
||||
{"clean", luavgl_obj_clean },
|
||||
|
||||
/* misc. functions */
|
||||
{"parent", luavgl_obj_set_get_parent},
|
||||
{"set_parent", luavgl_obj_set_parent},
|
||||
{"get_parent", luavgl_obj_get_parent},
|
||||
{"get_child", luavgl_obj_get_child},
|
||||
{"get_child_cnt", luavgl_obj_get_child_cnt},
|
||||
{"get_screen", luavgl_obj_get_screen},
|
||||
{"get_state", luavgl_obj_get_state},
|
||||
{"scroll_to", luavgl_obj_scroll_to},
|
||||
{"is_scrolling", luavgl_obj_is_scrolling},
|
||||
{"is_visible", luavgl_obj_is_visible},
|
||||
{"add_flag", luavgl_obj_add_flag},
|
||||
{"clear_flag", luavgl_obj_clear_flag},
|
||||
{"add_state", luavgl_obj_add_state},
|
||||
{"clear_state", luavgl_obj_clear_state},
|
||||
{"add_style", luavgl_obj_add_style},
|
||||
{"remove_style", luavgl_obj_remove_style},
|
||||
{"remove_style_all", luavgl_obj_remove_style_all},
|
||||
{"scroll_by", luavgl_obj_scroll_by},
|
||||
{"scroll_by_bounded", luavgl_obj_scroll_by_bounded},
|
||||
{"scroll_to_view", luavgl_obj_scroll_to_view},
|
||||
/* misc. functions */
|
||||
{"parent", luavgl_obj_set_get_parent },
|
||||
{"set_parent", luavgl_obj_set_parent },
|
||||
{"get_parent", luavgl_obj_get_parent },
|
||||
{"get_child", luavgl_obj_get_child },
|
||||
{"get_child_cnt", luavgl_obj_get_child_cnt },
|
||||
{"get_screen", luavgl_obj_get_screen },
|
||||
{"get_state", luavgl_obj_get_state },
|
||||
{"scroll_to", luavgl_obj_scroll_to },
|
||||
{"is_scrolling", luavgl_obj_is_scrolling },
|
||||
{"is_visible", luavgl_obj_is_visible },
|
||||
{"add_flag", luavgl_obj_add_flag },
|
||||
{"clear_flag", luavgl_obj_clear_flag },
|
||||
{"add_state", luavgl_obj_add_state },
|
||||
{"clear_state", luavgl_obj_clear_state },
|
||||
{"add_style", luavgl_obj_add_style },
|
||||
{"remove_style", luavgl_obj_remove_style },
|
||||
{"remove_style_all", luavgl_obj_remove_style_all },
|
||||
{"scroll_by", luavgl_obj_scroll_by },
|
||||
{"scroll_by_bounded", luavgl_obj_scroll_by_bounded },
|
||||
{"scroll_to_view", luavgl_obj_scroll_to_view },
|
||||
{"scroll_to_view_recursive", luavgl_obj_scroll_to_view_recursive},
|
||||
{"scroll_by_raw", luavgl_obj_scroll_by_raw},
|
||||
{"scrollbar_invalidate", luavgl_obj_scrollbar_invalidate},
|
||||
{"readjust_scroll", luavgl_obj_readjust_scroll},
|
||||
{"is_editable", luavgl_obj_is_editable},
|
||||
{"is_group_def", luavgl_obj_is_group_def},
|
||||
{"is_layout_positioned", luavgl_obj_is_layout_positioned},
|
||||
{"mark_layout_as_dirty", luavgl_obj_mark_layout_as_dirty},
|
||||
{"center", luavgl_obj_center},
|
||||
{"invalidate", luavgl_obj_invalidate},
|
||||
{"set_flex_flow", luavgl_obj_set_flex_flow},
|
||||
{"set_flex_align", luavgl_obj_set_flex_align},
|
||||
{"set_flex_grow", luavgl_obj_set_flex_grow},
|
||||
{"indev_search", luavgl_obj_indev_search},
|
||||
{"get_coords", luavgl_obj_get_coords},
|
||||
{"get_pos", luavgl_obj_get_pos},
|
||||
{"focus", luavgl_obj_focus},
|
||||
{"move_to_index", luavgl_obj_move_to_index},
|
||||
{"scroll_by_raw", luavgl_obj_scroll_by_raw },
|
||||
{"scrollbar_invalidate", luavgl_obj_scrollbar_invalidate },
|
||||
{"readjust_scroll", luavgl_obj_readjust_scroll },
|
||||
{"is_editable", luavgl_obj_is_editable },
|
||||
{"is_group_def", luavgl_obj_is_group_def },
|
||||
{"is_layout_positioned", luavgl_obj_is_layout_positioned },
|
||||
{"mark_layout_as_dirty", luavgl_obj_mark_layout_as_dirty },
|
||||
{"center", luavgl_obj_center },
|
||||
{"invalidate", luavgl_obj_invalidate },
|
||||
{"set_flex_flow", luavgl_obj_set_flex_flow },
|
||||
{"set_flex_align", luavgl_obj_set_flex_align },
|
||||
{"set_flex_grow", luavgl_obj_set_flex_grow },
|
||||
{"indev_search", luavgl_obj_indev_search },
|
||||
{"get_coords", luavgl_obj_get_coords },
|
||||
{"get_pos", luavgl_obj_get_pos },
|
||||
|
||||
{"onevent", luavgl_obj_on_event},
|
||||
{"onPressed", luavgl_obj_on_pressed},
|
||||
{"onClicked", luavgl_obj_on_clicked},
|
||||
{"onShortClicked", luavgl_obj_on_short_clicked},
|
||||
{"anim", luavgl_anim_create},
|
||||
{"Anim", luavgl_anim_create},
|
||||
{"remove_all_anim", luavgl_obj_remove_anim_all}, /* remove all */
|
||||
{NULL, NULL},
|
||||
{"onevent", luavgl_obj_on_event },
|
||||
{"onPressed", luavgl_obj_on_pressed },
|
||||
{"onClicked", luavgl_obj_on_clicked },
|
||||
{"onShortClicked", luavgl_obj_on_short_clicked },
|
||||
{"anim", luavgl_anim_create },
|
||||
{"Anim", luavgl_anim_create },
|
||||
{"remove_all_anim", luavgl_obj_remove_anim_all }, /* remove all */
|
||||
{NULL, NULL },
|
||||
};
|
||||
|
||||
static void luavgl_obj_init(lua_State *L) {
|
||||
static void luavgl_obj_init(lua_State *L)
|
||||
{
|
||||
/* base lv_obj */
|
||||
luavgl_obj_newmetatable(L, &lv_obj_class, "lv_obj", luavgl_obj_methods);
|
||||
lua_pushcfunction(L, luavgl_obj_gc);
|
||||
@@ -718,16 +801,16 @@ static void luavgl_obj_init(lua_State *L) {
|
||||
}
|
||||
|
||||
static const luavgl_value_setter_t obj_property_table[] = {
|
||||
{"x", 0, {.setter = (setter_int_t)lv_obj_set_x}},
|
||||
{"y", 0, {.setter = (setter_int_t)lv_obj_set_y}},
|
||||
{"w", 0, {.setter = (setter_int_t)lv_obj_set_width}},
|
||||
{"h", 0, {.setter = (setter_int_t)lv_obj_set_height}},
|
||||
{"align", SETTER_TYPE_STACK, {.setter_stack = _lv_obj_set_align}},
|
||||
{"x", 0, {.setter = (setter_int_t)lv_obj_set_x} },
|
||||
{"y", 0, {.setter = (setter_int_t)lv_obj_set_y} },
|
||||
{"w", 0, {.setter = (setter_int_t)lv_obj_set_width} },
|
||||
{"h", 0, {.setter = (setter_int_t)lv_obj_set_height} },
|
||||
{"align", SETTER_TYPE_STACK, {.setter_stack = _lv_obj_set_align} },
|
||||
|
||||
{"scrollbar_mode", 0, {.setter = (setter_int_t)lv_obj_set_scrollbar_mode}},
|
||||
{"scroll_dir", 0, {.setter = (setter_int_t)lv_obj_set_scroll_dir}},
|
||||
{"scroll_snap_x", 0, {.setter = (setter_int_t)lv_obj_set_scroll_snap_x}},
|
||||
{"scroll_snap_y", 0, {.setter = (setter_int_t)lv_obj_set_scroll_snap_y}},
|
||||
{"scrollbar_mode", 0, {.setter = (setter_int_t)lv_obj_set_scrollbar_mode}},
|
||||
{"scroll_dir", 0, {.setter = (setter_int_t)lv_obj_set_scroll_dir} },
|
||||
{"scroll_snap_x", 0, {.setter = (setter_int_t)lv_obj_set_scroll_snap_x} },
|
||||
{"scroll_snap_y", 0, {.setter = (setter_int_t)lv_obj_set_scroll_snap_y} },
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -741,8 +824,17 @@ static const luavgl_value_setter_t obj_property_table[] = {
|
||||
* stack[-2]: key(property name)
|
||||
* stack[-1]: value(could be any lua data)
|
||||
*/
|
||||
LUALIB_API int luavgl_obj_set_property_kv(lua_State *L, void *data) {
|
||||
LUALIB_API int luavgl_obj_set_property_kv(lua_State *L, void *data)
|
||||
{
|
||||
lv_obj_t *obj = data;
|
||||
|
||||
/* Check for integer key with userdata as value */
|
||||
if (lua_type(L, -2) == LUA_TNUMBER && lua_type(L, -1) == LUA_TUSERDATA) {
|
||||
lv_obj_t *child = luavgl_to_obj(L, -1);
|
||||
lv_obj_set_parent(child, obj);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ret = luavgl_set_property(L, obj, obj_property_table);
|
||||
|
||||
if (ret == 0)
|
||||
@@ -753,7 +845,8 @@ LUALIB_API int luavgl_obj_set_property_kv(lua_State *L, void *data) {
|
||||
}
|
||||
|
||||
LUALIB_API int luavgl_obj_create_helper(lua_State *L,
|
||||
lv_obj_t *(*create)(lv_obj_t *parent)) {
|
||||
lv_obj_t *(*create)(lv_obj_t *parent))
|
||||
{
|
||||
luavgl_ctx_t *ctx = luavgl_context(L);
|
||||
lv_obj_t *parent;
|
||||
|
||||
@@ -765,7 +858,7 @@ LUALIB_API int luavgl_obj_create_helper(lua_State *L,
|
||||
lua_remove(L, 1);
|
||||
}
|
||||
|
||||
debug("create obj on: %p\n", parent);
|
||||
LV_LOG_INFO("create obj on: %p", parent);
|
||||
|
||||
lv_obj_t *obj = create(parent);
|
||||
luavgl_add_lobj(L, obj)->lua_created = true;
|
||||
@@ -790,7 +883,7 @@ LUALIB_API int luavgl_obj_create_helper(lua_State *L,
|
||||
lua_rawget(L, LUA_REGISTRYINDEX);
|
||||
}
|
||||
|
||||
debug("create obj: %p\n", obj);
|
||||
LV_LOG_INFO("create obj: %p", obj);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -799,7 +892,8 @@ LUALIB_API int luavgl_obj_create_helper(lua_State *L,
|
||||
* If no metatable not found for this obj class, then lv_obj_class metatable is
|
||||
* used
|
||||
*/
|
||||
LUALIB_API luavgl_obj_t *luavgl_add_lobj(lua_State *L, lv_obj_t *obj) {
|
||||
LUALIB_API luavgl_obj_t *luavgl_add_lobj(lua_State *L, lv_obj_t *obj)
|
||||
{
|
||||
luavgl_obj_t *lobj;
|
||||
|
||||
/* In rare case, obj may be deleted but not gc'ed in lua, and lvgl quickly
|
||||
@@ -817,16 +911,18 @@ LUALIB_API luavgl_obj_t *luavgl_add_lobj(lua_State *L, lv_obj_t *obj) {
|
||||
|
||||
if (luavgl_obj_getmetatable(L, obj->class_p) == LUA_TNIL) {
|
||||
lua_pop(L, 1);
|
||||
debug("cannot find metatable for class: %p\n", obj->class_p);
|
||||
LV_LOG_ERROR("cannot find metatable for class: %p", obj->class_p);
|
||||
/* use base obj metatable instead */
|
||||
luavgl_obj_getmetatable(L, &lv_obj_class);
|
||||
}
|
||||
|
||||
lua_setmetatable(L, -2);
|
||||
|
||||
memset(lobj, 0, sizeof(*lobj));
|
||||
luavgl_obj_event_init(lobj);
|
||||
lv_memset(lobj, 0, sizeof(*lobj));
|
||||
lobj->obj = obj;
|
||||
|
||||
/* Init event array to store events added from lua. */
|
||||
lv_array_init(&lobj->events, 0, sizeof(struct event_callback_s *));
|
||||
lv_obj_add_event_cb(obj, obj_delete_cb, LV_EVENT_DELETE, L);
|
||||
|
||||
/* registry[obj] = lobj */
|
||||
|
||||
@@ -6,19 +6,6 @@
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/* clang-format off */
|
||||
#define debug(format, ...)
|
||||
// fprintf(stderr, "[luavgl] %s: " format, __FUNCTION__, ##__VA_ARGS__)
|
||||
// syslog(LOG_DEBUG, "[luavgl] %s: " format, __FUNCTION__, ##__VA_ARGS__)
|
||||
/* clang-format on */
|
||||
|
||||
struct event_callback_s {
|
||||
lv_event_code_t code;
|
||||
struct _lv_event_dsc_t *dsc;
|
||||
int ref; /* ref to callback */
|
||||
}; /* variable array if n_callback > 1 */
|
||||
|
||||
static void dumpstack(lua_State *L);
|
||||
static void dumptable(lua_State *L, int index);
|
||||
@@ -27,7 +14,6 @@ static void dumptable(lua_State *L, int index);
|
||||
int luavgl_obj_getmetatable(lua_State *L, const lv_obj_class_t *clz);
|
||||
int luavgl_obj_setmetatable(lua_State *L, int idx, const lv_obj_class_t *clz);
|
||||
|
||||
static void luavgl_obj_event_init(luavgl_obj_t *lobj);
|
||||
static void luavgl_obj_remove_event_all(lua_State *L, luavgl_obj_t *obj);
|
||||
|
||||
/* util functions */
|
||||
|
||||
+90
-44
@@ -54,10 +54,13 @@ static const struct style_map_s {
|
||||
{"transform_height", LV_STYLE_TRANSFORM_HEIGHT, STYLE_TYPE_INT },
|
||||
{"translate_x", LV_STYLE_TRANSLATE_X, STYLE_TYPE_INT },
|
||||
{"translate_y", LV_STYLE_TRANSLATE_Y, STYLE_TYPE_INT },
|
||||
{"transform_zoom", LV_STYLE_TRANSFORM_ZOOM, STYLE_TYPE_INT },
|
||||
{"transform_angle", LV_STYLE_TRANSFORM_ANGLE, STYLE_TYPE_INT },
|
||||
{"transform_scale_x", LV_STYLE_TRANSFORM_SCALE_X, STYLE_TYPE_INT },
|
||||
{"transform_scale_y", LV_STYLE_TRANSFORM_SCALE_X, STYLE_TYPE_INT },
|
||||
{"transform_rotation", LV_STYLE_TRANSFORM_ROTATION, STYLE_TYPE_INT },
|
||||
#if LV_VERSION_CHECK(8, 3, 0)
|
||||
{"transform_pivot_x", LV_STYLE_TRANSFORM_PIVOT_X, STYLE_TYPE_INT },
|
||||
{"transform_pivot_y", LV_STYLE_TRANSFORM_PIVOT_Y, STYLE_TYPE_INT },
|
||||
#endif
|
||||
{"pad_top", LV_STYLE_PAD_TOP, STYLE_TYPE_INT },
|
||||
{"pad_bottom", LV_STYLE_PAD_BOTTOM, STYLE_TYPE_INT },
|
||||
{"pad_left", LV_STYLE_PAD_LEFT, STYLE_TYPE_INT },
|
||||
@@ -71,12 +74,11 @@ static const struct style_map_s {
|
||||
{"bg_grad_dir", LV_STYLE_BG_GRAD_DIR, STYLE_TYPE_INT },
|
||||
{"bg_main_stop", LV_STYLE_BG_MAIN_STOP, STYLE_TYPE_INT },
|
||||
{"bg_grad_stop", LV_STYLE_BG_GRAD_STOP, STYLE_TYPE_INT },
|
||||
{"bg_dither_mode", LV_STYLE_BG_DITHER_MODE, STYLE_TYPE_INT },
|
||||
{"bg_img_src", LV_STYLE_BG_IMG_SRC, STYLE_TYPE_IMGSRC },
|
||||
{"bg_img_opa", LV_STYLE_BG_IMG_OPA, STYLE_TYPE_INT },
|
||||
{"bg_img_recolor", LV_STYLE_BG_IMG_RECOLOR, STYLE_TYPE_COLOR },
|
||||
{"bg_img_recolor_opa", LV_STYLE_BG_IMG_RECOLOR_OPA, STYLE_TYPE_INT },
|
||||
{"bg_img_tiled", LV_STYLE_BG_IMG_TILED, STYLE_TYPE_INT },
|
||||
{"bg_image_src", LV_STYLE_BG_IMAGE_SRC, STYLE_TYPE_IMGSRC },
|
||||
{"bg_image_opa", LV_STYLE_BG_IMAGE_OPA, STYLE_TYPE_INT },
|
||||
{"bg_image_recolor", LV_STYLE_BG_IMAGE_RECOLOR, STYLE_TYPE_COLOR },
|
||||
{"bg_image_recolor_opa", LV_STYLE_BG_IMAGE_RECOLOR_OPA, STYLE_TYPE_INT },
|
||||
{"bg_image_tiled", LV_STYLE_BG_IMAGE_TILED, STYLE_TYPE_INT },
|
||||
{"border_color", LV_STYLE_BORDER_COLOR, STYLE_TYPE_COLOR },
|
||||
{"border_opa", LV_STYLE_BORDER_OPA, STYLE_TYPE_INT },
|
||||
{"border_width", LV_STYLE_BORDER_WIDTH, STYLE_TYPE_INT },
|
||||
@@ -87,14 +89,14 @@ static const struct style_map_s {
|
||||
{"outline_opa", LV_STYLE_OUTLINE_OPA, STYLE_TYPE_INT },
|
||||
{"outline_pad", LV_STYLE_OUTLINE_PAD, STYLE_TYPE_INT },
|
||||
{"shadow_width", LV_STYLE_SHADOW_WIDTH, STYLE_TYPE_INT },
|
||||
{"shadow_ofs_x", LV_STYLE_SHADOW_OFS_X, STYLE_TYPE_INT },
|
||||
{"shadow_ofs_y", LV_STYLE_SHADOW_OFS_Y, STYLE_TYPE_INT },
|
||||
{"shadow_offset_x", LV_STYLE_SHADOW_OFFSET_X, STYLE_TYPE_INT },
|
||||
{"shadow_offset_y", LV_STYLE_SHADOW_OFFSET_Y, STYLE_TYPE_INT },
|
||||
{"shadow_spread", LV_STYLE_SHADOW_SPREAD, STYLE_TYPE_INT },
|
||||
{"shadow_color", LV_STYLE_SHADOW_COLOR, STYLE_TYPE_COLOR },
|
||||
{"shadow_opa", LV_STYLE_SHADOW_OPA, STYLE_TYPE_INT },
|
||||
{"img_opa", LV_STYLE_IMG_OPA, STYLE_TYPE_INT },
|
||||
{"img_recolor", LV_STYLE_IMG_RECOLOR, STYLE_TYPE_COLOR },
|
||||
{"img_recolor_opa", LV_STYLE_IMG_RECOLOR_OPA, STYLE_TYPE_INT },
|
||||
{"image_opa", LV_STYLE_IMAGE_OPA, STYLE_TYPE_INT },
|
||||
{"image_recolor", LV_STYLE_IMAGE_RECOLOR, STYLE_TYPE_COLOR },
|
||||
{"image_recolor_opa", LV_STYLE_IMAGE_RECOLOR_OPA, STYLE_TYPE_INT },
|
||||
{"line_width", LV_STYLE_LINE_WIDTH, STYLE_TYPE_INT },
|
||||
{"line_dash_width", LV_STYLE_LINE_DASH_WIDTH, STYLE_TYPE_INT },
|
||||
{"line_dash_gap", LV_STYLE_LINE_DASH_GAP, STYLE_TYPE_INT },
|
||||
@@ -102,7 +104,7 @@ static const struct style_map_s {
|
||||
{"line_color", LV_STYLE_LINE_COLOR, STYLE_TYPE_INT },
|
||||
{"line_opa", LV_STYLE_LINE_OPA, STYLE_TYPE_INT },
|
||||
{"arc_width", LV_STYLE_ARC_WIDTH, STYLE_TYPE_INT },
|
||||
{"arc_img_src", LV_STYLE_ARC_IMG_SRC, STYLE_TYPE_IMGSRC },
|
||||
{"arc_image_src", LV_STYLE_ARC_IMAGE_SRC, STYLE_TYPE_IMGSRC },
|
||||
{"arc_rounded", LV_STYLE_ARC_ROUNDED, STYLE_TYPE_INT },
|
||||
{"arc_color", LV_STYLE_ARC_COLOR, STYLE_TYPE_COLOR },
|
||||
{"arc_opa", LV_STYLE_ARC_OPA, STYLE_TYPE_INT },
|
||||
@@ -118,7 +120,6 @@ static const struct style_map_s {
|
||||
{"opa", LV_STYLE_OPA, STYLE_TYPE_INT },
|
||||
{"color_filter_opa", LV_STYLE_COLOR_FILTER_OPA, STYLE_TYPE_INT },
|
||||
{"anim_time", LV_STYLE_ANIM_TIME, STYLE_TYPE_INT },
|
||||
{"anim_speed", LV_STYLE_ANIM_SPEED, STYLE_TYPE_INT },
|
||||
{"blend_mode", LV_STYLE_BLEND_MODE, STYLE_TYPE_INT },
|
||||
{"layout", LV_STYLE_LAYOUT, STYLE_TYPE_INT },
|
||||
{"base_dir", LV_STYLE_BASE_DIR, STYLE_TYPE_INT },
|
||||
@@ -126,7 +127,9 @@ static const struct style_map_s {
|
||||
/* need to build pointer from table parameter */
|
||||
{"bg_grad", LV_STYLE_BG_GRAD, STYLE_TYPE_SPECIAL }, /* pointer from table */
|
||||
{"color_filter_dsc", LV_STYLE_COLOR_FILTER_DSC, STYLE_TYPE_SPECIAL }, /**/
|
||||
#if LV_VERSION_CHECK(8, 3, 0)
|
||||
{"anim", LV_STYLE_ANIM, STYLE_TYPE_SPECIAL }, /* anim para */
|
||||
#endif
|
||||
{"transition", LV_STYLE_TRANSITION, STYLE_TYPE_SPECIAL }, /* transition */
|
||||
|
||||
/* styles combined */
|
||||
@@ -166,12 +169,14 @@ static void lv_style_set_cb(lv_style_prop_t prop, lv_style_value_t value,
|
||||
lv_style_set_prop(s, prop, value);
|
||||
}
|
||||
|
||||
#if LV_VERSION_CHECK(8, 3, 0)
|
||||
static void lv_style_set_inherit_cb(lv_style_prop_t prop,
|
||||
lv_style_value_t value, void *args)
|
||||
{
|
||||
lv_style_t *s = args;
|
||||
lv_style_set_prop_meta(s, prop, LV_STYLE_PROP_META_INHERIT);
|
||||
}
|
||||
#endif
|
||||
|
||||
static uint8_t to_int(char c)
|
||||
{
|
||||
@@ -193,33 +198,53 @@ static lv_flex_align_t luavgl_to_flex_align(lua_State *L, int idx)
|
||||
return LV_FLEX_ALIGN_START;
|
||||
|
||||
const char *str = lua_tostring(L, idx);
|
||||
if (strcmp("flex-start", str) == 0)
|
||||
if (lv_strcmp("flex-start", str) == 0)
|
||||
return LV_FLEX_ALIGN_START;
|
||||
|
||||
if (strcmp("flex-end", str) == 0)
|
||||
if (lv_strcmp("flex-end", str) == 0)
|
||||
return LV_FLEX_ALIGN_END;
|
||||
|
||||
if (strcmp("center", str) == 0)
|
||||
if (lv_strcmp("center", str) == 0)
|
||||
return LV_FLEX_ALIGN_CENTER;
|
||||
|
||||
if (strcmp("space-evenly", str) == 0)
|
||||
if (lv_strcmp("space-evenly", str) == 0)
|
||||
return LV_FLEX_ALIGN_SPACE_EVENLY;
|
||||
|
||||
if (strcmp("space-around", str) == 0)
|
||||
if (lv_strcmp("space-around", str) == 0)
|
||||
return LV_FLEX_ALIGN_SPACE_AROUND;
|
||||
|
||||
if (strcmp("space-between", str) == 0)
|
||||
if (lv_strcmp("space-between", str) == 0)
|
||||
return LV_FLEX_ALIGN_SPACE_BETWEEN;
|
||||
|
||||
return LV_FLEX_ALIGN_START;
|
||||
}
|
||||
|
||||
static char *luavgl_strstr(const char *haystack, const char *needle) {
|
||||
while (*haystack != '\0') {
|
||||
const char *h = haystack;
|
||||
const char *n = needle;
|
||||
|
||||
while (*n != '\0' && *h == *n) {
|
||||
h++;
|
||||
n++;
|
||||
}
|
||||
|
||||
if (*n == '\0') {
|
||||
return (char *)haystack;
|
||||
}
|
||||
|
||||
haystack++;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int luavgl_set_flex_layout_kv(lua_State *L, style_set_cb_t cb,
|
||||
void *args)
|
||||
{
|
||||
if (!lua_istable(L, -1)) {
|
||||
debug("para should be table.");
|
||||
return luaL_argerror(L, -1, "should be table.");
|
||||
LV_LOG_ERROR("para should be table");
|
||||
return luaL_argerror(L, -1, "should be table");
|
||||
}
|
||||
|
||||
const char *str;
|
||||
@@ -234,14 +259,14 @@ static int luavgl_set_flex_layout_kv(lua_State *L, style_set_cb_t cb,
|
||||
if (lua_type(L, -1) == LUA_TSTRING) {
|
||||
str = lua_tostring(L, -1);
|
||||
/* starts with */
|
||||
if (strncmp("row", str, 3) == 0) {
|
||||
if (lv_strcmp("row", str) == 0) {
|
||||
flow = LV_FLEX_FLOW_ROW;
|
||||
} else if (strncmp("column", str, 3) == 0) {
|
||||
} else if (lv_strcmp("column", str) == 0) {
|
||||
flow = LV_FLEX_FLOW_COLUMN;
|
||||
}
|
||||
|
||||
/* if reverse presents */
|
||||
if (strstr(str, "-reverse")) {
|
||||
if (luavgl_strstr(str, "-reverse")) {
|
||||
flow |= _LV_FLEX_REVERSE;
|
||||
}
|
||||
}
|
||||
@@ -254,9 +279,9 @@ static int luavgl_set_flex_layout_kv(lua_State *L, style_set_cb_t cb,
|
||||
lua_getfield(L, -1, "flex_wrap");
|
||||
if (lua_type(L, -1) == LUA_TSTRING) {
|
||||
str = lua_tostring(L, -1);
|
||||
if (strcmp("wrap", str) == 0) {
|
||||
if (lv_strcmp("wrap", str) == 0) {
|
||||
flow |= _LV_FLEX_WRAP;
|
||||
} else if (strcmp("wrap-reverse", str) == 0) {
|
||||
} else if (lv_strcmp("wrap-reverse", str) == 0) {
|
||||
flow |= _LV_FLEX_WRAP | _LV_FLEX_REVERSE;
|
||||
}
|
||||
/* else: normal */
|
||||
@@ -316,7 +341,7 @@ static inline bool luavgl_is_style_inherit(lua_State *L)
|
||||
{
|
||||
const char *str;
|
||||
return (lua_type(L, -1) == LUA_TSTRING) && (str = lua_tostring(L, -1)) &&
|
||||
(strcmp(str, "inherit") == 0);
|
||||
(lv_strcmp(str, "inherit") == 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -330,7 +355,7 @@ static int luavgl_set_style_kv(lua_State *L, style_set_cb_t cb, void *args)
|
||||
{
|
||||
const char *key = lua_tostring(L, -2);
|
||||
if (key == NULL) {
|
||||
debug("Null key, ignored.\n");
|
||||
LV_LOG_WARN("Null key, ignored");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -338,7 +363,7 @@ static int luavgl_set_style_kv(lua_State *L, style_set_cb_t cb, void *args)
|
||||
lv_style_value_t value = {0};
|
||||
const struct style_map_s *p = NULL;
|
||||
for (int i = 0; i < STYLE_MAP_LEN; i++) {
|
||||
if (strcmp(key, g_style_map[i].name) == 0) {
|
||||
if (lv_strcmp(key, g_style_map[i].name) == 0) {
|
||||
p = &g_style_map[i];
|
||||
break;
|
||||
}
|
||||
@@ -374,8 +399,18 @@ static int luavgl_set_style_kv(lua_State *L, style_set_cb_t cb, void *args)
|
||||
}
|
||||
}
|
||||
|
||||
lv_style_prop_t prop = p->prop;
|
||||
|
||||
#if LV_VERSION_CHECK(9, 0, 0)
|
||||
lv_style_prop_t mask = ~0;
|
||||
#elif LV_VERSION_CHECK(8, 3, 0)
|
||||
lv_style_prop_t mask = ~LV_STYLE_PROP_FLAG_ALL;
|
||||
#else
|
||||
lv_style_prop_t mask = LV_STYLE_PROP_ANY;
|
||||
#endif
|
||||
|
||||
if (p->type & STYLE_TYPE_SPECIAL) {
|
||||
switch ((int)p->prop) {
|
||||
switch ((int)prop) {
|
||||
/* style combinations */
|
||||
case LV_STYLE_SIZE:
|
||||
cb(LV_STYLE_WIDTH, value, args);
|
||||
@@ -410,10 +445,10 @@ static int luavgl_set_style_kv(lua_State *L, style_set_cb_t cb, void *args)
|
||||
|
||||
case LV_STYLE_COLOR_FILTER_DSC:
|
||||
break;
|
||||
|
||||
#if LV_VERSION_CHECK(8, 3, 0)
|
||||
case LV_STYLE_ANIM:
|
||||
break;
|
||||
|
||||
#endif
|
||||
case LV_STYLE_TRANSITION:
|
||||
break;
|
||||
|
||||
@@ -442,8 +477,8 @@ static int luavgl_set_style_kv(lua_State *L, style_set_cb_t cb, void *args)
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else if (p->prop <= _LV_STYLE_LAST_BUILT_IN_PROP) {
|
||||
cb(p->prop, value, args);
|
||||
} else if ((prop & mask) <= _LV_STYLE_LAST_BUILT_IN_PROP) {
|
||||
cb(prop & mask, value, args);
|
||||
} else {
|
||||
return luaL_error(L, "unknown style");
|
||||
}
|
||||
@@ -459,7 +494,7 @@ static int luavgl_style_set(lua_State *L)
|
||||
luavgl_style_t *s = luavgl_check_style(L, 1);
|
||||
|
||||
if (!lua_istable(L, 2)) {
|
||||
luaL_argerror(L, 2, "expect a table on 2nd para.");
|
||||
luaL_argerror(L, 2, "expect a table on 2nd para");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -468,16 +503,21 @@ static int luavgl_style_set(lua_State *L)
|
||||
/* -1: value, -2: key */
|
||||
if (!lua_isstring(L, -2)) {
|
||||
/* we expect string as key, ignore it if not */
|
||||
debug("ignore non-string key in table.\n");
|
||||
LV_LOG_WARN("ignore non-string key in table");
|
||||
lua_pop(L, 1);
|
||||
continue;
|
||||
}
|
||||
|
||||
#if LV_VERSION_CHECK(8, 3, 0)
|
||||
/* special value check */
|
||||
bool inherit = luavgl_is_style_inherit(L);
|
||||
|
||||
luavgl_set_style_kv(L, inherit ? lv_style_set_inherit_cb : lv_style_set_cb,
|
||||
s);
|
||||
#else
|
||||
luavgl_set_style_kv(L, lv_style_set_cb, s);
|
||||
#endif
|
||||
|
||||
lua_pop(L, 1); /* remove value, keep the key to continue. */
|
||||
}
|
||||
|
||||
@@ -497,7 +537,7 @@ static int luavgl_style_create(lua_State *L)
|
||||
{
|
||||
luavgl_style_t *s = malloc(sizeof(luavgl_style_t));
|
||||
if (s == NULL) {
|
||||
return luaL_error(L, "No memory.");
|
||||
return luaL_error(L, "No memory");
|
||||
}
|
||||
|
||||
lv_style_init(&s->style);
|
||||
@@ -528,7 +568,7 @@ static int luavgl_style_remove_prop(lua_State *L)
|
||||
|
||||
for (int i = 0; i < STYLE_MAP_LEN; i++) {
|
||||
const struct style_map_s *p = &g_style_map[i];
|
||||
if (strcmp(name, p->name) == 0) {
|
||||
if (lv_strcmp(name, p->name) == 0) {
|
||||
lv_style_remove_prop(&s->style, p->prop);
|
||||
return 0;
|
||||
}
|
||||
@@ -553,7 +593,7 @@ static int luavgl_style_gc(lua_State *L)
|
||||
luavgl_style_t *s = luavgl_check_style(L, 1);
|
||||
lv_style_reset(&s->style);
|
||||
free(s);
|
||||
debug("gc style:%p\n", s);
|
||||
LV_LOG_INFO("gc style:%p", s);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -573,6 +613,7 @@ static void obj_style_set_cb(lv_style_prop_t prop, lv_style_value_t value,
|
||||
lv_obj_set_local_style_prop(info->obj, prop, value, info->selector);
|
||||
}
|
||||
|
||||
#if LV_VERSION_CHECK(8, 3, 0)
|
||||
static void obj_style_inherit_set_cb(lv_style_prop_t prop,
|
||||
lv_style_value_t value, void *args)
|
||||
{
|
||||
@@ -580,6 +621,7 @@ static void obj_style_inherit_set_cb(lv_style_prop_t prop,
|
||||
lv_obj_set_local_style_prop_meta(info->obj, prop, LV_STYLE_PROP_META_INHERIT,
|
||||
info->selector);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int luavgl_obj_set_style_kv(lua_State *L, lv_obj_t *obj, int selector)
|
||||
{
|
||||
@@ -588,11 +630,15 @@ static int luavgl_obj_set_style_kv(lua_State *L, lv_obj_t *obj, int selector)
|
||||
.selector = selector,
|
||||
};
|
||||
|
||||
#if LV_VERSION_CHECK(8, 3, 0)
|
||||
/* special value check */
|
||||
bool inherit = luavgl_is_style_inherit(L);
|
||||
|
||||
return luavgl_set_style_kv(
|
||||
L, inherit ? obj_style_inherit_set_cb : obj_style_set_cb, &info);
|
||||
#else
|
||||
return luavgl_set_style_kv(L, obj_style_set_cb, &info);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -602,12 +648,12 @@ static int luavgl_obj_set_style(lua_State *L)
|
||||
{
|
||||
lv_obj_t *obj = luavgl_to_obj(L, 1);
|
||||
if (obj == NULL) {
|
||||
luaL_argerror(L, 1, "obj could already been deleted.");
|
||||
luaL_argerror(L, 1, "obj could already been deleted");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!lua_istable(L, 2)) {
|
||||
luaL_argerror(L, 2, "expect a table on 2nd para.");
|
||||
luaL_argerror(L, 2, "expect a table on 2nd para");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -622,7 +668,7 @@ static int luavgl_obj_set_style(lua_State *L)
|
||||
/* -1: value, -2: key */
|
||||
if (!lua_isstring(L, -2)) {
|
||||
/* we expect string as key, ignore it if not */
|
||||
debug("ignore non-string key in table.\n");
|
||||
LV_LOG_WARN("ignore non-string key in table");
|
||||
lua_pop(L, 1);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ static int timer_set_para_cb(lua_State *L, void *data)
|
||||
int ret = luavgl_set_property(L, data, timer_property_table);
|
||||
|
||||
if (ret != 0) {
|
||||
debug("failed\n");
|
||||
LV_LOG_ERROR("failed");
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -88,7 +88,7 @@ static int luavgl_timer_create(lua_State *L)
|
||||
{
|
||||
luavgl_timer_t *data = malloc(sizeof(luavgl_timer_t));
|
||||
if (data == NULL) {
|
||||
return luaL_error(L, "No memory.");
|
||||
return luaL_error(L, "No memory");
|
||||
}
|
||||
data->ref = LUA_NOREF;
|
||||
data->L = L;
|
||||
@@ -119,7 +119,7 @@ static int luavgl_timer_set(lua_State *L)
|
||||
{
|
||||
lv_timer_t *t = luavgl_check_timer(L, 1);
|
||||
if (t == NULL) {
|
||||
return luaL_argerror(L, 1, "timer is null.");
|
||||
return luaL_argerror(L, 1, "timer is null");
|
||||
}
|
||||
|
||||
luavgl_timer_setup(L, 2, t);
|
||||
@@ -130,7 +130,7 @@ static int luavgl_timer_ready(lua_State *L)
|
||||
{
|
||||
lv_timer_t *t = luavgl_check_timer(L, 1);
|
||||
if (t == NULL) {
|
||||
return luaL_argerror(L, 1, "timer is null.");
|
||||
return luaL_argerror(L, 1, "timer is null");
|
||||
}
|
||||
|
||||
lv_timer_ready(t);
|
||||
@@ -141,7 +141,7 @@ static int luavgl_timer_resume(lua_State *L)
|
||||
{
|
||||
lv_timer_t *t = luavgl_check_timer(L, 1);
|
||||
if (t == NULL) {
|
||||
return luaL_argerror(L, 1, "timer is null.");
|
||||
return luaL_argerror(L, 1, "timer is null");
|
||||
}
|
||||
|
||||
lv_timer_resume(t);
|
||||
@@ -152,7 +152,7 @@ static int luavgl_timer_pause(lua_State *L)
|
||||
{
|
||||
lv_timer_t *t = luavgl_check_timer(L, 1);
|
||||
if (t == NULL) {
|
||||
return luaL_argerror(L, 1, "timer is null.");
|
||||
return luaL_argerror(L, 1, "timer is null");
|
||||
}
|
||||
|
||||
lv_timer_pause(t);
|
||||
@@ -165,7 +165,7 @@ static int luavgl_timer_delete(lua_State *L)
|
||||
{
|
||||
lv_timer_t *t = luavgl_check_timer(L, 1);
|
||||
if (t == NULL) {
|
||||
return luaL_argerror(L, 1, "timer is null.");
|
||||
return luaL_argerror(L, 1, "timer is null");
|
||||
}
|
||||
|
||||
luavgl_timer_t *data = t->user_data;
|
||||
@@ -181,7 +181,7 @@ static int luavgl_timer_delete(lua_State *L)
|
||||
/* we can only release memory in gc, since we need t->use_data */
|
||||
lv_timer_pause(t);
|
||||
|
||||
debug("delete timer:%p\n", t);
|
||||
LV_LOG_INFO("delete timer:%p", t);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -194,7 +194,7 @@ static int luavgl_timer_gc(lua_State *L)
|
||||
free(t->user_data);
|
||||
lv_timer_del(t);
|
||||
|
||||
debug("gc timer:%p\n", t);
|
||||
LV_LOG_INFO("gc timer:%p", t);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
+29
-26
@@ -16,7 +16,7 @@ LUALIB_API luavgl_obj_t *luavgl_to_lobj(lua_State *L, int idx)
|
||||
return lobj;
|
||||
|
||||
fail:
|
||||
debug("arg not lv_obj userdata.\n");
|
||||
LV_LOG_ERROR("arg not lv_obj userdata");
|
||||
luaL_argerror(L, idx, "Expected lv_obj userdata");
|
||||
return NULL;
|
||||
}
|
||||
@@ -55,19 +55,19 @@ static void dumpvalue(lua_State *L, int i, bool cr)
|
||||
const char ending = cr ? '\n' : '\0';
|
||||
switch (lua_type(L, i)) {
|
||||
case LUA_TNUMBER:
|
||||
printf("number: %g%c", lua_tonumber(L, i), ending);
|
||||
LV_LOG_USER("number: %g%c", lua_tonumber(L, i), ending);
|
||||
break;
|
||||
case LUA_TSTRING:
|
||||
printf("string: %s%c", lua_tostring(L, i), ending);
|
||||
LV_LOG_USER("string: %s%c", lua_tostring(L, i), ending);
|
||||
break;
|
||||
case LUA_TBOOLEAN:
|
||||
printf("boolean: %s%c", (lua_toboolean(L, i) ? "true" : "false"), ending);
|
||||
LV_LOG_USER("boolean: %s%c", (lua_toboolean(L, i) ? "true" : "false"), ending);
|
||||
break;
|
||||
case LUA_TNIL:
|
||||
printf("nil: %s%c", "nil", ending);
|
||||
LV_LOG_USER("nil: %s%c", "nil", ending);
|
||||
break;
|
||||
default:
|
||||
printf("pointer: %p%c", lua_topointer(L, i), ending);
|
||||
LV_LOG_USER("pointer: %p%c", lua_topointer(L, i), ending);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -79,7 +79,7 @@ static void dumptable(lua_State *L, int index)
|
||||
while (lua_next(L, i)) {
|
||||
/* -1: value, -2: key */
|
||||
dumpvalue(L, -2, 0);
|
||||
printf(" ");
|
||||
LV_LOG_USER(" ");
|
||||
dumpvalue(L, -1, 1);
|
||||
lua_pop(L, 1); /* remove value, keep the key to continue. */
|
||||
}
|
||||
@@ -89,24 +89,22 @@ static void dumptable(lua_State *L, int index)
|
||||
static void dumpstack(lua_State *L)
|
||||
{
|
||||
int top = lua_gettop(L);
|
||||
printf("\n");
|
||||
for (int i = 1; i <= top; i++) {
|
||||
printf("%d\t%s\t", i, luaL_typename(L, i));
|
||||
switch (lua_type(L, i)) {
|
||||
case LUA_TNUMBER:
|
||||
printf("number: %g\n", lua_tonumber(L, i));
|
||||
LV_LOG_USER("%s: %g", luaL_typename(L, i), lua_tonumber(L, i));
|
||||
break;
|
||||
case LUA_TSTRING:
|
||||
printf("string: %s\n", lua_tostring(L, i));
|
||||
LV_LOG_USER("%s: %s", luaL_typename(L, i), lua_tostring(L, i));
|
||||
break;
|
||||
case LUA_TBOOLEAN:
|
||||
printf("boolean: %s\n", (lua_toboolean(L, i) ? "true" : "false"));
|
||||
LV_LOG_USER("%s: %s", luaL_typename(L, i), (lua_toboolean(L, i) ? "true" : "false"));
|
||||
break;
|
||||
case LUA_TNIL:
|
||||
printf("nil: %s\n", "nil");
|
||||
LV_LOG_USER("%s: %s", luaL_typename(L, i), "nil");
|
||||
break;
|
||||
default:
|
||||
printf("pointer: %p\n", lua_topointer(L, i));
|
||||
LV_LOG_USER("%s: %p", luaL_typename(L, i), lua_topointer(L, i));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -236,7 +234,7 @@ LUALIB_API int luavgl_pcall(lua_State *L, int nargs, int nresult)
|
||||
lua_insert(L, base); /* put it under function and args */
|
||||
int status = lua_pcall(L, nargs, nresult, base);
|
||||
if (status != LUA_OK) {
|
||||
debug("crashed\n%s", lua_tostring(L, -1));
|
||||
LV_LOG_ERROR("crashed\n%s", lua_tostring(L, -1));
|
||||
}
|
||||
lua_remove(L, base); /* remove message handler from the stack */
|
||||
|
||||
@@ -304,11 +302,11 @@ LUALIB_API lv_color_t luavgl_tocolor(lua_State *L, int idx)
|
||||
/* support #RGB and #RRGGBB */
|
||||
const char *s = lua_tostring(L, idx);
|
||||
if (s == NULL) {
|
||||
luaL_error(L, "unknown color.");
|
||||
luaL_error(L, "unknown color");
|
||||
return color;
|
||||
}
|
||||
|
||||
int len = strlen(s);
|
||||
int len = lv_strlen(s);
|
||||
if (len == 4 && s[0] == '#') {
|
||||
/* #RGB */
|
||||
int r = to_int(s[1]);
|
||||
@@ -325,7 +323,7 @@ LUALIB_API lv_color_t luavgl_tocolor(lua_State *L, int idx)
|
||||
int b = (to_int(s[5]) << 4) | to_int(s[6]);
|
||||
color = lv_color_make(r, g, b);
|
||||
} else {
|
||||
luaL_error(L, "unknown color format.");
|
||||
luaL_error(L, "unknown color format");
|
||||
return color;
|
||||
}
|
||||
} else {
|
||||
@@ -340,11 +338,11 @@ LUALIB_API const char *luavgl_toimgsrc(lua_State *L, int idx)
|
||||
const char *src = NULL;
|
||||
if (lua_isuserdata(L, idx)) {
|
||||
src = lua_touserdata(L, idx);
|
||||
debug("set img src to user data: %p\n", src);
|
||||
LV_LOG_INFO("set img src to user data: %p", src);
|
||||
} else if (lua_isstring(L, idx)) {
|
||||
src = lua_tostring(L, idx);
|
||||
} else {
|
||||
debug("img src should be string or userdata.\n");
|
||||
LV_LOG_ERROR("img src should be string or userdata");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -355,12 +353,13 @@ LUALIB_API void luavgl_iterate(lua_State *L, int index,
|
||||
int (*cb)(lua_State *, void *), void *cb_para)
|
||||
{
|
||||
int i = index < 0 ? index - 1 : index;
|
||||
|
||||
lua_pushnil(L); /* nil as initial key to iterate through table */
|
||||
while (lua_next(L, i)) {
|
||||
/* -1: value, -2: key */
|
||||
if (!lua_isstring(L, -2)) {
|
||||
/* we expect string as key, ignore it if not */
|
||||
debug("ignore non-string key in table.\n");
|
||||
LV_LOG_INFO("ignore non-string key in table");
|
||||
lua_pop(L, 1);
|
||||
continue;
|
||||
}
|
||||
@@ -376,13 +375,13 @@ LUALIB_API int luavgl_set_property_array(lua_State *L, void *obj,
|
||||
{
|
||||
const char *key = lua_tostring(L, -2);
|
||||
if (key == NULL) {
|
||||
debug("Null key, ignored.\n");
|
||||
LV_LOG_ERROR("Null key, ignored");
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
const luavgl_value_setter_t *p = &table[i];
|
||||
if (strcmp(key, p->key))
|
||||
if (lv_strcmp(key, p->key))
|
||||
continue;
|
||||
|
||||
if (p->type == SETTER_TYPE_INT) {
|
||||
@@ -397,8 +396,12 @@ LUALIB_API int luavgl_set_property_array(lua_State *L, void *obj,
|
||||
p->setter(obj, v);
|
||||
} else if (p->type == SETTER_TYPE_COLOR) {
|
||||
/* color */
|
||||
lv_color_t color = luavgl_tocolor(L, -1);
|
||||
p->setter(obj, color.full);
|
||||
union {
|
||||
lv_color_t c;
|
||||
uint32_t v;
|
||||
} color;
|
||||
color.c = luavgl_tocolor(L, -1);
|
||||
p->setter(obj, color.v);
|
||||
} else if (p->type == SETTER_TYPE_IMGSRC) {
|
||||
/* img src */
|
||||
p->setter_pointer(obj, (void *)luavgl_toimgsrc(L, -1));
|
||||
@@ -408,7 +411,7 @@ LUALIB_API int luavgl_set_property_array(lua_State *L, void *obj,
|
||||
void *data = lua_touserdata(L, -1);
|
||||
p->setter_pointer(obj, data);
|
||||
} else {
|
||||
debug("unsupported type: %d\n", p->type);
|
||||
LV_LOG_ERROR("unsupported type: %d", p->type);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ LUALIB_API int luavgl_calendar_set_property_kv(lua_State *L, void *data)
|
||||
/* a base obj property? */
|
||||
ret = luavgl_obj_set_property_kv(L, obj);
|
||||
if (ret != 0) {
|
||||
debug("unkown property for calendar.\n");
|
||||
LV_LOG_ERROR("unkown property for calendar.");
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
@@ -32,7 +32,7 @@ LUALIB_API int luavgl_checkbox_set_property_kv(lua_State *L, void *data)
|
||||
/* a base obj property? */
|
||||
ret = luavgl_obj_set_property_kv(L, obj);
|
||||
if (ret != 0) {
|
||||
debug("unkown property for checkbox.\n");
|
||||
LV_LOG_ERROR("unkown property for checkbox");
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
@@ -36,7 +36,7 @@ LUALIB_API int luavgl_dropdown_set_property_kv(lua_State *L, void *data)
|
||||
/* a base obj property? */
|
||||
ret = luavgl_obj_set_property_kv(L, obj);
|
||||
if (ret != 0) {
|
||||
debug("unkown property for dropdown.\n");
|
||||
LV_LOG_ERROR("unkown property for dropdown");
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -72,7 +72,7 @@ static int luavgl_dropdown_get(lua_State *L)
|
||||
}
|
||||
|
||||
const char *key = lua_tostring(L, 2);
|
||||
if (strcmp(key, "list") == 0) {
|
||||
if (lv_strcmp(key, "list") == 0) {
|
||||
lv_obj_t *list = lv_dropdown_get_list(obj);
|
||||
lua_pushlightuserdata(L, list);
|
||||
lua_rawget(L, LUA_REGISTRYINDEX);
|
||||
@@ -83,45 +83,47 @@ static int luavgl_dropdown_get(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (strcmp(key, "text") == 0) {
|
||||
if (lv_strcmp(key, "text") == 0) {
|
||||
lua_pushstring(L, lv_dropdown_get_text(obj));
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (strcmp(key, "options") == 0) {
|
||||
if (lv_strcmp(key, "options") == 0) {
|
||||
lua_pushstring(L, lv_dropdown_get_options(obj));
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (strcmp(key, "selected") == 0) {
|
||||
if (lv_strcmp(key, "selected") == 0) {
|
||||
lua_pushinteger(L, lv_dropdown_get_selected(obj));
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (strcmp(key, "option_cnt") == 0) {
|
||||
if (lv_strcmp(key, "option_cnt") == 0) {
|
||||
lua_pushinteger(L, lv_dropdown_get_option_cnt(obj));
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (strcmp(key, "selected_str") == 0) {
|
||||
if (lv_strcmp(key, "selected_str") == 0) {
|
||||
char buf[64];
|
||||
lv_dropdown_get_selected_str(obj, buf, sizeof(buf));
|
||||
lua_pushstring(L, buf);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (strcmp(key, "option_index") == 0) {
|
||||
#if LV_VERSION_CHECK(8, 3, 0)
|
||||
if (lv_strcmp(key, "option_index") == 0) {
|
||||
const char *option = lua_tostring(L, 3);
|
||||
lua_pushinteger(L, lv_dropdown_get_option_index(obj, option));
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (strcmp(key, "symbol") == 0) {
|
||||
if (lv_strcmp(key, "symbol") == 0) {
|
||||
lua_pushlightuserdata(L, (void *)lv_dropdown_get_symbol(obj));
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (strcmp(key, "dir") == 0) {
|
||||
if (lv_strcmp(key, "dir") == 0) {
|
||||
lua_pushinteger(L, lv_dropdown_get_dir(obj));
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -3,14 +3,14 @@
|
||||
|
||||
static int luavgl_img_create(lua_State *L)
|
||||
{
|
||||
return luavgl_obj_create_helper(L, lv_img_create);
|
||||
return luavgl_obj_create_helper(L, lv_image_create);
|
||||
}
|
||||
|
||||
static void _lv_img_set_pivot(void *obj, lua_State *L)
|
||||
static void lv_image_set_pivot_(void *obj, lua_State *L)
|
||||
{
|
||||
if (!lua_istable(L, -1)) {
|
||||
luaL_argerror(L, -1, "should be table.");
|
||||
debug("para should be table.");
|
||||
LV_LOG_ERROR("para should be table.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -22,18 +22,18 @@ static void _lv_img_set_pivot(void *obj, lua_State *L)
|
||||
lv_coord_t y = lua_tointeger(L, -1);
|
||||
lua_pop(L, 1);
|
||||
|
||||
lv_img_set_pivot(obj, x, y);
|
||||
lv_image_set_pivot(obj, x, y);
|
||||
}
|
||||
|
||||
static const luavgl_value_setter_t img_property_table[] = {
|
||||
{"src",
|
||||
SETTER_TYPE_IMGSRC, {.setter_pointer = (setter_pointer_t)lv_img_set_src}},
|
||||
{"offset_x", 0, {.setter = (setter_int_t)lv_img_set_offset_x} },
|
||||
{"offset_y", 0, {.setter = (setter_int_t)lv_img_set_offset_y} },
|
||||
SETTER_TYPE_IMGSRC, {.setter_pointer = (setter_pointer_t)lv_image_set_src}},
|
||||
{"offset_x", 0, {.setter = (setter_int_t)lv_image_set_offset_x} },
|
||||
{"offset_y", 0, {.setter = (setter_int_t)lv_image_set_offset_y} },
|
||||
{"angle", 0, {.setter = (setter_int_t)lv_img_set_angle} },
|
||||
{"zoom", 0, {.setter = (setter_int_t)lv_img_set_zoom} },
|
||||
{"antialias", 0, {.setter = (setter_int_t)lv_img_set_antialias} },
|
||||
{"pivot", SETTER_TYPE_STACK, {.setter_stack = _lv_img_set_pivot} },
|
||||
{"antialias", 0, {.setter = (setter_int_t)lv_image_set_antialias} },
|
||||
{"pivot", SETTER_TYPE_STACK, {.setter_stack = lv_image_set_pivot_} },
|
||||
};
|
||||
|
||||
LUALIB_API int luavgl_img_set_property_kv(lua_State *L, void *data)
|
||||
@@ -48,7 +48,7 @@ LUALIB_API int luavgl_img_set_property_kv(lua_State *L, void *data)
|
||||
/* a base obj property? */
|
||||
ret = luavgl_obj_set_property_kv(L, obj);
|
||||
if (ret != 0) {
|
||||
debug("unkown property for image.\n");
|
||||
LV_LOG_ERROR("unkown property for image");
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -69,11 +69,11 @@ static int luavgl_img_set(lua_State *L)
|
||||
const char *src = NULL;
|
||||
if (lua_isuserdata(L, -1)) {
|
||||
src = lua_touserdata(L, -1);
|
||||
debug("set img src to user data: %p\n", src);
|
||||
LV_LOG_INFO("set img src to user data: %p", src);
|
||||
} else {
|
||||
src = lua_tostring(L, -1);
|
||||
}
|
||||
lv_img_set_src(obj, src);
|
||||
lv_image_set_src(obj, src);
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
|
||||
@@ -90,7 +90,7 @@ static int luavgl_img_set_src(lua_State *L)
|
||||
lv_obj_t *obj = luavgl_to_obj(L, 1);
|
||||
const char *src = luavgl_toimgsrc(L, 2);
|
||||
if (src != NULL) {
|
||||
lv_img_set_src(obj, src);
|
||||
lv_image_set_src(obj, src);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -114,14 +114,14 @@ static int luavgl_img_set_offset(lua_State *L)
|
||||
if (!lua_isnil(L, -1)) {
|
||||
v = lua_tointeger(L, -1);
|
||||
lua_pop(L, 1);
|
||||
lv_img_set_offset_x(obj, v);
|
||||
lv_image_set_offset_x(obj, v);
|
||||
}
|
||||
|
||||
lua_getfield(L, -1, "y");
|
||||
if (!lua_isnil(L, -1)) {
|
||||
v = lua_tointeger(L, -1);
|
||||
lua_pop(L, 1);
|
||||
lv_img_set_offset_y(obj, v);
|
||||
lv_image_set_offset_y(obj, v);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -145,7 +145,7 @@ static int luavgl_img_set_pivot(lua_State *L)
|
||||
lua_getfield(L, -1, "y");
|
||||
y = lua_tointeger(L, -1);
|
||||
|
||||
lv_img_set_pivot(obj, x, y);
|
||||
lv_image_set_pivot(obj, x, y);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -161,13 +161,13 @@ static int luavgl_get_img_size(lua_State *L)
|
||||
|
||||
const void *src = NULL;
|
||||
if (lua_isnoneornil(L, 2)) {
|
||||
src = lv_img_get_src(obj);
|
||||
src = lv_image_get_src(obj);
|
||||
} else {
|
||||
src = luavgl_toimgsrc(L, 2);
|
||||
}
|
||||
|
||||
lv_img_header_t header;
|
||||
if (src == NULL || lv_img_decoder_get_info(src, &header) != LV_RES_OK) {
|
||||
lv_image_header_t header;
|
||||
if (src == NULL || lv_image_decoder_get_info(src, &header) != LV_RES_OK) {
|
||||
lua_pushnil(L);
|
||||
lua_pushnil(L);
|
||||
} else {
|
||||
@@ -191,6 +191,6 @@ static const luaL_Reg luavgl_img_methods[] = {
|
||||
|
||||
static void luavgl_img_init(lua_State *L)
|
||||
{
|
||||
luavgl_obj_newmetatable(L, &lv_img_class, "lv_img", luavgl_img_methods);
|
||||
luavgl_obj_newmetatable(L, &lv_image_class, "lv_img", luavgl_img_methods);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ LUALIB_API int luavgl_keyboard_set_property_kv(lua_State *L, void *data)
|
||||
/* a base obj property? */
|
||||
ret = luavgl_obj_set_property_kv(L, obj);
|
||||
if (ret != 0) {
|
||||
debug("unkown property for keyboard.\n");
|
||||
LV_LOG_ERROR("unkown property for keyboard");
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -67,7 +67,7 @@ static void luavgl_keyboard_init(lua_State *L)
|
||||
static const luaL_Reg btm_methods[] = {
|
||||
{NULL, NULL},
|
||||
};
|
||||
luavgl_obj_newmetatable(L, &lv_btnmatrix_class, "lv_btnm", btm_methods);
|
||||
luavgl_obj_newmetatable(L, &lv_buttonmatrix_class, "lv_btnm", btm_methods);
|
||||
lua_pop(L, 1);
|
||||
|
||||
luavgl_obj_newmetatable(L, &lv_keyboard_class, "lv_keyboard",
|
||||
|
||||
@@ -47,7 +47,7 @@ LUALIB_API int luavgl_label_set_property_kv(lua_State *L, void *data)
|
||||
/* a base obj property? */
|
||||
ret = luavgl_obj_set_property_kv(L, obj);
|
||||
if (ret != 0) {
|
||||
debug("unkown property for label.\n");
|
||||
LV_LOG_ERROR("unkown property for label");
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
@@ -25,7 +25,7 @@ LUALIB_API int luavgl_led_set_property_kv(lua_State *L, void *data)
|
||||
/* a base obj property? */
|
||||
ret = luavgl_obj_set_property_kv(L, obj);
|
||||
if (ret != 0) {
|
||||
debug("unkown property for led.\n");
|
||||
LV_LOG_ERROR("unkown property for led");
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
@@ -24,7 +24,7 @@ LUALIB_API int luavgl_list_set_property_kv(lua_State *L, void *data)
|
||||
/* a base obj property? */
|
||||
ret = luavgl_obj_set_property_kv(L, obj);
|
||||
if (ret != 0) {
|
||||
debug("unkown property for list.\n");
|
||||
LV_LOG_ERROR("unkown property for list");
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
@@ -69,7 +69,7 @@ LUALIB_API int luavgl_roller_set_property_kv(lua_State *L, void *data)
|
||||
/* a base obj property? */
|
||||
ret = luavgl_obj_set_property_kv(L, obj);
|
||||
if (ret != 0) {
|
||||
debug("unkown property for roller.\n");
|
||||
LV_LOG_ERROR("unkown property for roller");
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
@@ -28,12 +28,14 @@ static void _lv_textarea_set_placeholder_txt(void *obj, lua_State *L)
|
||||
|
||||
static void _lv_textarea_set_password_bullet(void *obj, lua_State *L)
|
||||
{
|
||||
#if LV_VERSION_CHECK(8, 3, 0)
|
||||
if (!lua_isstring(L, -1)) {
|
||||
luaL_argerror(L, -1, "expect string");
|
||||
return;
|
||||
}
|
||||
|
||||
lv_textarea_set_password_bullet(obj, lua_tostring(L, -1));
|
||||
#endif
|
||||
}
|
||||
|
||||
static void _lv_textarea_set_accepted_chars(void *obj, lua_State *L)
|
||||
@@ -72,7 +74,7 @@ LUALIB_API int luavgl_textarea_set_property_kv(lua_State *L, void *data)
|
||||
/* a base obj property? */
|
||||
ret = luavgl_obj_set_property_kv(L, obj);
|
||||
if (ret != 0) {
|
||||
debug("unkown property for textarea: %s\n", lua_tostring(L, -2));
|
||||
LV_LOG_ERROR("unkown property for textarea: %s", lua_tostring(L, -2));
|
||||
}
|
||||
|
||||
return -1;
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#include "dropdown.c"
|
||||
#endif
|
||||
|
||||
#if LV_USE_IMG
|
||||
#if LV_USE_IMAGE
|
||||
#include "img.c"
|
||||
#endif
|
||||
|
||||
@@ -82,7 +82,7 @@ static const luaL_Reg widget_create_methods[] = {
|
||||
{"Dropdown", luavgl_dropdown_create},
|
||||
#endif
|
||||
|
||||
#if LV_USE_IMG
|
||||
#if LV_USE_IMAGE
|
||||
{"Image", luavgl_img_create },
|
||||
#endif
|
||||
|
||||
@@ -122,7 +122,7 @@ static const luaL_Reg widget_create_methods[] = {
|
||||
|
||||
static void luavgl_widgets_init(lua_State *L)
|
||||
{
|
||||
#if LV_USE_IMG
|
||||
#if LV_USE_IMAGE
|
||||
luavgl_img_init(L);
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user