summaryrefslogtreecommitdiff
path: root/lib/lvgl/src/layouts/lv_layout.c
blob: a14c1219f5f8efd1c1a4aa9ff7083422040cafb2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/**
 * @file lv_layout.c
 *
 */

/*********************
 *      INCLUDES
 *********************/
#include "lv_layout.h"
#include "../core/lv_global.h"
#include "../core/lv_obj.h"

/*********************
 *      DEFINES
 *********************/
#define layout_cnt LV_GLOBAL_DEFAULT()->layout_count
#define layout_list_def LV_GLOBAL_DEFAULT()->layout_list

/**********************
 *      TYPEDEFS
 **********************/

/**********************
 *  STATIC PROTOTYPES
 **********************/

/**********************
 *  STATIC VARIABLES
 **********************/

/**********************
 *      MACROS
 **********************/

/**********************
 *   GLOBAL FUNCTIONS
 **********************/

void _lv_layout_init(void)
{
    /*Malloc a list for the built in layouts*/
    layout_list_def = lv_malloc(layout_cnt * sizeof(lv_layout_dsc_t));

#if LV_USE_FLEX
    lv_flex_init();
#endif

#if LV_USE_GRID
    lv_grid_init();
#endif
}

void _lv_layout_deinit(void)
{
    lv_free(layout_list_def);
}

uint32_t lv_layout_register(lv_layout_update_cb_t cb, void * user_data)
{
    layout_list_def = lv_realloc(layout_list_def, (layout_cnt + 1) * sizeof(lv_layout_dsc_t));
    LV_ASSERT_MALLOC(layout_list_def);

    layout_list_def[layout_cnt].cb = cb;
    layout_list_def[layout_cnt].user_data = user_data;
    return layout_cnt++;
}

void _lv_layout_apply(lv_obj_t * obj)
{
    lv_layout_t layout_id = lv_obj_get_style_layout(obj, LV_PART_MAIN);
    if(layout_id > 0 && layout_id <= layout_cnt) {
        void  * user_data = layout_list_def[layout_id].user_data;
        layout_list_def[layout_id].cb(obj, user_data);
    }
}

/**********************
 *   STATIC FUNCTIONS
 **********************/