1 /** 2 * @file lv_layout.c 3 * 4 */ 5 6 /********************* 7 * INCLUDES 8 *********************/ 9 #include "lv_layout_private.h" 10 #include "../core/lv_global.h" 11 #include "../core/lv_obj.h" 12 13 /********************* 14 * DEFINES 15 *********************/ 16 #define layout_cnt LV_GLOBAL_DEFAULT()->layout_count 17 #define layout_list_def LV_GLOBAL_DEFAULT()->layout_list 18 19 /********************** 20 * TYPEDEFS 21 **********************/ 22 23 /********************** 24 * STATIC PROTOTYPES 25 **********************/ 26 27 /********************** 28 * STATIC VARIABLES 29 **********************/ 30 31 /********************** 32 * MACROS 33 **********************/ 34 35 /********************** 36 * GLOBAL FUNCTIONS 37 **********************/ 38 lv_layout_init(void)39void lv_layout_init(void) 40 { 41 /*Malloc a list for the built in layouts*/ 42 layout_list_def = lv_malloc(layout_cnt * sizeof(lv_layout_dsc_t)); 43 44 #if LV_USE_FLEX 45 lv_flex_init(); 46 #endif 47 48 #if LV_USE_GRID 49 lv_grid_init(); 50 #endif 51 } 52 lv_layout_deinit(void)53void lv_layout_deinit(void) 54 { 55 lv_free(layout_list_def); 56 } 57 lv_layout_register(lv_layout_update_cb_t cb,void * user_data)58uint32_t lv_layout_register(lv_layout_update_cb_t cb, void * user_data) 59 { 60 layout_list_def = lv_realloc(layout_list_def, (layout_cnt + 1) * sizeof(lv_layout_dsc_t)); 61 LV_ASSERT_MALLOC(layout_list_def); 62 63 layout_list_def[layout_cnt].cb = cb; 64 layout_list_def[layout_cnt].user_data = user_data; 65 return layout_cnt++; 66 } 67 lv_layout_apply(lv_obj_t * obj)68void lv_layout_apply(lv_obj_t * obj) 69 { 70 lv_layout_t layout_id = lv_obj_get_style_layout(obj, LV_PART_MAIN); 71 if(layout_id > 0 && layout_id <= layout_cnt) { 72 void * user_data = layout_list_def[layout_id].user_data; 73 layout_list_def[layout_id].cb(obj, user_data); 74 } 75 } 76 77 /********************** 78 * STATIC FUNCTIONS 79 **********************/ 80