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