acid-drop- Hacking the planet from a LilyGo T-Deck using custom firmware |
git clone git://git.acid.vegas/acid-drop.git |
Log | Files | Refs | Archive | README | LICENSE |
lv_example_gridnav_3.c (3619B)
1 #include "../../lv_examples.h" 2 #if LV_USE_GRIDNAV && LV_USE_FLEX && LV_BUILD_EXAMPLES 3 4 static void cont_sub_event_cb(lv_event_t * e) 5 { 6 uint32_t k = lv_event_get_key(e); 7 lv_obj_t * obj = lv_event_get_current_target(e); 8 if(k == LV_KEY_ENTER) { 9 lv_group_focus_obj(obj); 10 } 11 else if(k == LV_KEY_ESC) { 12 lv_group_focus_next(lv_obj_get_group(obj)); 13 } 14 15 } 16 17 /** 18 * Nested grid navigations 19 */ 20 void lv_example_gridnav_3(void) 21 { 22 /*It's assumed that the default group is set and 23 *there is a keyboard indev*/ 24 25 lv_obj_t * cont_main = lv_obj_create(lv_scr_act()); 26 lv_gridnav_add(cont_main, LV_GRIDNAV_CTRL_ROLLOVER | LV_GRIDNAV_CTRL_SCROLL_FIRST); 27 28 /*Only the container needs to be in a group*/ 29 lv_group_add_obj(lv_group_get_default(), cont_main); 30 31 /*Use flex here, but works with grid or manually placed objects as well*/ 32 lv_obj_set_flex_flow(cont_main, LV_FLEX_FLOW_ROW_WRAP); 33 lv_obj_set_style_bg_color(cont_main, lv_palette_lighten(LV_PALETTE_BLUE, 5), LV_STATE_FOCUSED); 34 lv_obj_set_size(cont_main, lv_pct(80), LV_SIZE_CONTENT); 35 36 lv_obj_t * btn; 37 lv_obj_t * label; 38 39 btn = lv_btn_create(cont_main); 40 lv_group_remove_obj(btn); 41 label = lv_label_create(btn); 42 lv_label_set_text(label, "Button 1"); 43 44 btn = lv_btn_create(cont_main); 45 lv_group_remove_obj(btn); 46 label = lv_label_create(btn); 47 lv_label_set_text(label, "Button 2"); 48 49 50 /*Create an other container with long text to show how LV_GRIDNAV_CTRL_SCROLL_FIRST works*/ 51 lv_obj_t * cont_sub1 = lv_obj_create(cont_main); 52 lv_obj_set_size(cont_sub1, lv_pct(100), 100); 53 54 label = lv_label_create(cont_sub1); 55 lv_obj_set_style_bg_color(cont_sub1, lv_palette_lighten(LV_PALETTE_RED, 5), LV_STATE_FOCUSED); 56 lv_obj_set_width(label, lv_pct(100)); 57 lv_label_set_text(label, 58 "I'm a very long text which is makes my container scrollable. " 59 "As LV_GRIDNAV_FLAG_SCROLL_FIRST is enabled arrow will scroll me first " 60 "and a new objects will be focused only when an edge is reached with the scrolling.\n\n" 61 "This is only some placeholder text to be sure the parent will be scrollable. \n\n" 62 "Hello world!\n" 63 "Hello world!\n" 64 "Hello world!\n" 65 "Hello world!\n" 66 "Hello world!\n" 67 "Hello world!"); 68 69 /*Create a third container that can be focused with ENTER and contains an other grid nav*/ 70 lv_obj_t * cont_sub2 = lv_obj_create(cont_main); 71 lv_gridnav_add(cont_sub2, LV_GRIDNAV_CTRL_ROLLOVER); 72 /*Only the container needs to be in a group*/ 73 lv_group_add_obj(lv_group_get_default(), cont_sub2); 74 75 lv_obj_add_event_cb(cont_sub2, cont_sub_event_cb, LV_EVENT_KEY, NULL); 76 77 /*Use flex here, but works with grid or manually placed objects as well*/ 78 lv_obj_set_flex_flow(cont_sub2, LV_FLEX_FLOW_ROW_WRAP); 79 lv_obj_set_style_bg_color(cont_sub2, lv_palette_lighten(LV_PALETTE_RED, 5), LV_STATE_FOCUSED); 80 lv_obj_set_size(cont_sub2, lv_pct(100), LV_SIZE_CONTENT); 81 82 label = lv_label_create(cont_sub2); 83 lv_label_set_text(label, "Use ENTER/ESC to focus/defocus this container"); 84 lv_obj_set_width(label, lv_pct(100)); 85 86 btn = lv_btn_create(cont_sub2); 87 lv_group_remove_obj(btn); 88 label = lv_label_create(btn); 89 lv_label_set_text(label, "Button 3"); 90 91 btn = lv_btn_create(cont_sub2); 92 lv_group_remove_obj(btn); 93 label = lv_label_create(btn); 94 lv_label_set_text(label, "Button 4"); 95 96 97 98 99 } 100 101 #endif