1 #include "../../lv_examples.h"
2 #if LV_USE_GRIDNAV && LV_USE_FLEX && LV_BUILD_EXAMPLES
3
4
event_handler(lv_event_t * e)5 static void event_handler(lv_event_t * e)
6 {
7 lv_obj_t * obj = lv_event_get_target(e);
8 lv_obj_t * list = lv_obj_get_parent(obj);
9 LV_LOG_USER("Clicked: %s", lv_list_get_btn_text(list, obj));
10 }
11
12 /**
13 * Simple navigation on a list widget
14 */
lv_example_gridnav_4(void)15 void lv_example_gridnav_4(void)
16 {
17 /*It's assumed that the default group is set and
18 *there is a keyboard indev*/
19
20 lv_obj_t * list = lv_list_create(lv_scr_act());
21 lv_gridnav_add(list, LV_GRIDNAV_CTRL_ROLLOVER);
22 lv_obj_align(list, LV_ALIGN_LEFT_MID, 0, 10);
23 lv_group_add_obj(lv_group_get_default(), list);
24
25 uint32_t i;
26 for(i = 0; i < 20; i++) {
27 char buf[32];
28
29 /*Add some separators too, they are not focusable by gridnav*/
30 if((i % 5) == 0) {
31 lv_snprintf(buf, sizeof(buf), "Section %d", i / 5 + 1);
32 lv_list_add_text(list, buf);
33 }
34
35 lv_snprintf(buf, sizeof(buf), "File %d", i + 1);
36 lv_obj_t * item = lv_list_add_btn(list, LV_SYMBOL_FILE, buf);
37 lv_obj_add_event_cb(item, event_handler, LV_EVENT_CLICKED, NULL);
38 lv_group_remove_obj(item); /*The default group adds it automatically*/
39 }
40
41 lv_obj_t * btn = lv_btn_create(lv_scr_act());
42 lv_obj_align(btn, LV_ALIGN_RIGHT_MID, 0, -10);
43 lv_obj_t * label = lv_label_create(btn);
44 lv_label_set_text(label, "Button");
45 }
46
47 #endif
48