1# Grid navigation
2
3Grid navigation (gridnav for short) is a feature that changes the currently focused child object as arrow keys are pressed.
4
5If the children are arranged into a grid-like layout then the up, down, left and right arrows move focus to the nearest sibling
6in the respective direction.
7
8It doesn't matter how the children are positioned, as only the current x and y coordinates are considered.
9This means that gridnav works with manually positioned children, as well as [Flex](/layouts/flex) and [Grid](/layouts/grid) layouts.
10
11Gridnav also works if the children are arranged into a single row or column.
12That makes it useful, for example, to simplify navigation on a [List widget](/widgets/extra/list).
13
14Gridnav assumes that the object to which gridnav is added is part of a [group](/overview/indev.html#groups).
15This way, if the object with gridnav is focused, the arrow key presses are automatically forwarded to the object
16so that gridnav can process the arrow keys.
17
18To move the focus to the next widget of the group use `LV_KEY_NEXT/PREV` or `lv_group_focus_next/prev()` or the `TAB` key on keyboard as usual.
19
20If the container is scrollable and the focused child is out of the view, gridnav will automatically scroll the child into view.
21
22## Usage
23
24To add the gridnav feature to an object use `lv_gridnav_add(cont, flags)`.
25
26`flags` control the behavior of gridnav:
27- `LV_GRIDNAV_CTRL_NONE` Default settings
28- `LV_GRIDNAV_CTRL_ROLLOVER`  If there is no next/previous object in a direction,
29the focus goes to the object in the next/previous row (on left/right keys) or first/last row (on up/down keys
30- `LV_GRIDNAV_CTRL_SCROLL_FIRST` If an arrow is pressed and the focused object can be scrolled in that direction
31then it will be scrolled instead of going to the next/previous object.  If there is no more room for scrolling the next/previous object will be focused normally
32
33`lv_gridnav_remove(cont)` Removes gridnav from an object.
34
35## Focusable objects
36
37An object needs to be clickable or click focusable (`LV_OBJ_FLAG_CLICKABLE` or `LV_OBJ_FLAG_CLICK_FOCUSABLE`)
38and not hidden (`LV_OBJ_FLAG_HIDDEN`) to be focusable by gridnav.
39
40
41## Example
42
43```eval_rst
44
45.. include:: ../../examples/others/gridnav/index.rst
46
47```
48## API
49
50
51```eval_rst
52
53.. doxygenfile:: lv_gridnav.h
54  :project: lvgl
55
56```
57