[English]

Grid navigation(网格导航)

显示原文

Grid navigation (gridnav for short) is a feature that changes the currently focused child object as arrow keys are pressed.

If the children are arranged into a grid-like layout then the up, down, left and right arrows move focus to the nearest sibling in the respective direction.

It doesn't matter how the children are positioned, as only the current x and y coordinates are considered. This means that gridnav works with manually positioned children, as well as Flex(弹性布局) and Grid(网格布局) layouts.

Gridnav also works if the children are arranged into a single row or column. That makes it useful, for example, to simplify navigation on a List widget.

Gridnav assumes that the object to which gridnav is added is part of a group. This way, if the object with gridnav is focused, the arrow key presses are automatically forwarded to the object so that gridnav can process the arrow keys.

To move the focus to the next widget of the group use LV_KEY_NEXT or LV_KEY_PREV. Optionally you can also use lv_group_focus_next() or lv_group_focus_prev() or the TAB key on keyboard as usual.

If the container is scrollable and the focused child is out of the view, gridnav will automatically scroll the child into view.


网格导航(简称gridnav)是一个功能,它会随着箭头键的按下而改变当前焦点对象。

如果子对象被排列成类似网格的布局,那么上、下、左、右箭头将会把焦点移动到相应方向上最近的兄弟节点。

孩子们的位置并不重要,因为只有当前的x和y坐标被考虑在内。这意味着gridnav适用于手动定位的子对象,以及 Flex(弹性布局)Grid(网格布局) 布局。

如果孩子们被排列成单行或单列,gridnav也能正常工作。例如,在 List widget 上简化导航就很有用。

Gridnav假设添加了gridnav的对象是 group 的一部分。这样,如果带有gridnav的对象被聚焦,箭头键的按下就会自动转发到对象上,以便gridnav能够处理这些箭头键。

使用 LV_KEY_NEXTLV_KEY_PREV 可以将焦点移到组的下一个部件。此外,你也可以像往常一样使用 lv_group_focus_next()lv_group_focus_prev() 或键盘上的 TAB 键。

如果容器可以滚动,且焦点子对象在视野之外,gridnav将自动滚动子对象到视野中。

Usage(用法)

显示原文

To add the gridnav feature to an object use lv_gridnav_add(cont, flags).

flags control the behavior of gridnav:

  • LV_GRIDNAV_CTRL_NONE: Default settings

  • LV_GRIDNAV_CTRL_ROLLOVER: If there is no next/previous object in a direction, the focus goes to the object in the next/previous row (on left/right keys) or first/last row (on up/down keys)

  • LV_GRIDNAV_CTRL_SCROLL_FIRST: If an arrow is pressed and the focused object can be scrolled in that direction then 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

  • LV_GRIDNAV_CTRL_HORIZONTAL_MOVE_ONLY: Only use the left/right keys for grid navigation. Up/down key events will be sent to the focused object.

  • LV_GRIDNAV_CTRL_VERTICAL_MOVE_ONLY: Only use the up/down keys for grid navigation. Left/right key events will be sent to the focused object.

LV_GRIDNAV_CTRL_HORIZONTAL_MOVE_ONLY and LV_GRIDNAV_CTRL_VERTICAL_MOVE_ONLY should not be used together. lv_gridnav_remove(cont) Removes gridnav from an object.


要给对象添加gridnav功能,请使用 lv_gridnav_add(cont, flags)

flags 控制gridnav的行为:

  • LV_GRIDNAV_CTRL_NONE:默认设置

  • LV_GRIDNAV_CTRL_ROLLOVER:如果在某个方向上没有下一个/上一个对象,焦点将转移到下一行/上一行的对象(在左/右键上)或第一行/最后一行的对象(在上/下键上)

  • LV_GRIDNAV_CTRL_SCROLL_FIRST:如果按下箭头并且焦点对象可以在该方向上滚动,则它将滚动而不是转到下一个/上一个对象。如果没有更多的滚动空间,则正常情况下将对下一个/上一个对象进行聚焦

  • LV_GRIDNAV_CTRL_HORIZONTAL_MOVE_ONLY:仅使用左/右键,用于网格导航。 向上/向下键事件将被发送到焦点对象。

  • LV_GRIDNAV_CTRL_VERTICAL_MOVE_ONLY:仅使用向上/向下键,用于网格导航。 左/右键事件将被发送到焦点对象。

LV_GRIDNAV_CTRL_HORIZONTAL_MOVE_ONLYLV_GRIDNAV_CTRL_VERTICAL_MOVE_ONLY`不应该一起使用。 :cpp:expr:`lv_gridnav_remove(cont) 从对象中移除gridnav。

Focusable objects(可以聚焦的对象)

显示原文

An object needs to be clickable or click focusable (LV_OBJ_FLAG_CLICKABLE or LV_OBJ_FLAG_CLICK_FOCUSABLE) and not hidden (LV_OBJ_FLAG_HIDDEN) to be focusable by gridnav.


一个对象需要是可点击的或者有点击焦点 (LV_OBJ_FLAG_CLICKABLE) 和未隐藏 (LV_OBJ_FLAG_HIDDEN) 才能被gridnav聚焦。

Example

API

lv_gridnav.h