diff --git a/bsp/lvgl-vs-simu/LVGL.Simulator/.vscode/settings.json b/bsp/lvgl-vs-simu/LVGL.Simulator/.vscode/settings.json index f17651b13..e9ce25190 100644 --- a/bsp/lvgl-vs-simu/LVGL.Simulator/.vscode/settings.json +++ b/bsp/lvgl-vs-simu/LVGL.Simulator/.vscode/settings.json @@ -18,6 +18,15 @@ "pika_lvgl_textarea.h": "c", "pika_lvgl_align_cls.h": "c", "pika_lvgl_palette_cls.h": "c", - "pika_lvgl_lv_event.h": "c" + "pika_lvgl_lv_event.h": "c", + "pika_lvgl_style_t.h": "c", + "pika_lvgl_align.h": "c", + "pika_lvgl_event.h": "c", + "pika_lvgl_opa.h": "c", + "pika_lvgl_palette.h": "c", + "pika_lvgl_state.h": "c", + "pika_lvgl_anim.h": "c", + "pika_lvgl_indev_t.h": "c", + "pika_lvgl_point_t.h": "c" } } \ No newline at end of file diff --git a/bsp/lvgl-vs-simu/LVGL.Simulator/LVGL.Simulator.vcxproj b/bsp/lvgl-vs-simu/LVGL.Simulator/LVGL.Simulator.vcxproj index 35d1878ba..2b4511c8b 100644 --- a/bsp/lvgl-vs-simu/LVGL.Simulator/LVGL.Simulator.vcxproj +++ b/bsp/lvgl-vs-simu/LVGL.Simulator/LVGL.Simulator.vcxproj @@ -54,8 +54,10 @@ + + @@ -74,12 +76,14 @@ + + @@ -121,8 +125,10 @@ + + @@ -141,12 +147,14 @@ + + @@ -173,9 +181,12 @@ + + + @@ -188,6 +199,7 @@ + @@ -197,6 +209,7 @@ + diff --git a/bsp/lvgl-vs-simu/LVGL.Simulator/LVGL.Simulator.vcxproj.filters b/bsp/lvgl-vs-simu/LVGL.Simulator/LVGL.Simulator.vcxproj.filters index f76fb4e95..d9764b41f 100644 --- a/bsp/lvgl-vs-simu/LVGL.Simulator/LVGL.Simulator.vcxproj.filters +++ b/bsp/lvgl-vs-simu/LVGL.Simulator/LVGL.Simulator.vcxproj.filters @@ -69,6 +69,10 @@ + + + + @@ -164,6 +168,15 @@ + + + + + + + + + diff --git a/bsp/lvgl-vs-simu/LVGL.Simulator/pikascript/main.py b/bsp/lvgl-vs-simu/LVGL.Simulator/pikascript/main.py index fc43ddc32..23431fa7c 100644 --- a/bsp/lvgl-vs-simu/LVGL.Simulator/pikascript/main.py +++ b/bsp/lvgl-vs-simu/LVGL.Simulator/pikascript/main.py @@ -2,11 +2,23 @@ import pika_lvgl as lv import PikaStdLib mem = PikaStdLib.MemChecker() -# Create an Arc -arc = lv.arc(lv.scr_act()) -arc.set_end_angle(200) -arc.set_size(150, 150) -arc.center() + +def event_cb_1(evt): + print('in evt1') + print('mem used now: %0.2f kB' % (mem.getNow())) + + +def event_cb_2(evt): + print('in evt2') + print('mem used now: %0.2f kB' % (mem.getNow())) + + +btn1 = lv.btn(lv.scr_act()) +btn1.align(lv.ALIGN.TOP_MID, 0, 10) +btn2 = lv.btn(lv.scr_act()) +btn2.align(lv.ALIGN.TOP_MID, 0, 50) +btn1.add_event_cb(event_cb_1, lv.EVENT.CLICKED, 0) +btn2.add_event_cb(event_cb_2, lv.EVENT.CLICKED, 0) print('mem used max: %0.2f kB' % (mem.getMax())) print('mem used now: %0.2f kB' % (mem.getNow())) diff --git a/bsp/lvgl-vs-simu/LVGL.Simulator/pikascript/requestment.txt b/bsp/lvgl-vs-simu/LVGL.Simulator/pikascript/requestment.txt index 94b821245..b983f8f19 100644 --- a/bsp/lvgl-vs-simu/LVGL.Simulator/pikascript/requestment.txt +++ b/bsp/lvgl-vs-simu/LVGL.Simulator/pikascript/requestment.txt @@ -1,3 +1,2 @@ -pikascript-core==v1.8.8 -PikaStdLib==v1.8.8 -pika_lvgl==latest +pikascript-core==v1.10.0 +PikaStdLib==v1.10.0 \ No newline at end of file diff --git a/examples/lvgl/lv_drag.py b/examples/lvgl/lv_drag.py new file mode 100644 index 000000000..d025bf8ab --- /dev/null +++ b/examples/lvgl/lv_drag.py @@ -0,0 +1,30 @@ +import pika_lvgl as lv +from PikaStdLib import MemChecker + +mem = MemChecker() + +def drag_event_handler(e): + + obj = e.get_target() + + indev = lv.indev_get_act() + + vect = lv.point_t() + indev.get_vect(vect) + x = obj.get_x() + vect.x + y = obj.get_y() + vect.y + obj.set_pos(x, y) + mem.now() + + +# +# Make an object dragable. +# + +obj = lv.obj(lv.scr_act()) +obj.set_size(150, 100) +obj.add_event_cb(drag_event_handler, lv.EVENT.PRESSING, None) + +label = lv.label(obj) +label.set_text("Drag me") +label.center() diff --git a/examples/lvgl/lv_obj3.py b/examples/lvgl/lv_obj3.py new file mode 100644 index 000000000..cabf6ebac --- /dev/null +++ b/examples/lvgl/lv_obj3.py @@ -0,0 +1,20 @@ +import pika_lvgl as lv +import PikaStdLib +mem = PikaStdLib.MemChecker() + +obj1 = lv.obj(lv.scr_act()) +obj1.set_size(100, 50) +obj1.align(lv.ALIGN.CENTER, -60, -30) + +style_shadow = lv.style_t() +style_shadow.init() +style_shadow.set_shadow_width(10) +style_shadow.set_shadow_spread(5) +style_shadow.set_shadow_color(lv.palette_main(lv.PALETTE.BLUE)) + +obj2 = lv.obj(lv.scr_act()) +obj2.add_style(style_shadow, 0) +obj2.align(lv.ALIGN.CENTER, 60, 30) + +print('mem used max: %0.2f kB' % (mem.getMax())) +print('mem used now: %0.2f kB' % (mem.getNow())) diff --git a/package/pika_lvgl/pika_lv_point_t.c b/package/pika_lvgl/pika_lv_point_t.c new file mode 100644 index 000000000..0da53f551 --- /dev/null +++ b/package/pika_lvgl/pika_lv_point_t.c @@ -0,0 +1,8 @@ +#include "lvgl.h" +#include "pika_lvgl_point_t.h" + +void pika_lvgl_point_t___init__(PikaObj* self) { + lv_point_t lv_point = {0}; + args_setStruct(self->list, "lv_point_struct", lv_point); + obj_setPtr(self, "lv_point", args_getStruct(self->list, "lv_point_struct")); +} diff --git a/package/pika_lvgl/pika_lvgl.c b/package/pika_lvgl/pika_lvgl.c index b89c4cf41..65f05e058 100644 --- a/package/pika_lvgl/pika_lvgl.c +++ b/package/pika_lvgl/pika_lvgl.c @@ -10,6 +10,7 @@ #include "pika_lvgl_arc.h" #include "pika_lvgl_lv_color_t.h" #include "pika_lvgl_lv_obj.h" +#include "pika_lvgl_indev_t.h" PikaObj* pika_lv_event_listener_g; @@ -157,7 +158,7 @@ PikaObj* pika_lvgl_obj(PikaObj* self, PikaObj* parent) { return new_obj; } -PikaObj* pika_lvgl_palette_lighten(PikaObj* self, int lvl, int p) { +PikaObj* pika_lvgl_palette_lighten(PikaObj *self, int p, int lvl){ PikaObj* new_obj = newNormalObj(New_pika_lvgl_lv_color_t); lv_color_t lv_color = lv_palette_lighten(p, lvl); args_setStruct(new_obj->list, "lv_color_struct", lv_color); @@ -174,3 +175,10 @@ PikaObj* pika_lvgl_palette_main(PikaObj* self, int p) { args_getStruct(new_obj->list, "lv_color_struct")); return new_obj; } + +PikaObj* pika_lvgl_indev_get_act(PikaObj *self){ + PikaObj* new_obj = newNormalObj(New_pika_lvgl_indev_t); + lv_indev_t *lv_indev = lv_indev_get_act(); + obj_setPtr(new_obj,"lv_indev", lv_indev); + return new_obj; +} diff --git a/package/pika_lvgl/pika_lvgl.pyi b/package/pika_lvgl/pika_lvgl.pyi index 1e363a274..6283c5902 100644 --- a/package/pika_lvgl/pika_lvgl.pyi +++ b/package/pika_lvgl/pika_lvgl.pyi @@ -3,6 +3,7 @@ from PikaObj import * def __init__(): ... + class EVENT(TinyObj): ALL: int PRESSED: int @@ -114,12 +115,14 @@ class ANIM(TinyObj): ON: int def __init__(self): ... + class STATE(TinyObj): def __init__(self): ... class lv_event(TinyObj): def get_code(self) -> int: ... + def get_target(self) -> lv_obj: ... class lv_color_t(TinyObj): @@ -139,6 +142,9 @@ class style_t(TinyObj): def set_outline_width(self, w: int): ... def set_outline_color(self, color: lv_color_t): ... def set_outline_pad(self, pad: int): ... + def set_shadow_width(self, w: int): ... + def set_shadow_spread(self, s: int): ... + def set_shadow_color(self, color: lv_color_t): ... class lv_obj(TinyObj): @@ -151,9 +157,21 @@ class lv_obj(TinyObj): def add_state(self, state: int): ... def add_event_cb(self, event_cb: any, filter: int, user_data: pointer): ... def add_style(self, style: style_t, selector: int): ... + def get_x(self) -> int: ... + def get_y(self) -> int: ... + def set_pos(self, x: int, y: int): ... + + +class indev_t(TinyObj): + def get_vect(self, point: point_t): ... def obj(parent: lv_obj) -> lv_obj: ... +def indev_get_act() -> indev_t: ... + + +class point_t(TinyObj): + def __init__(self): ... class arc(lv_obj): diff --git a/package/pika_lvgl/pika_lvgl_arc.c b/package/pika_lvgl/pika_lvgl_arc.c index 11863638e..a0f88b44d 100644 --- a/package/pika_lvgl/pika_lvgl_arc.c +++ b/package/pika_lvgl/pika_lvgl_arc.c @@ -15,12 +15,12 @@ void pika_lvgl_arc_set_end_angle(PikaObj* self, int angle) { lv_arc_set_end_angle(lv_obj, angle); } -void pika_lvgl_arc_set_bg_angles(PikaObj* self, int end, int start) { +void pika_lvgl_arc_set_bg_angles(PikaObj *self, int start, int end){ lv_obj_t* lv_obj = obj_getPtr(self, "lv_obj"); lv_arc_set_bg_angles(lv_obj, start, end); } -void pika_lvgl_arc_set_angles(PikaObj* self, int end, int start) { +void pika_lvgl_arc_set_angles(PikaObj *self, int start, int end){ lv_obj_t* lv_obj = obj_getPtr(self, "lv_obj"); lv_arc_set_angles(lv_obj, start, end); } diff --git a/package/pika_lvgl/pika_lvgl_bar.c b/package/pika_lvgl/pika_lvgl_bar.c index 14d7c9481..0c1aadfbc 100644 --- a/package/pika_lvgl/pika_lvgl_bar.c +++ b/package/pika_lvgl/pika_lvgl_bar.c @@ -7,7 +7,7 @@ void pika_lvgl_bar___init__(PikaObj* self, PikaObj* parent) { obj_setPtr(self, "lv_obj", lv_obj); } -void pika_lvgl_bar_set_value(PikaObj* self, int anim, int value) { +void pika_lvgl_bar_set_value(PikaObj *self, int value, int anim){ lv_obj_t* lv_obj = obj_getPtr(self, "lv_obj"); lv_bar_set_value(lv_obj, value, value); } diff --git a/package/pika_lvgl/pika_lvgl_indev_t.c b/package/pika_lvgl/pika_lvgl_indev_t.c new file mode 100644 index 000000000..53f164b08 --- /dev/null +++ b/package/pika_lvgl/pika_lvgl_indev_t.c @@ -0,0 +1,10 @@ +#include "pika_lvgl_indev_t.h" +#include "lvgl.h" + +void pika_lvgl_indev_t_get_vect(PikaObj* self, PikaObj* point) { + lv_indev_t* lv_indev = obj_getPtr(self, "lv_indev"); + lv_point_t* lv_point = obj_getPtr(point, "lv_point"); + lv_indev_get_vect(lv_indev, lv_point); + obj_setInt(point, "x", lv_point->x); + obj_setInt(point, "y", lv_point->y); +} diff --git a/package/pika_lvgl/pika_lvgl_label.c b/package/pika_lvgl/pika_lvgl_label.c index 6dec11337..97ee15eb8 100644 --- a/package/pika_lvgl/pika_lvgl_label.c +++ b/package/pika_lvgl/pika_lvgl_label.c @@ -23,8 +23,8 @@ void pika_lvgl_label_set_text(PikaObj* self, char* txt) { } void pika_lvgl_label_set_style_text_align(PikaObj* self, - int selector, - int value) { + int value, + int selector) { lv_obj_t* lv_obj = obj_getPtr(self, "lv_obj"); lv_obj_set_style_text_align(lv_obj, value, selector); } diff --git a/package/pika_lvgl/pika_lvgl_lv_event.c b/package/pika_lvgl/pika_lvgl_lv_event.c index 24c95ed2d..b2acaa339 100644 --- a/package/pika_lvgl/pika_lvgl_lv_event.c +++ b/package/pika_lvgl/pika_lvgl_lv_event.c @@ -6,3 +6,11 @@ int pika_lvgl_lv_event_get_code(PikaObj *self){ return lv_event_get_code(lv_event); } +PikaObj *New_pika_lvgl_lv_obj(Args *args); +PikaObj* pika_lvgl_lv_event_get_target(PikaObj *self){ + lv_event_t *lv_event = obj_getPtr(self, "lv_event"); + lv_obj_t* lv_obj = lv_event_get_target(lv_event); + PikaObj* new_obj = newNormalObj(New_pika_lvgl_lv_obj); + obj_setPtr(new_obj, "lv_obj", lv_obj); + return new_obj; +} diff --git a/package/pika_lvgl/pika_lvgl_lv_obj.c b/package/pika_lvgl/pika_lvgl_lv_obj.c index f49203475..62925e485 100644 --- a/package/pika_lvgl/pika_lvgl_lv_obj.c +++ b/package/pika_lvgl/pika_lvgl_lv_obj.c @@ -92,8 +92,23 @@ void pika_lvgl_lv_obj_add_event_cb(PikaObj* self, eventLicener_registEvent(pika_lv_event_listener_g, (uintptr_t)lv_obj, self); } -void pika_lvgl_lv_obj_add_style(PikaObj* self, int selector, PikaObj* style) { +void pika_lvgl_lv_obj_add_style(PikaObj *self, PikaObj* style, int selector){ lv_obj_t* lv_obj = obj_getPtr(self, "lv_obj"); lv_state_t* lv_style = obj_getPtr(style, "lv_style"); lv_obj_add_style(lv_obj, lv_style, selector); } + +int pika_lvgl_lv_obj_get_x(PikaObj *self){ + lv_obj_t* lv_obj = obj_getPtr(self, "lv_obj"); + return lv_obj_get_x(lv_obj); +} + +int pika_lvgl_lv_obj_get_y(PikaObj *self){ + lv_obj_t* lv_obj = obj_getPtr(self, "lv_obj"); + return lv_obj_get_y(lv_obj); +} + +void pika_lvgl_lv_obj_set_pos(PikaObj *self, int x, int y){ + lv_obj_t* lv_obj = obj_getPtr(self, "lv_obj"); + lv_obj_set_pos(lv_obj, x, y); +} diff --git a/package/pika_lvgl/pika_lvgl_lv_style_t.c b/package/pika_lvgl/pika_lvgl_lv_style_t.c index c0bf5f57d..ba0887896 100644 --- a/package/pika_lvgl/pika_lvgl_lv_style_t.c +++ b/package/pika_lvgl/pika_lvgl_lv_style_t.c @@ -44,3 +44,19 @@ void pika_lvgl_style_t___init__(PikaObj* self) { lv_style_t* lv_style = args_getStruct(self->list, "lv_style_struct"); obj_setPtr(self, "lv_style", lv_style); } + +void pika_lvgl_style_t_set_shadow_color(PikaObj *self, PikaObj* color){ + lv_style_t* lv_style = obj_getPtr(self, "lv_style"); + lv_color_t* lv_color = obj_getPtr(color, "lv_color"); + lv_style_set_shadow_color(lv_style, *lv_color); +} + +void pika_lvgl_style_t_set_shadow_spread(PikaObj *self, int s){ + lv_style_t* lv_style = obj_getPtr(self, "lv_style"); + lv_style_set_shadow_spread(lv_style, s); +} + +void pika_lvgl_style_t_set_shadow_width(PikaObj *self, int w){ + lv_style_t* lv_style = obj_getPtr(self, "lv_style"); + lv_style_set_shadow_width(lv_style, w); +} diff --git a/package/pika_lvgl/pika_lvgl_roller.c b/package/pika_lvgl/pika_lvgl_roller.c index 770709df1..f041bc35e 100644 --- a/package/pika_lvgl/pika_lvgl_roller.c +++ b/package/pika_lvgl/pika_lvgl_roller.c @@ -7,7 +7,7 @@ void pika_lvgl_roller___init__(PikaObj* self, PikaObj* parent) { obj_setPtr(self, "lv_obj", lv_obj); } -void pika_lvgl_roller_set_options(PikaObj* self, int mode, char* options) { +void pika_lvgl_roller_set_options(PikaObj *self, char* options, int mode){ lv_obj_t* lv_obj = obj_getPtr(self, "lv_obj"); lv_roller_set_options(lv_obj, options, mode); } diff --git a/package/pika_lvgl/pika_lvgl_table.c b/package/pika_lvgl/pika_lvgl_table.c index 9ee4072be..5d4a78048 100644 --- a/package/pika_lvgl/pika_lvgl_table.c +++ b/package/pika_lvgl/pika_lvgl_table.c @@ -8,8 +8,8 @@ void pika_lvgl_table___init__(PikaObj* self, PikaObj* parent) { } void pika_lvgl_table_set_cell_value(PikaObj* self, - int col, int row, + int col, char* txt) { lv_obj_t* lv_obj = obj_getPtr(self, "lv_obj"); lv_table_set_cell_value(lv_obj, row, col, txt);