summaryrefslogtreecommitdiff
path: root/lib/luavgl/src
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2023-11-20 16:59:53 +1100
committerjacqueline <me@jacqueline.id.au>2023-11-20 16:59:53 +1100
commitf34b6405884c4073158c3f36158c6351fa135a0f (patch)
tree5ca5ebd1d19cb568dd402c1e53bfffdc86101acf /lib/luavgl/src
parent5c7f07e638c50a7b063009718f8ab35c0ce7fa44 (diff)
downloadtangara-fw-f34b6405884c4073158c3f36158c6351fa135a0f.tar.gz
Add 'btn' support to luavgl
Diffstat (limited to 'lib/luavgl/src')
-rw-r--r--lib/luavgl/src/lvgl.lua29
-rw-r--r--lib/luavgl/src/widgets/btn.c53
-rw-r--r--lib/luavgl/src/widgets/widgets.c12
3 files changed, 93 insertions, 1 deletions
diff --git a/lib/luavgl/src/lvgl.lua b/lib/luavgl/src/lvgl.lua
index db1ee349..f30335cb 100644
--- a/lib/luavgl/src/lvgl.lua
+++ b/lib/luavgl/src/lvgl.lua
@@ -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
@@ -466,6 +472,13 @@ 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
--- @return Calendar
@@ -854,6 +867,18 @@ 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
diff --git a/lib/luavgl/src/widgets/btn.c b/lib/luavgl/src/widgets/btn.c
new file mode 100644
index 00000000..848b0b45
--- /dev/null
+++ b/lib/luavgl/src/widgets/btn.c
@@ -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);
+}
diff --git a/lib/luavgl/src/widgets/widgets.c b/lib/luavgl/src/widgets/widgets.c
index d26cdf95..19b789a7 100644
--- a/lib/luavgl/src/widgets/widgets.c
+++ b/lib/luavgl/src/widgets/widgets.c
@@ -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
+
}