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_fragment_2.c (4332B)
1 /** 2 * @file lv_example_fragment_2.c 3 * @brief Navigation stack using obj fragment 4 */ 5 #include "../../lv_examples.h" 6 7 #if LV_USE_FRAGMENT && LV_USE_WIN && LV_BUILD_EXAMPLES 8 9 static void sample_fragment_ctor(lv_fragment_t * self, void * args); 10 11 static lv_obj_t * sample_fragment_create_obj(lv_fragment_t * self, lv_obj_t * parent); 12 13 static void sample_push_click(lv_event_t * e); 14 15 static void sample_pop_click(lv_event_t * e); 16 17 static void sample_fragment_inc_click(lv_event_t * e); 18 19 typedef struct sample_fragment_t { 20 lv_fragment_t base; 21 lv_obj_t * label; 22 int depth; 23 int counter; 24 } sample_fragment_t; 25 26 static const lv_fragment_class_t sample_cls = { 27 .constructor_cb = sample_fragment_ctor, 28 .create_obj_cb = sample_fragment_create_obj, 29 .instance_size = sizeof(sample_fragment_t) 30 }; 31 32 static lv_obj_t * container = NULL; 33 34 void lv_example_fragment_2(void) 35 { 36 lv_obj_t * root = lv_obj_create(lv_scr_act()); 37 lv_obj_set_size(root, LV_PCT(100), LV_PCT(100)); 38 lv_obj_set_layout(root, LV_LAYOUT_GRID); 39 static const lv_coord_t col_dsc[] = {LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_TEMPLATE_LAST}; 40 static const lv_coord_t row_dsc[] = {LV_GRID_FR(1), LV_GRID_CONTENT, LV_GRID_TEMPLATE_LAST}; 41 lv_obj_set_grid_dsc_array(root, col_dsc, row_dsc); 42 container = lv_obj_create(root); 43 lv_obj_remove_style_all(container); 44 lv_obj_set_grid_cell(container, LV_GRID_ALIGN_STRETCH, 0, 2, LV_GRID_ALIGN_STRETCH, 0, 1); 45 46 lv_obj_t * push_btn = lv_btn_create(root); 47 lv_obj_t * push_label = lv_label_create(push_btn); 48 lv_label_set_text(push_label, "Push"); 49 50 lv_obj_t * pop_btn = lv_btn_create(root); 51 lv_obj_t * pop_label = lv_label_create(pop_btn); 52 lv_label_set_text(pop_label, "Pop"); 53 lv_obj_set_grid_cell(push_btn, LV_GRID_ALIGN_START, 0, 1, LV_GRID_ALIGN_CENTER, 1, 1); 54 lv_obj_set_grid_cell(pop_btn, LV_GRID_ALIGN_END, 1, 1, LV_GRID_ALIGN_CENTER, 1, 1); 55 56 lv_fragment_manager_t * manager = lv_fragment_manager_create(NULL); 57 int depth = 0; 58 lv_fragment_t * fragment = lv_fragment_create(&sample_cls, &depth); 59 lv_fragment_manager_push(manager, fragment, &container); 60 lv_obj_add_event_cb(push_btn, sample_push_click, LV_EVENT_CLICKED, manager); 61 lv_obj_add_event_cb(pop_btn, sample_pop_click, LV_EVENT_CLICKED, manager); 62 } 63 64 65 static void sample_fragment_ctor(lv_fragment_t * self, void * args) 66 { 67 LV_UNUSED(args); 68 ((sample_fragment_t *) self)->depth = *((int *) args); 69 ((sample_fragment_t *) self)->counter = 0; 70 } 71 72 static lv_obj_t * sample_fragment_create_obj(lv_fragment_t * self, lv_obj_t * parent) 73 { 74 sample_fragment_t * fragment = (sample_fragment_t *) self; 75 lv_obj_t * content = lv_obj_create(parent); 76 lv_obj_remove_style_all(content); 77 lv_obj_set_style_bg_opa(content, LV_OPA_50, 0); 78 lv_obj_set_style_bg_color(content, lv_palette_main(LV_PALETTE_YELLOW), 0); 79 lv_obj_set_size(content, LV_PCT(100), LV_PCT(100)); 80 lv_obj_set_flex_flow(content, LV_FLEX_FLOW_COLUMN); 81 lv_obj_t * depth = lv_label_create(content); 82 lv_label_set_text_fmt(depth, "Depth: %d", fragment->depth); 83 lv_obj_t * label = lv_label_create(content); 84 fragment->label = label; 85 lv_label_set_text_fmt(label, "The button has been pressed %d times", fragment->counter); 86 87 lv_obj_t * inc_btn = lv_btn_create(content); 88 lv_obj_t * inc_label = lv_label_create(inc_btn); 89 lv_label_set_text(inc_label, "+1"); 90 lv_obj_add_event_cb(inc_btn, sample_fragment_inc_click, LV_EVENT_CLICKED, fragment); 91 92 return content; 93 } 94 95 static void sample_push_click(lv_event_t * e) 96 { 97 lv_fragment_manager_t * manager = (lv_fragment_manager_t *) lv_event_get_user_data(e); 98 size_t stack_size = lv_fragment_manager_get_stack_size(manager); 99 lv_fragment_t * fragment = lv_fragment_create(&sample_cls, &stack_size); 100 lv_fragment_manager_push(manager, fragment, &container); 101 } 102 103 static void sample_pop_click(lv_event_t * e) 104 { 105 lv_fragment_manager_t * manager = (lv_fragment_manager_t *) lv_event_get_user_data(e); 106 lv_fragment_manager_pop(manager); 107 } 108 109 static void sample_fragment_inc_click(lv_event_t * e) 110 { 111 sample_fragment_t * fragment = (sample_fragment_t *) lv_event_get_user_data(e); 112 fragment->counter++; 113 lv_label_set_text_fmt(fragment->label, "The button has been pressed %d times", fragment->counter); 114 } 115 116 #endif