1 #include "../../lv_examples.h"
2 #if LV_USE_GRIDNAV && LV_USE_FLEX && LV_BUILD_EXAMPLES
3 
4 /**
5  * Demonstrate a a basic grid navigation
6  */
lv_example_gridnav_1(void)7 void lv_example_gridnav_1(void)
8 {
9     /*It's assumed that the default group is set and
10      *there is a keyboard indev*/
11 
12     lv_obj_t * cont1 = lv_obj_create(lv_scr_act());
13     lv_gridnav_add(cont1, LV_GRIDNAV_CTRL_NONE);
14 
15     /*Use flex here, but works with grid or manually placed objects as well*/
16     lv_obj_set_flex_flow(cont1, LV_FLEX_FLOW_ROW_WRAP);
17     lv_obj_set_style_bg_color(cont1, lv_palette_lighten(LV_PALETTE_BLUE, 5), LV_STATE_FOCUSED);
18     lv_obj_set_size(cont1, lv_pct(50), lv_pct(100));
19 
20     /*Only the container needs to be in a group*/
21     lv_group_add_obj(lv_group_get_default(), cont1);
22 
23     lv_obj_t * label = lv_label_create(cont1);
24     lv_label_set_text_fmt(label, "No rollover");
25 
26     uint32_t i;
27     for(i = 0; i < 10; i++) {
28         lv_obj_t * obj = lv_btn_create(cont1);
29         lv_obj_set_size(obj, 70, LV_SIZE_CONTENT);
30         lv_obj_add_flag(obj, LV_OBJ_FLAG_CHECKABLE);
31         lv_group_remove_obj(obj);   /*Not needed, we use the gridnav instead*/
32 
33         lv_obj_t * label = lv_label_create(obj);
34         lv_label_set_text_fmt(label, "%d", i);
35         lv_obj_center(label);
36     }
37 
38     /* Create a second container with rollover grid nav mode.*/
39 
40     lv_obj_t * cont2 = lv_obj_create(lv_scr_act());
41     lv_gridnav_add(cont2, LV_GRIDNAV_CTRL_ROLLOVER);
42     lv_obj_set_style_bg_color(cont2, lv_palette_lighten(LV_PALETTE_BLUE, 5), LV_STATE_FOCUSED);
43     lv_obj_set_size(cont2, lv_pct(50), lv_pct(100));
44     lv_obj_align(cont2, LV_ALIGN_RIGHT_MID, 0, 0);
45 
46     label = lv_label_create(cont2);
47     lv_obj_set_width(label, lv_pct(100));
48     lv_label_set_text_fmt(label, "Rollover\nUse tab to focus the other container");
49 
50     /*Only the container needs to be in a group*/
51     lv_group_add_obj(lv_group_get_default(), cont2);
52 
53     /*Add and place some children manually*/
54     lv_obj_t * ta = lv_textarea_create(cont2);
55     lv_obj_set_size(ta, lv_pct(100), 80);
56     lv_obj_set_pos(ta, 0, 80);
57     lv_group_remove_obj(ta);   /*Not needed, we use the gridnav instead*/
58 
59     lv_obj_t * cb = lv_checkbox_create(cont2);
60     lv_obj_set_pos(cb, 0, 170);
61     lv_group_remove_obj(cb);   /*Not needed, we use the gridnav instead*/
62 
63     lv_obj_t * sw1 = lv_switch_create(cont2);
64     lv_obj_set_pos(sw1, 0, 200);
65     lv_group_remove_obj(sw1);   /*Not needed, we use the gridnav instead*/
66 
67     lv_obj_t * sw2 = lv_switch_create(cont2);
68     lv_obj_set_pos(sw2, lv_pct(50), 200);
69     lv_group_remove_obj(sw2);   /*Not needed, we use the gridnav instead*/
70 }
71 
72 #endif
73