网格导航¶
网格导航(简称 gridnav)是一项功能,可在按下方向键时更改当前聚焦的子对象。
如果子对象排列成类似网格的布局,则上下左右箭头会将焦点移动到相应方向上最近的兄弟对象。
子对象的具体位置无关紧要,因为只考虑当前的 x 和 y 坐标。 这意味着 gridnav 可以与手动定位的子对象一起使用,也可以与 Flex 和 Grid 布局一起使用。
即使子对象排列成单行或单列,gridnav 也能正常工作。 例如,这使其在简化 列表小部件 的导航时非常有用。
gridnav 假定添加了 gridnav 的对象是 组 的一部分。 这样,如果带有 gridnav 的对象被聚焦,方向键的按键会自动转发到该对象,以便 gridnav 可以处理方向键。
要将焦点移动到组的下一个小部件,请像往常一样使用 LV_KEY_NEXT/PREV 或 lv_group_focus_next/prev() 或键盘上的 TAB 键。
如果容器是可滚动的,并且聚焦的子对象超出了视图范围,gridnav 会自动滚动子对象以使其进入视图范围。
使用方法¶
要将 gridnav 功能添加到对象,请使用 lv_gridnav_add(cont, flags)。
flags 控制 gridnav 的行为:
LV_GRIDNAV_CTRL_NONE默认设置LV_GRIDNAV_CTRL_ROLLOVER如果某个方向上没有下一个/上一个对象, 焦点会移动到下一行/上一行的对象(按左/右键)或第一行/最后一行的对象(按上/下键)LV_GRIDNAV_CTRL_SCROLL_FIRST如果按下箭头键并且聚焦的对象可以在该方向上滚动, 则它会滚动而不是移动到下一个/上一个对象。如果没有更多的滚动空间,下一个/上一个对象将正常聚焦
lv_gridnav_remove(cont) 从对象中移除 gridnav。
可聚焦对象¶
对象需要是可点击的或可点击聚焦的(LV_OBJ_FLAG_CLICKABLE 或 LV_OBJ_FLAG_CLICK_FOCUSABLE)
并且不能隐藏(LV_OBJ_FLAG_HIDDEN),才能被 gridnav 聚焦。
示例¶
API¶
Typedefs
-
typedef int
_keep_pedantic_happy¶
Enums
Values:
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)
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
Functions
Add grid navigation feature to an object. It expects the children to be arranged into a grid-like layout. Although it's not required to have pixel perfect alignment. This feature makes possible to use keys to navigate among the children and focus them. The keys other than arrows and press/release related events are forwarded to the focused child.
- Parameters
obj -- pointer to an object on which navigation should be applied.
ctrl -- control flags from
lv_gridnav_ctrl_t.
Remove the grid navigation support from an object
- Parameters
obj -- pointer to an object
Manually focus an object on gridnav container
- Parameters
cont -- pointer to a gridnav container
to_focus -- pointer to an object to focus
anim_en -- LV_ANIM_ON/OFF