How to get into LV_EVENT_DRAG_BEGIN and LV_EVENT_DRAG_END event?


What MCU/Processor/Board and compiler are you using?


What LVGL version are you using?


What do you want to achieve?

To let me get into LV_EVENT_DRAG_BEGIN and LV_EVENT_DRAG_END event

What have you tried so far?

I’ve tried ‘lv_obj_set_drag()’ and ‘lv_obj_set_drag_dir()’,worked,but I only want to redirect to another page when I swipe screen from left to right.
‘lv_obj_set_drag()’ doesn’t reach my expectation.Just like ‘lv_obj_set_drag_dir(obj, LV_DRAG_DIR_HOR)’, but only from left to right.

Code to reproduce

Add a code snippet which can run in the simulator. It should contain only the relevant code that compiles without errors when separated from your main code base.

The code block(s) should be formatted like:

/*You code here*/
#include "test.h"
#include "../../lv_examples.h"

static lv_obj_t* screen;

void event_handler(lv_obj_t* obj, lv_event_t event);

void test_start(void)
	screen = lv_scr_act();
	lv_obj_t* container = lv_cont_create(screen, NULL);
	lv_obj_set_size(container, 256, 402);
	lv_obj_align(container, screen, LV_ALIGN_CENTER, 0, 0);
	lv_obj_set_event_cb(container, event_handler);

void event_handler(lv_obj_t* obj, lv_event_t event)
	//printf("event:%d\n", event);
	if (event == LV_EVENT_DRAG_BEGIN)
		lv_indev_t* indev = lv_indev_get_act();
		if (indev != NULL)
			if (indev->proc.types.pointer.drag_dir == LV_DRAG_DIR_HOR)
				if (indev->proc.types.pointer.vect.x > 0)
					printf("left to right\n");
				else if (indev->proc.types.pointer.vect.x < 0)
					printf("right to left\n");

Screenshot and/or video

If possible, add screenshots and/or videos about the current state.