init Files
This commit is contained in:
34
libraries/lvgl/examples/widgets/obj/lv_example_obj_2.c
Normal file
34
libraries/lvgl/examples/widgets/obj/lv_example_obj_2.c
Normal file
@@ -0,0 +1,34 @@
|
||||
#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_active();
|
||||
if(indev == NULL) return;
|
||||
|
||||
lv_point_t vect;
|
||||
lv_indev_get_vect(indev, &vect);
|
||||
|
||||
int32_t x = lv_obj_get_x_aligned(obj) + vect.x;
|
||||
int32_t y = lv_obj_get_y_aligned(obj) + vect.y;
|
||||
lv_obj_set_pos(obj, x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make an object draggable.
|
||||
*/
|
||||
void lv_example_obj_2(void)
|
||||
{
|
||||
lv_obj_t * obj;
|
||||
obj = lv_obj_create(lv_screen_active());
|
||||
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
|
||||
Reference in New Issue
Block a user