From 734ce2633784be8a8c414431a50c0aef856bf37c Mon Sep 17 00:00:00 2001 From: ShallowGreen123 <67771110+ShallowGreen123@users.noreply.github.com> Date: Mon, 18 Sep 2023 12:15:24 +0800 Subject: [PATCH] Add files via upload Add missing file --- .../lvgl/examples/widgets/obj/index.rst | 13 +++++++ .../examples/widgets/obj/lv_example_obj_1.c | 22 ++++++++++++ .../examples/widgets/obj/lv_example_obj_1.py | 14 ++++++++ .../examples/widgets/obj/lv_example_obj_2.c | 35 +++++++++++++++++++ .../examples/widgets/obj/lv_example_obj_2.py | 25 +++++++++++++ 5 files changed, 109 insertions(+) create mode 100644 LVGL.Simulator/lvgl/examples/widgets/obj/index.rst create mode 100644 LVGL.Simulator/lvgl/examples/widgets/obj/lv_example_obj_1.c create mode 100644 LVGL.Simulator/lvgl/examples/widgets/obj/lv_example_obj_1.py create mode 100644 LVGL.Simulator/lvgl/examples/widgets/obj/lv_example_obj_2.c create mode 100644 LVGL.Simulator/lvgl/examples/widgets/obj/lv_example_obj_2.py diff --git a/LVGL.Simulator/lvgl/examples/widgets/obj/index.rst b/LVGL.Simulator/lvgl/examples/widgets/obj/index.rst new file mode 100644 index 0000000..5d1c2d4 --- /dev/null +++ b/LVGL.Simulator/lvgl/examples/widgets/obj/index.rst @@ -0,0 +1,13 @@ + +Base objects with custom styles +"""""""""""""""""""""""""""""""" + +.. lv_example:: widgets/obj/lv_example_obj_1 + :language: c + +Make an object draggable +"""""""""""""""""""""""""""" + +.. lv_example:: widgets/obj/lv_example_obj_2 + :language: c + diff --git a/LVGL.Simulator/lvgl/examples/widgets/obj/lv_example_obj_1.c b/LVGL.Simulator/lvgl/examples/widgets/obj/lv_example_obj_1.c new file mode 100644 index 0000000..2f55429 --- /dev/null +++ b/LVGL.Simulator/lvgl/examples/widgets/obj/lv_example_obj_1.c @@ -0,0 +1,22 @@ +#include "../../lv_examples.h" +#if LV_BUILD_EXAMPLES + +void lv_example_obj_1(void) +{ + lv_obj_t * obj1; + obj1 = lv_obj_create(lv_scr_act()); + lv_obj_set_size(obj1, 100, 50); + lv_obj_align(obj1, LV_ALIGN_CENTER, -60, -30); + + static lv_style_t style_shadow; + lv_style_init(&style_shadow); + lv_style_set_shadow_width(&style_shadow, 10); + lv_style_set_shadow_spread(&style_shadow, 5); + lv_style_set_shadow_color(&style_shadow, lv_palette_main(LV_PALETTE_BLUE)); + + lv_obj_t * obj2; + obj2 = lv_obj_create(lv_scr_act()); + lv_obj_add_style(obj2, &style_shadow, 0); + lv_obj_align(obj2, LV_ALIGN_CENTER, 60, 30); +} +#endif diff --git a/LVGL.Simulator/lvgl/examples/widgets/obj/lv_example_obj_1.py b/LVGL.Simulator/lvgl/examples/widgets/obj/lv_example_obj_1.py new file mode 100644 index 0000000..c6afad3 --- /dev/null +++ b/LVGL.Simulator/lvgl/examples/widgets/obj/lv_example_obj_1.py @@ -0,0 +1,14 @@ +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) + diff --git a/LVGL.Simulator/lvgl/examples/widgets/obj/lv_example_obj_2.c b/LVGL.Simulator/lvgl/examples/widgets/obj/lv_example_obj_2.c new file mode 100644 index 0000000..1d956a9 --- /dev/null +++ b/LVGL.Simulator/lvgl/examples/widgets/obj/lv_example_obj_2.c @@ -0,0 +1,35 @@ +#include "../../lv_examples.h" +#if LV_BUILD_EXAMPLES + +static void drag_event_handler(lv_event_t * e) +{ + lv_obj_t * obj = lv_event_get_target(e); + + lv_indev_t * indev = lv_indev_get_act(); + if(indev == NULL) return; + + lv_point_t vect; + lv_indev_get_vect(indev, &vect); + + lv_coord_t x = lv_obj_get_x(obj) + vect.x; + lv_coord_t y = lv_obj_get_y(obj) + vect.y; + lv_obj_set_pos(obj, x, y); +} + + +/** + * Make an object dragable. + */ +void lv_example_obj_2(void) +{ + lv_obj_t * obj; + obj = lv_obj_create(lv_scr_act()); + lv_obj_set_size(obj, 150, 100); + lv_obj_add_event_cb(obj, drag_event_handler, LV_EVENT_PRESSING, NULL); + + lv_obj_t * label = lv_label_create(obj); + lv_label_set_text(label, "Drag me"); + lv_obj_center(label); + +} +#endif diff --git a/LVGL.Simulator/lvgl/examples/widgets/obj/lv_example_obj_2.py b/LVGL.Simulator/lvgl/examples/widgets/obj/lv_example_obj_2.py new file mode 100644 index 0000000..0771f83 --- /dev/null +++ b/LVGL.Simulator/lvgl/examples/widgets/obj/lv_example_obj_2.py @@ -0,0 +1,25 @@ +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) + + +# +# 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() +