Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
CTCaer
GitHub Repository: CTCaer/hekate
Path: blob/master/bdk/libs/lvgl/lv_objx/lv_objx_templ.c
1476 views
1
/**
2
* @file lv_templ.c
3
*
4
*/
5
6
/* TODO Remove these instructions
7
* Search an replace: template -> object normal name with lower case (e.g. button, label etc.)
8
* templ -> object short name with lower case(e.g. btn, label etc)
9
* TEMPL -> object short name with upper case (e.g. BTN, LABEL etc.)
10
*
11
*/
12
13
/*********************
14
* INCLUDES
15
*********************/
16
//#include "lv_templ.h" /*TODO uncomment this*/
17
#if USE_LV_TEMPL != 0
18
19
/*********************
20
* DEFINES
21
*********************/
22
23
/**********************
24
* TYPEDEFS
25
**********************/
26
27
/**********************
28
* STATIC PROTOTYPES
29
**********************/
30
static bool lv_templ_design(lv_obj_t * templ, const lv_area_t * mask, lv_design_mode_t mode);
31
static lv_res_t lv_templ_signal(lv_obj_t * templ, lv_signal_t sign, void * param);
32
33
/**********************
34
* STATIC VARIABLES
35
**********************/
36
static lv_signal_func_t ancestor_signal;
37
static lv_design_func_t ancestor_design;
38
39
/**********************
40
* MACROS
41
**********************/
42
43
/**********************
44
* GLOBAL FUNCTIONS
45
**********************/
46
47
/**
48
* Create a template object
49
* @param par pointer to an object, it will be the parent of the new template
50
* @param copy pointer to a template object, if not NULL then the new object will be copied from it
51
* @return pointer to the created template
52
*/
53
lv_obj_t * lv_templ_create(lv_obj_t * par, const lv_obj_t * copy)
54
{
55
LV_LOG_TRACE("template create started");
56
57
/*Create the ancestor of template*/
58
/*TODO modify it to the ancestor create function */
59
lv_obj_t * new_templ = lv_ANCESTOR_create(par, copy);
60
lv_mem_assert(new_templ);
61
if(new_templ == NULL) return NULL;
62
63
/*Allocate the template type specific extended data*/
64
lv_templ_ext_t * ext = lv_obj_allocate_ext_attr(new_templ, sizeof(lv_templ_ext_t));
65
lv_mem_assert(ext);
66
if(ext == NULL) return NULL;
67
if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_templ);
68
if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_func(new_templ);
69
70
/*Initialize the allocated 'ext' */
71
ext->xyz = 0;
72
73
/*The signal and design functions are not copied so set them here*/
74
lv_obj_set_signal_func(new_templ, lv_templ_signal);
75
lv_obj_set_design_func(new_templ, lv_templ_design);
76
77
/*Init the new template template*/
78
if(copy == NULL) {
79
80
}
81
/*Copy an existing template*/
82
else {
83
lv_templ_ext_t * copy_ext = lv_obj_get_ext_attr(copy);
84
85
/*Refresh the style with new signal function*/
86
lv_obj_refresh_style(new_templ);
87
}
88
89
LV_LOG_INFO("template created");
90
91
return new_templ;
92
}
93
94
/*======================
95
* Add/remove functions
96
*=====================*/
97
98
/*
99
* New object specific "add" or "remove" functions come here
100
*/
101
102
103
/*=====================
104
* Setter functions
105
*====================*/
106
107
/*
108
* New object specific "set" functions come here
109
*/
110
111
112
/**
113
* Set a style of a template.
114
* @param templ pointer to template object
115
* @param type which style should be set
116
* @param style pointer to a style
117
*/
118
void lv_templ_set_style(lv_obj_t * templ, lv_templ_style_t type, lv_style_t * style)
119
{
120
lv_templ_ext_t * ext = lv_obj_get_ext_attr(templ);
121
122
switch(type) {
123
case LV_TEMPL_STYLE_X:
124
break;
125
case LV_TEMPL_STYLE_Y:
126
break;
127
}
128
}
129
130
/*=====================
131
* Getter functions
132
*====================*/
133
134
/*
135
* New object specific "get" functions come here
136
*/
137
138
/**
139
* Get style of a template.
140
* @param templ pointer to template object
141
* @param type which style should be get
142
* @return style pointer to the style
143
*/
144
lv_style_t * lv_templ_get_style(const lv_obj_t * templ, lv_templ_style_t type)
145
{
146
lv_templ_ext_t * ext = lv_obj_get_ext_attr(templ);
147
lv_style_t * style = NULL;
148
149
switch(type) {
150
case LV_TEMPL_STYLE_X:
151
style = NULL; /*Replace NULL with a pointer to the style*/
152
case LV_TEMPL_STYLE_Y:
153
style = NULL; /*Replace NULL with a pointer to the style*/
154
default:
155
style = NULL;
156
}
157
158
return style;
159
}
160
161
/*=====================
162
* Other functions
163
*====================*/
164
165
/*
166
* New object specific "other" functions come here
167
*/
168
169
/**********************
170
* STATIC FUNCTIONS
171
**********************/
172
173
/**
174
* Handle the drawing related tasks of the templates
175
* @param templ pointer to an object
176
* @param mask the object will be drawn only in this area
177
* @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area
178
* (return 'true' if yes)
179
* LV_DESIGN_DRAW: draw the object (always return 'true')
180
* LV_DESIGN_DRAW_POST: drawing after every children are drawn
181
* @param return true/false, depends on 'mode'
182
*/
183
static bool lv_templ_design(lv_obj_t * templ, const lv_area_t * mask, lv_design_mode_t mode)
184
{
185
/*Return false if the object is not covers the mask_p area*/
186
if(mode == LV_DESIGN_COVER_CHK) {
187
return false;
188
}
189
/*Draw the object*/
190
else if(mode == LV_DESIGN_DRAW_MAIN) {
191
192
}
193
/*Post draw when the children are drawn*/
194
else if(mode == LV_DESIGN_DRAW_POST) {
195
196
}
197
198
return true;
199
}
200
201
/**
202
* Signal function of the template
203
* @param templ pointer to a template object
204
* @param sign a signal type from lv_signal_t enum
205
* @param param pointer to a signal specific variable
206
* @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
207
*/
208
static lv_res_t lv_templ_signal(lv_obj_t * templ, lv_signal_t sign, void * param)
209
{
210
lv_res_t res;
211
212
/* Include the ancient signal function */
213
res = ancestor_signal(templ, sign, param);
214
if(res != LV_RES_OK) return res;
215
216
217
if(sign == LV_SIGNAL_CLEANUP) {
218
/*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/
219
} else if(sign == LV_SIGNAL_GET_TYPE) {
220
lv_obj_type_t * buf = param;
221
uint8_t i;
222
for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/
223
if(buf->type[i] == NULL) break;
224
}
225
buf->type[i] = "lv_templ";
226
}
227
228
return res;
229
}
230
231
#endif
232
233