Add 'btn' support to luavgl
This commit is contained in:
+28
-1
@@ -335,6 +335,13 @@ end
|
||||
function lvgl.Object(parent, property)
|
||||
end
|
||||
|
||||
--- Create Button widget on parent
|
||||
--- @param parent? Object | nil
|
||||
--- @param property? StyleProp
|
||||
--- @return Button
|
||||
function lvgl.Button(parent, property)
|
||||
end
|
||||
|
||||
--- Create Calendar widget on parent
|
||||
--- @param parent? Object | nil
|
||||
--- @param property? StyleProp
|
||||
@@ -342,7 +349,6 @@ end
|
||||
function lvgl.Calendar(parent, property)
|
||||
end
|
||||
|
||||
|
||||
---
|
||||
--- Create Label on parent
|
||||
--- @param parent? Object | nil
|
||||
@@ -465,6 +471,13 @@ obj = {}
|
||||
function obj:Object(property)
|
||||
end
|
||||
|
||||
---
|
||||
--- Create button on object
|
||||
--- @param property? ButtonStyle
|
||||
--- @return Button
|
||||
function obj:Button(property)
|
||||
end
|
||||
|
||||
---
|
||||
--- Create calendar on object
|
||||
--- @param property? CalendarStyle
|
||||
@@ -853,6 +866,18 @@ end
|
||||
function calendar:Dropdown(p)
|
||||
end
|
||||
|
||||
---
|
||||
--- Button widget
|
||||
---@class Button:Object
|
||||
---
|
||||
local button = {}
|
||||
|
||||
--- set method for button widget
|
||||
--- @param p ButtonStyle
|
||||
--- @return nil
|
||||
function button:set(p)
|
||||
end
|
||||
|
||||
---
|
||||
--- Checkbox widget
|
||||
---@class Checkbox:Object
|
||||
@@ -1350,6 +1375,8 @@ end
|
||||
--- @class LabelStyle :StyleProp
|
||||
--- @field text string
|
||||
|
||||
--- Button style
|
||||
--- @class ButtonStyle :StyleProp
|
||||
|
||||
--- Checkbox style
|
||||
--- @class CalendarStyle :StyleProp
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
#include "luavgl.h"
|
||||
#include "private.h"
|
||||
|
||||
static int luavgl_btn_create(lua_State *L)
|
||||
{
|
||||
return luavgl_obj_create_helper(L, lv_btn_create);
|
||||
}
|
||||
|
||||
LUALIB_API int luavgl_btn_set_property_kv(lua_State *L, void *data)
|
||||
{
|
||||
lv_obj_t *obj = data;
|
||||
/* a base obj property? */
|
||||
int ret = luavgl_obj_set_property_kv(L, obj);
|
||||
if (ret != 0) {
|
||||
debug("unkown property for btn.\n");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int luavgl_btn_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_btn_set_property_kv, obj);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int luavgl_btn_tostring(lua_State *L)
|
||||
{
|
||||
lv_obj_t *obj = luavgl_to_obj(L, 1);
|
||||
lua_pushfstring(L, "lv_btn:%p", obj);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg luavgl_btn_methods[] = {
|
||||
{"set", luavgl_btn_set },
|
||||
{NULL, NULL },
|
||||
};
|
||||
|
||||
static void luavgl_btn_init(lua_State *L)
|
||||
{
|
||||
luavgl_obj_newmetatable(L, &lv_btn_class, "lv_btn", luavgl_btn_methods);
|
||||
lua_pushcfunction(L, luavgl_btn_tostring);
|
||||
lua_setfield(L, -2, "__tostring");
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
@@ -1,6 +1,10 @@
|
||||
#include "luavgl.h"
|
||||
#include "private.h"
|
||||
|
||||
#if LV_USE_BTN
|
||||
#include "btn.c"
|
||||
#endif
|
||||
|
||||
#if LV_USE_CALENDAR
|
||||
#include "calendar.c"
|
||||
#endif
|
||||
@@ -46,6 +50,10 @@ static int luavgl_obj_create(lua_State *L);
|
||||
static const luaL_Reg widget_create_methods[] = {
|
||||
{"Object", luavgl_obj_create },
|
||||
|
||||
#if LV_USE_BTN
|
||||
{"Button", luavgl_btn_create},
|
||||
#endif
|
||||
|
||||
#if LV_USE_CALENDAR
|
||||
{"Calendar", luavgl_calendar_create},
|
||||
#endif
|
||||
@@ -130,4 +138,8 @@ static void luavgl_widgets_init(lua_State *L)
|
||||
luavgl_dropdown_init(L);
|
||||
#endif
|
||||
|
||||
#if LV_USE_BTN
|
||||
luavgl_btn_init(L);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user