LV_EVENT_GESTURE
lv_indev_get_gesture_dir
lv_dir_t lv_indev_get_gesture_dir(const lv_indev_t * indev)
{
return indev->proc.types.pointer.gesture_dir;
}
方向
enum {
LV_DIR_NONE = 0x00,
LV_DIR_LEFT = (1 << 0),
LV_DIR_RIGHT = (1 << 1),
LV_DIR_TOP = (1 << 2),
LV_DIR_BOTTOM = (1 << 3),
LV_DIR_HOR = LV_DIR_LEFT | LV_DIR_RIGHT,
LV_DIR_VER = LV_DIR_TOP | LV_DIR_BOTTOM,
LV_DIR_ALL = LV_DIR_HOR | LV_DIR_VER,
};
typedef uint8_t lv_dir_t;
使用lv_indev_get_gesture_dir(lv_indev_get_act());
可以得到当前屏幕的姿势。
给当前屏幕
绑定事件回调函数。
事件为 LV_EVENT_GESTURE
。
绑定回调函数后可以当事件 LV_EVENT_GESTURE
发生时自动由回调函数进行处理,而不用主动查询。
lv_obj_add_event_cb(lv_scr_act(), scr_event_cb, LV_EVENT_GESTURE, NULL);
LV_EVENT_GESTURE
好像只会由屏幕发出
lv_indev_wait_release(lv_indev_get_act());
使用 lv_indev_wait_release
可解决手势滑过button引起 LV_EVENT_CLICKED
(或者其他的BUG?)
int Screen_Flag=0;
void scr_event_cb(lv_event_t * event)
{
lv_indev_wait_release(lv_indev_get_act());
lv_dir_t dir = lv_indev_get_gesture_dir(lv_indev_get_act());
if (dir == LV_DIR_LEFT) {
Screen_Flag = LV_DIR_LEFT;
}
else if(dir == LV_DIR_RIGHT)
{
Screen_Flag = LV_DIR_RIGHT;
}
else if (dir == LV_DIR_TOP)
{
Screen_Flag = LV_DIR_TOP;
}
else if (dir == LV_DIR_BOTTOM)
{
Screen_Flag = LV_DIR_BOTTOM;
}
//LV_LOG("dir:%d\n", dir);
on_other_event(event);
}
lv_obj_add_event_cb(lv_scr_act(), scr_event_cb, LV_EVENT_GESTURE, &Screen_Flag);