From 2719862fc3065b5d72c74c3f5f0923c3f6cc82c6 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Mon, 3 Jan 2022 13:39:14 +0100 Subject: [PATCH] docs(indev): add description about gestures --- docs/overview/indev.md | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/docs/overview/indev.md b/docs/overview/indev.md index 0a4f377d6..25585bc19 100644 --- a/docs/overview/indev.md +++ b/docs/overview/indev.md @@ -16,22 +16,54 @@ An input device usually means: ## Pointers +### Cursor + Pointer input devices (like a mouse) can have a cursor. ```c ... lv_indev_t * mouse_indev = lv_indev_drv_register(&indev_drv); -LV_IMG_DECLARE(mouse_cursor_icon); /*Declare the image file.*/ +LV_IMG_DECLARE(mouse_cursor_icon); /*Declare the image source.*/ lv_obj_t * cursor_obj = lv_img_create(lv_scr_act()); /*Create an image object for the cursor */ lv_img_set_src(cursor_obj, &mouse_cursor_icon); /*Set the image source*/ lv_indev_set_cursor(mouse_indev, cursor_obj); /*Connect the image object to the driver*/ - ``` Note that the cursor object should have `lv_obj_clear_flag(cursor_obj, LV_OBJ_FLAG_CLICKABLE)`. For images, *clicking* is disabled by default. +### Gestures +Pointer input devives can detect basic gestures. By default, most of the widgets send the gestures to its parent, so finally the gestures can be detected on the screen object in a form of an `LV_EVENT_GESTURE` event. For example: + +```c +void my_event(lv_event_t * e) +{ + lv_obj_t * screen = lv_event_get_current_target(e); + lv_dir_t dir = lv_indev_get_gesture_dir(lv_indev_act()); + switch(dir) { + case LV_DIR_LEFT: + ... + break; + case LV_DIR_RIGHT: + ... + break; + case LV_DIR_TOP: + ... + break; + case LV_DIR_BOTTOM: + ... + break; + } +} + +... + +lv_obj_add_event_cb(screen1, my_event, LV_EVENT_GESTURE, NULL); +``` + +To prevent passing the gesture event to the parent from an obejct use `lv_obj_clear_flag(obj, LV_OBJ_FLAG_GESTURE_BUBBLE)`. + ## Keypad and encoder You can fully control the user interface without a touchpad or mouse by using a keypad or encoder(s). It works similar to the *TAB* key on the PC to select an element in an application or a web page.