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