Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/constants.c
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,15 @@ static void luavgl_constants_init(lua_State *L)
lua_setfield(L, -2, "TEXTAREA_CURSOR_LAST");
#endif

#if LV_USE_ARC
lua_pushinteger(L, LV_ARC_MODE_NORMAL);
lua_setfield(L, -2, "ARC_MODE_NORMAL");
lua_pushinteger(L, LV_ARC_MODE_SYMMETRICAL);
lua_setfield(L, -2, "ARC_MODE_SYMMETRICAL");
lua_pushinteger(L, LV_ARC_MODE_REVERSE);
lua_setfield(L, -2, "ARC_MODE_REVERSE");
#endif

lua_pushinteger(L, LV_LAYOUT_FLEX);
lua_setfield(L, -2, "LAYOUT_FLEX");

Expand Down
162 changes: 162 additions & 0 deletions src/widgets/arc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
#include "luavgl.h"
#include "private.h"
#include "rotable.h"

static int luavgl_arc_create(lua_State *L)
{
return luavgl_obj_create_helper(L, lv_arc_create);
}

static int arc_set_start_angle(lua_State *L, lv_obj_t *obj, bool set)
{
if (!set) {
lua_pushnumber(L, lv_arc_get_angle_start(obj));
return 1;
}
lv_value_precise_t start_angle = lua_tonumber(L, -1);
lv_arc_set_start_angle(obj, start_angle);
return 1;
}

static int arc_set_end_angle(lua_State *L, lv_obj_t *obj, bool set)
{
if (!set) {
lua_pushnumber(L, lv_arc_get_angle_end(obj));
return 1;
}
lv_value_precise_t end_angle = lua_tonumber(L, -1);
lv_arc_set_end_angle(obj, end_angle);
return 1;
}

static int arc_set_bg_start_angle(lua_State *L, lv_obj_t *obj, bool set)
{
if (!set) {
lua_pushnumber(L, lv_arc_get_angle_start(obj));
return 1;
}
lv_value_precise_t start_angle = lua_tonumber(L, -1);
lv_arc_set_bg_start_angle(obj, start_angle);
return 1;
}

static int arc_set_bg_end_angle(lua_State *L, lv_obj_t *obj, bool set)
{
if (!set) {
lua_pushnumber(L, lv_arc_get_angle_end(obj));
return 1;
}
lv_value_precise_t end_angle = lua_tonumber(L, -1);
lv_arc_set_bg_end_angle(obj, end_angle);
return 1;
}

static int arc_set_rotation(lua_State *L, lv_obj_t *obj, bool set)
{
if (!set) {
lua_pushinteger(L, lv_arc_get_rotation(obj));
return 1;
}
int32_t rotation = lua_tointeger(L, -1);
lv_arc_set_rotation(obj, rotation);
return 1;
}

static int arc_set_value(lua_State *L, lv_obj_t *obj, bool set)
{
if (!set) {
lua_pushinteger(L, lv_arc_get_value(obj));
return 1;
}
int32_t value = lua_tointeger(L, -1);
lv_arc_set_value(obj, value);
return 1;
}

static int arc_set_min_value(lua_State *L, lv_obj_t *obj, bool set)
{
if (!set) {
lua_pushinteger(L, lv_arc_get_min_value(obj));
return 1;
}
int32_t min_value = lua_tointeger(L, -1);
lv_arc_set_min_value(obj, min_value);

Check failure on line 83 in src/widgets/arc.c

View workflow job for this annotation

GitHub Actions / Build on ubuntu-latest

implicit declaration of function ‘lv_arc_set_min_value’; did you mean ‘lv_arc_get_min_value’? [-Werror=implicit-function-declaration]
return 1;
}

static int arc_set_max_value(lua_State *L, lv_obj_t *obj, bool set)
{
if (!set) {
lua_pushinteger(L, lv_arc_get_max_value(obj));
return 1;
}
int32_t max_value = lua_tointeger(L, -1);
lv_arc_set_max_value(obj, max_value);

Check failure on line 94 in src/widgets/arc.c

View workflow job for this annotation

GitHub Actions / Build on ubuntu-latest

implicit declaration of function ‘lv_arc_set_max_value’; did you mean ‘lv_arc_get_max_value’? [-Werror=implicit-function-declaration]
return 1;
}

static int arc_set_knob_offset(lua_State *L, lv_obj_t *obj, bool set)
{
if (!set) {
lua_pushinteger(L, lv_arc_get_knob_offset(obj));
return 1;
}
int32_t knob_offset = lua_tointeger(L, -1);
lv_arc_set_knob_offset(obj, knob_offset);
return 1;
}

static int arc_set_mode(lua_State *L, lv_obj_t *obj, bool set)
{
if (!set) {
lua_pushinteger(L, lv_arc_get_mode(obj));
return 1;
}
int32_t mode = lua_tointeger(L, -1);
lv_arc_set_mode(obj, mode);
return 1;
}

static const luavgl_property_ops_t arc_property_ops[] = {
{.name = "start_angle", .ops = arc_set_start_angle },
{.name = "end_angle", .ops = arc_set_end_angle },
{.name = "bg_start_angle", .ops = arc_set_bg_start_angle},
{.name = "bg_end_angle", .ops = arc_set_bg_end_angle },
{.name = "rotation", .ops = arc_set_rotation },
{.name = "value", .ops = arc_set_value },
{.name = "min_value", .ops = arc_set_min_value },
{.name = "max_value", .ops = arc_set_max_value },
{.name = "knob_offset", .ops = arc_set_knob_offset },
{.name = "mode", .ops = arc_set_mode },
};

static const luavgl_table_t arc_property_table = {
.len = sizeof(arc_property_ops) / sizeof(arc_property_ops[0]),
.array = arc_property_ops,
};

static int luavgl_arc_rotate_obj_to_angle(lua_State *L)
{
lv_obj_t *obj = luavgl_to_obj(L, 1), *obj_to_rotate = luavgl_to_obj(L, 2);

int32_t r_offset = 0;
if (lua_isinteger(L, 3)) {
r_offset = lua_tointeger(L, 3);
}
lv_arc_rotate_obj_to_angle(obj, obj_to_rotate, r_offset);
return 0;
}

static const rotable_Reg luavgl_arc_methods[] = {
{"__property", LUA_TLIGHTUSERDATA, {.ptr = &arc_property_table}},

{"rotate_obj_to_angle",
LUA_TFUNCTION, {.ptr = luavgl_arc_rotate_obj_to_angle}},
{},
};

static void luavgl_arc_init(lua_State *L)
{
luavgl_obj_newmetatable(L, &lv_arc_class, "lv_arc", luavgl_arc_methods);
lua_pop(L, 1);
}
12 changes: 12 additions & 0 deletions src/widgets/widgets.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#include "luavgl.h"
#include "private.h"

#if LV_USE_ARC
#include "arc.c"
#endif

#if LV_USE_CALENDAR
#include "calendar.c"
#endif
Expand Down Expand Up @@ -50,6 +54,10 @@ static int luavgl_obj_create(lua_State *L);
static const luaL_Reg widget_create_methods[] = {
{"Object", luavgl_obj_create },

#if LV_USE_ARC
{"Arc", luavgl_arc_create },
#endif

#if LV_USE_CALENDAR
{"Calendar", luavgl_calendar_create},
#endif
Expand Down Expand Up @@ -102,6 +110,10 @@ static void luavgl_widgets_init(lua_State *L)
luavgl_img_init(L);
#endif

#if LV_USE_ARC
luavgl_arc_init(L);
#endif

#if LV_USE_LABEL
luavgl_label_init(L);
#endif
Expand Down
Loading