/**1* @file lv_templ.c2*3*/45/* TODO Remove these instructions6* Search an replace: template -> object normal name with lower case (e.g. button, label etc.)7* templ -> object short name with lower case(e.g. btn, label etc)8* TEMPL -> object short name with upper case (e.g. BTN, LABEL etc.)9*10*/1112/*********************13* INCLUDES14*********************/15//#include "lv_templ.h" /*TODO uncomment this*/16#if USE_LV_TEMPL != 01718/*********************19* DEFINES20*********************/2122/**********************23* TYPEDEFS24**********************/2526/**********************27* STATIC PROTOTYPES28**********************/29static bool lv_templ_design(lv_obj_t * templ, const lv_area_t * mask, lv_design_mode_t mode);30static lv_res_t lv_templ_signal(lv_obj_t * templ, lv_signal_t sign, void * param);3132/**********************33* STATIC VARIABLES34**********************/35static lv_signal_func_t ancestor_signal;36static lv_design_func_t ancestor_design;3738/**********************39* MACROS40**********************/4142/**********************43* GLOBAL FUNCTIONS44**********************/4546/**47* Create a template object48* @param par pointer to an object, it will be the parent of the new template49* @param copy pointer to a template object, if not NULL then the new object will be copied from it50* @return pointer to the created template51*/52lv_obj_t * lv_templ_create(lv_obj_t * par, const lv_obj_t * copy)53{54LV_LOG_TRACE("template create started");5556/*Create the ancestor of template*/57/*TODO modify it to the ancestor create function */58lv_obj_t * new_templ = lv_ANCESTOR_create(par, copy);59lv_mem_assert(new_templ);60if(new_templ == NULL) return NULL;6162/*Allocate the template type specific extended data*/63lv_templ_ext_t * ext = lv_obj_allocate_ext_attr(new_templ, sizeof(lv_templ_ext_t));64lv_mem_assert(ext);65if(ext == NULL) return NULL;66if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_templ);67if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_func(new_templ);6869/*Initialize the allocated 'ext' */70ext->xyz = 0;7172/*The signal and design functions are not copied so set them here*/73lv_obj_set_signal_func(new_templ, lv_templ_signal);74lv_obj_set_design_func(new_templ, lv_templ_design);7576/*Init the new template template*/77if(copy == NULL) {7879}80/*Copy an existing template*/81else {82lv_templ_ext_t * copy_ext = lv_obj_get_ext_attr(copy);8384/*Refresh the style with new signal function*/85lv_obj_refresh_style(new_templ);86}8788LV_LOG_INFO("template created");8990return new_templ;91}9293/*======================94* Add/remove functions95*=====================*/9697/*98* New object specific "add" or "remove" functions come here99*/100101102/*=====================103* Setter functions104*====================*/105106/*107* New object specific "set" functions come here108*/109110111/**112* Set a style of a template.113* @param templ pointer to template object114* @param type which style should be set115* @param style pointer to a style116*/117void lv_templ_set_style(lv_obj_t * templ, lv_templ_style_t type, lv_style_t * style)118{119lv_templ_ext_t * ext = lv_obj_get_ext_attr(templ);120121switch(type) {122case LV_TEMPL_STYLE_X:123break;124case LV_TEMPL_STYLE_Y:125break;126}127}128129/*=====================130* Getter functions131*====================*/132133/*134* New object specific "get" functions come here135*/136137/**138* Get style of a template.139* @param templ pointer to template object140* @param type which style should be get141* @return style pointer to the style142*/143lv_style_t * lv_templ_get_style(const lv_obj_t * templ, lv_templ_style_t type)144{145lv_templ_ext_t * ext = lv_obj_get_ext_attr(templ);146lv_style_t * style = NULL;147148switch(type) {149case LV_TEMPL_STYLE_X:150style = NULL; /*Replace NULL with a pointer to the style*/151case LV_TEMPL_STYLE_Y:152style = NULL; /*Replace NULL with a pointer to the style*/153default:154style = NULL;155}156157return style;158}159160/*=====================161* Other functions162*====================*/163164/*165* New object specific "other" functions come here166*/167168/**********************169* STATIC FUNCTIONS170**********************/171172/**173* Handle the drawing related tasks of the templates174* @param templ pointer to an object175* @param mask the object will be drawn only in this area176* @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area177* (return 'true' if yes)178* LV_DESIGN_DRAW: draw the object (always return 'true')179* LV_DESIGN_DRAW_POST: drawing after every children are drawn180* @param return true/false, depends on 'mode'181*/182static bool lv_templ_design(lv_obj_t * templ, const lv_area_t * mask, lv_design_mode_t mode)183{184/*Return false if the object is not covers the mask_p area*/185if(mode == LV_DESIGN_COVER_CHK) {186return false;187}188/*Draw the object*/189else if(mode == LV_DESIGN_DRAW_MAIN) {190191}192/*Post draw when the children are drawn*/193else if(mode == LV_DESIGN_DRAW_POST) {194195}196197return true;198}199200/**201* Signal function of the template202* @param templ pointer to a template object203* @param sign a signal type from lv_signal_t enum204* @param param pointer to a signal specific variable205* @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted206*/207static lv_res_t lv_templ_signal(lv_obj_t * templ, lv_signal_t sign, void * param)208{209lv_res_t res;210211/* Include the ancient signal function */212res = ancestor_signal(templ, sign, param);213if(res != LV_RES_OK) return res;214215216if(sign == LV_SIGNAL_CLEANUP) {217/*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/218} else if(sign == LV_SIGNAL_GET_TYPE) {219lv_obj_type_t * buf = param;220uint8_t i;221for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/222if(buf->type[i] == NULL) break;223}224buf->type[i] = "lv_templ";225}226227return res;228}229230#endif231232233