1.. _gridnav: 2 3=============== 4Grid navigation 5=============== 6 7Grid navigation (gridnav for short) is a feature that moves focus among a set 8of child Widgets via arrow-key presses. 9 10If the child Widgets are arranged into a grid-like layout then the up, down, 11left and right arrows move focus to the nearest sibling in the 12respective direction. 13 14It doesn't matter how the children are positioned, as only the current x 15and y coordinates are considered. This means that gridnav works with 16manually positioned children, as well as :ref:`flex` and 17:ref:`grid` layouts. 18 19Gridnav also works if the children are arranged into a single row or 20column. This is useful, for example, to simplify navigation among items in a 21:ref:`List Widget <lv_list>`. 22 23Gridnav assumes that the Widget to which gridnav is added is part of a 24:ref:`group <indev_groups>`. This way, if the Widget with 25gridnav has focus, the arrow key presses are automatically forwarded to 26the Widget so that gridnav can process the arrow keys. 27 28To move the focus to the next widget of the group use 29:cpp:enumerator:`LV_KEY_NEXT` or :cpp:enumerator:`LV_KEY_PREV`. 30Optionally you can also use :cpp:func:`lv_group_focus_next` 31or :cpp:func:`lv_group_focus_prev` or the ``TAB`` 32key on keyboard as usual. 33 34If the container is scrollable and the focused child is out of the view, 35gridnav will automatically scroll the child into view. 36 37 38 39.. _gridnav_usage: 40 41Usage 42***** 43 44To add gridnav behavior to any Widget (e.g. one serving as a container for 45child Widgets that the end user will navigate among using arrow keys) use 46:cpp:expr:`lv_gridnav_add(container, flags)`. 47 48The ``flags`` argument controls the navigation behavior: 49 50- :cpp:enumerator:`LV_GRIDNAV_CTRL_NONE`: Default settings 51- :cpp:enumerator:`LV_GRIDNAV_CTRL_ROLLOVER`: If there is no next/previous Widget in a 52 direction, the focus goes to the Widget in the next/previous row (on 53 left/right keys) or first/last row (on up/down keys) 54- :cpp:enumerator:`LV_GRIDNAV_CTRL_SCROLL_FIRST`: If an arrow is pressed and the focused 55 Widget can be scrolled in that direction then it will be scrolled instead of 56 going to the next/previous Widget. If there is no more room for scrolling the 57 next/previous Widget will receive focus normally. 58- :cpp:enumerator:`LV_GRIDNAV_CTRL_HORIZONTAL_MOVE_ONLY`: Only use the left/right keys 59 for grid navigation. Up/down key events will be sent to the Widget that has focus. 60- :cpp:enumerator:`LV_GRIDNAV_CTRL_VERTICAL_MOVE_ONLY`: Only use the up/down keys 61 for grid navigation. Left/right key events will be sent to the Widget that has focus. 62 63While the above behaviors can be combined by bit-wise OR-ing the above values together, 64:cpp:enumerator:`LV_GRIDNAV_CTRL_HORIZONTAL_MOVE_ONLY` and :cpp:enumerator:`LV_GRIDNAV_CTRL_VERTICAL_MOVE_ONLY` 65should not be used together. 66 67:cpp:expr:`lv_gridnav_remove(container)` Removes gridnav behavior from a Widget. 68 69 70 71Focusable Widgets 72***************** 73 74A Widget needs to be clickable or click focusable 75(:cpp:enumerator:`LV_OBJ_FLAG_CLICKABLE` or :cpp:enumerator:`LV_OBJ_FLAG_CLICK_FOCUSABLE`) and not 76hidden (:cpp:enumerator:`LV_OBJ_FLAG_HIDDEN`) to receive focus via gridnav. 77 78 79 80.. _gridnav_example: 81 82Examples 83******** 84 85.. include:: ../../examples/others/gridnav/index.rst 86 87 88 89.. _gridnav_api: 90 91API 92*** 93 94