diff options
| author | jacqueline <me@jacqueline.id.au> | 2023-11-12 19:14:09 +1100 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2023-11-12 19:14:09 +1100 |
| commit | 8a0a167adbf3d9b6f8b6f16aaf20ca39ad5549de (patch) | |
| tree | 02b6cf23f591915747ec2994381854a79979c4a0 /lib/luavgl/src/widgets/checkbox.c | |
| parent | 8471046a95ab9e00f7d42b56dbbc9ce3e5b424b9 (diff) | |
| download | tangara-fw-8a0a167adbf3d9b6f8b6f16aaf20ca39ad5549de.tar.gz | |
Convert the main menu screen to lua lol
Diffstat (limited to 'lib/luavgl/src/widgets/checkbox.c')
| -rw-r--r-- | lib/luavgl/src/widgets/checkbox.c | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/lib/luavgl/src/widgets/checkbox.c b/lib/luavgl/src/widgets/checkbox.c new file mode 100644 index 00000000..e7885c8e --- /dev/null +++ b/lib/luavgl/src/widgets/checkbox.c @@ -0,0 +1,74 @@ +#include "luavgl.h" +#include "private.h" + +static int luavgl_checkbox_create(lua_State *L) +{ + return luavgl_obj_create_helper(L, lv_checkbox_create); +} + +static void _lv_checkbox_set_txt(void *obj, lua_State *L) +{ + if (!lua_isstring(L, -1)) { + luaL_argerror(L, -1, "only support string for text."); + return; + } + + lv_checkbox_set_text(obj, lua_tostring(L, -1)); +} + +static const luavgl_value_setter_t checkbox_property_table[] = { + {"text", SETTER_TYPE_STACK, {.setter_stack = _lv_checkbox_set_txt}}, +}; + +LUALIB_API int luavgl_checkbox_set_property_kv(lua_State *L, void *data) +{ + lv_obj_t *obj = data; + int ret = luavgl_set_property(L, obj, checkbox_property_table); + + if (ret == 0) { + return 0; + } + + /* a base obj property? */ + ret = luavgl_obj_set_property_kv(L, obj); + if (ret != 0) { + debug("unkown property for checkbox.\n"); + } + + return ret; +} + +static int luavgl_checkbox_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; + } + + luavgl_iterate(L, -1, luavgl_checkbox_set_property_kv, obj); + + return 0; +} + +static int luavgl_checkbox_get_text(lua_State *L) +{ + lv_obj_t *obj = luavgl_to_obj(L, 1); + lua_pushstring(L, lv_checkbox_get_text(obj)); + return 1; +} + +static const luaL_Reg luavgl_checkbox_methods[] = { + {"set", luavgl_checkbox_set }, + {"get_text", luavgl_checkbox_get_text}, + + {NULL, NULL }, +}; + +static void luavgl_checkbox_init(lua_State *L) +{ + luavgl_obj_newmetatable(L, &lv_checkbox_class, "lv_checkbox", + luavgl_checkbox_methods); + lua_pop(L, 1); +} |
