1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-14 06:42:58 +08:00
lvgl/lv_objx/lv_objx_templ.c

227 lines
5.8 KiB
C
Raw Normal View History

2016-06-08 07:25:08 +02:00
/**
2016-06-22 17:24:02 +02:00
* @file lv_templ.c
2018-06-19 09:49:58 +02:00
*
2016-06-08 07:25:08 +02:00
*/
2017-10-05 11:29:21 +02:00
/* TODO Remove these instructions
* Search an replace: template -> object normal name with lower case (e.g. button, label etc.)
* templ -> object short name with lower case(e.g. btn, label etc)
* TEMPL -> object short name with upper case (e.g. BTN, LABEL etc.)
2016-07-19 14:05:27 +02:00
*
2016-06-22 17:24:02 +02:00
*/
2016-06-08 07:25:08 +02:00
/*********************
* INCLUDES
*********************/
//#include "lv_templ.h" /*TODO uncomment this*/
2016-06-08 07:25:08 +02:00
#if USE_LV_TEMPL != 0
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static bool lv_templ_design(lv_obj_t * templ, const lv_area_t * mask, lv_design_mode_t mode);
2017-11-10 15:29:53 +01:00
static lv_res_t lv_templ_signal(lv_obj_t * templ, lv_signal_t sign, void * param);
2016-06-08 07:25:08 +02:00
/**********************
* STATIC VARIABLES
**********************/
2017-11-10 15:29:53 +01:00
static lv_signal_func_t ancestor_signal;
static lv_design_func_t ancestor_design;
2016-06-08 07:25:08 +02:00
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Create a template object
2016-10-07 11:15:46 +02:00
* @param par pointer to an object, it will be the parent of the new template
* @param copy pointer to a template object, if not NULL then the new object will be copied from it
2016-06-22 17:24:02 +02:00
* @return pointer to the created template
2016-06-08 07:25:08 +02:00
*/
2016-10-07 11:15:46 +02:00
lv_obj_t * lv_templ_create(lv_obj_t * par, lv_obj_t * copy)
2016-06-08 07:25:08 +02:00
{
2017-04-21 17:11:47 +02:00
/*Create the ancestor of template*/
2018-06-19 09:49:58 +02:00
/*TODO modify it to the ancestor create function */
2017-01-02 15:00:21 +01:00
lv_obj_t * new_templ = lv_ANCESTOR_create(par, copy);
lv_mem_assert(new_templ);
2018-06-19 09:49:58 +02:00
/*Allocate the template type specific extended data*/
lv_templ_ext_t * ext = lv_obj_allocate_ext_attr(new_templ, sizeof(lv_templ_ext_t));
lv_mem_assert(ext);
2017-11-10 15:29:53 +01:00
if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_templ);
if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_func(new_templ);
2016-08-04 11:33:35 +02:00
2017-01-02 15:00:21 +01:00
/*Initialize the allocated 'ext' */
2017-04-21 17:11:47 +02:00
ext->xyz = 0;
2017-01-02 15:00:21 +01:00
/*The signal and design functions are not copied so set them here*/
lv_obj_set_signal_func(new_templ, lv_templ_signal);
lv_obj_set_design_func(new_templ, lv_templ_design);
2016-09-28 15:53:27 +02:00
/*Init the new template template*/
2016-10-07 11:15:46 +02:00
if(copy == NULL) {
2016-09-28 15:53:27 +02:00
}
/*Copy an existing template*/
2016-09-28 15:53:27 +02:00
else {
2018-06-19 09:49:58 +02:00
lv_templ_ext_t * copy_ext = lv_obj_get_ext_attr(copy);
2017-01-02 15:00:21 +01:00
/*Refresh the style with new signal function*/
lv_obj_refresh_style(new_templ);
2016-08-04 11:33:35 +02:00
}
2018-06-19 09:49:58 +02:00
2016-10-07 11:15:46 +02:00
return new_templ;
2016-06-08 07:25:08 +02:00
}
/*======================
* Add/remove functions
*=====================*/
/*
* New object specific "add" or "remove" functions come here
*/
2016-07-19 14:05:27 +02:00
/*=====================
* Setter functions
*====================*/
2017-02-06 10:07:25 +01:00
/*
2017-08-21 14:41:50 +02:00
* New object specific "set" functions come here
2017-02-06 10:07:25 +01:00
*/
2016-07-19 14:05:27 +02:00
2017-12-21 00:19:59 +01:00
/**
* Set a style of a template.
* @param templ pointer to template object
* @param type which style should be set
* @param style pointer to a style
* */
2018-06-19 09:49:58 +02:00
void lv_templ_set_style(lv_obj_t * templ, lv_templ_style_t type, lv_style_t * style)
2017-12-21 00:19:59 +01:00
{
2018-06-19 09:49:58 +02:00
lv_templ_ext_t * ext = lv_obj_get_ext_attr(templ);
2017-12-21 00:19:59 +01:00
2018-06-19 09:49:58 +02:00
switch(type) {
2017-12-21 00:19:59 +01:00
case LV_TEMPL_STYLE_X:
break;
case LV_TEMPL_STYLE_Y:
break;
}
}
2016-07-19 14:05:27 +02:00
/*=====================
* Getter functions
*====================*/
2017-02-06 10:07:25 +01:00
/*
2017-08-21 14:41:50 +02:00
* New object specific "get" functions come here
2017-02-06 10:07:25 +01:00
*/
2017-12-21 00:19:59 +01:00
/**
* Get style of a template.
* @param templ pointer to template object
* @param type which style should be get
* @return style pointer to the style
* */
lv_style_t * lv_templ_get_style(lv_obj_t * templ, lv_templ_style_t type)
2017-12-21 00:19:59 +01:00
{
2018-06-19 09:49:58 +02:00
lv_templ_ext_t * ext = lv_obj_get_ext_attr(templ);
2017-12-21 00:19:59 +01:00
2018-06-19 09:49:58 +02:00
switch(type) {
case LV_TEMPL_STYLE_X:
return NULL;
case LV_TEMPL_STYLE_Y:
return NULL;
default:
return NULL;
2017-12-21 00:19:59 +01:00
}
/*To avoid warning*/
return NULL;
}
2017-08-21 14:41:50 +02:00
/*=====================
* Other functions
*====================*/
/*
* New object specific "other" functions come here
*/
2017-02-06 10:07:25 +01:00
2016-06-08 07:25:08 +02:00
/**********************
* STATIC FUNCTIONS
**********************/
/**
2016-06-22 17:24:02 +02:00
* Handle the drawing related tasks of the templates
2016-10-07 11:15:46 +02:00
* @param templ pointer to an object
2016-06-08 07:25:08 +02:00
* @param mask the object will be drawn only in this area
* @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area
* (return 'true' if yes)
* LV_DESIGN_DRAW: draw the object (always return 'true')
* LV_DESIGN_DRAW_POST: drawing after every children are drawn
2016-06-08 07:25:08 +02:00
* @param return true/false, depends on 'mode'
*/
static bool lv_templ_design(lv_obj_t * templ, const lv_area_t * mask, lv_design_mode_t mode)
2016-06-08 07:25:08 +02:00
{
2017-01-02 15:00:21 +01:00
/*Return false if the object is not covers the mask_p area*/
2016-06-08 07:25:08 +02:00
if(mode == LV_DESIGN_COVER_CHK) {
2018-06-19 09:49:58 +02:00
return false;
2016-06-08 07:25:08 +02:00
}
2017-01-02 15:00:21 +01:00
/*Draw the object*/
else if(mode == LV_DESIGN_DRAW_MAIN) {
2016-06-08 07:25:08 +02:00
2017-01-02 15:00:21 +01:00
}
/*Post draw when the children are drawn*/
else if(mode == LV_DESIGN_DRAW_POST) {
2016-06-08 07:25:08 +02:00
2017-01-02 15:00:21 +01:00
}
2016-06-08 07:25:08 +02:00
return true;
}
2017-11-10 15:29:53 +01:00
/**
* Signal function of the template
* @param templ pointer to a template object
* @param sign a signal type from lv_signal_t enum
* @param param pointer to a signal specific variable
* @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
*/
static lv_res_t lv_templ_signal(lv_obj_t * templ, lv_signal_t sign, void * param)
{
lv_res_t res;
/* Include the ancient signal function */
res = ancestor_signal(templ, sign, param);
2017-11-10 15:29:53 +01:00
if(res != LV_RES_OK) return res;
if(sign == LV_SIGNAL_CLEANUP) {
/*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/
2018-06-19 09:49:58 +02:00
} else if(sign == LV_SIGNAL_GET_TYPE) {
2018-02-28 15:37:41 +01:00
lv_obj_type_t * buf = param;
uint8_t i;
for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/
if(buf->type[i] == NULL) break;
}
buf->type[i] = "lv_templ";
}
2017-11-10 15:29:53 +01:00
return res;
}
2016-06-08 07:25:08 +02:00
#endif