1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-02-04 07:13:00 +08:00
lvgl/lv_objx/lv_objx_templ.c

170 lines
4.1 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
2016-06-08 07:25:08 +02:00
*
*/
2016-07-19 14:05:27 +02:00
/*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)
2016-06-22 17:24:02 +02:00
* 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_conf.h"
#if USE_LV_TEMPL != 0
#include "lv_templ.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static bool lv_templ_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mode_t mode);
/**********************
* STATIC VARIABLES
**********************/
static lv_templs_t lv_templs_def =
{ /*Create a default style*/ };
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/*-----------------
* Create function
*-----------------*/
/**
2016-06-22 17:24:02 +02:00
* Create a template objects
* @param par_dp pointer to an object, it will be the parent of the new template
* @param copy_dp pointer to a template object, if not NULL then the new object will be copied from it
* @return pointer to the created template
2016-06-08 07:25:08 +02:00
*/
2016-07-19 14:05:27 +02:00
lv_obj_t* lv_templ_create(lv_obj_t* par_dp, lv_obj_t * copy_dp)
2016-06-08 07:25:08 +02:00
{
2016-06-22 17:24:02 +02:00
/*Create the ancestor basic object*/
2016-07-19 14:05:27 +02:00
lv_obj_t* new_obj_dp = lv_obj_create(par_dp, copy_dp);
2016-06-22 17:24:02 +02:00
dm_assert(new_obj_dp);
2016-06-08 07:25:08 +02:00
2016-08-04 11:33:35 +02:00
/*Allocate the object type specific extended data*/
lv_templ_ext_t * ext_dp = lv_obj_alloc_ext(new_obj_dp, sizeof(lv_templ_ext_t));
dm_assert(ext_dp);
2016-06-22 17:24:02 +02:00
/*Init the new template object*/
2016-08-04 11:33:35 +02:00
if(copy_dp == NULL) {
lv_obj_set_signal_f(new_obj_dp, lv_templ_signal);
} else {
}
2016-06-08 07:25:08 +02:00
2016-06-22 17:24:02 +02:00
return new_obj_dp;
2016-06-08 07:25:08 +02:00
}
/**
2016-06-22 17:24:02 +02:00
* Signal function of the template
* @param obj_dp pointer to a template object
2016-06-08 07:25:08 +02:00
* @param sign a signal type from lv_signal_t enum
* @param param pointer to a signal specific variable
*/
2016-06-22 17:24:02 +02:00
bool lv_templ_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param)
2016-06-08 07:25:08 +02:00
{
bool valid;
/* Include the ancient signal function */
2016-06-22 17:24:02 +02:00
/* TODO update it to the ancient signal function*/
2016-06-08 07:25:08 +02:00
valid = lv_obj_signal(obj_dp, sign, param);
/* The object can be deleted so check its validity and then
* make the object specific signal handling */
if(valid != false) {
switch(sign) {
case LV_SIGNAL_CLEANUP:
/*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/
break;
2016-06-08 07:25:08 +02:00
default:
break;
}
}
return valid;
}
2016-07-19 14:05:27 +02:00
/*=====================
* Setter functions
*====================*/
/*=====================
* Getter functions
*====================*/
2016-06-08 07:25:08 +02:00
/**
* Return with a pointer to a built-in style and/or copy it to a variable
2016-06-22 17:24:02 +02:00
* @param style a style name from lv_templs_builtin_t enum
2016-06-08 07:25:08 +02:00
* @param copy_p copy the style to this variable. (NULL if unused)
* @return pointer to an lv_templs_t style
*/
2016-06-22 17:24:02 +02:00
lv_templs_t * lv_templs_get(lv_templs_builtin_t style, lv_templs_t * copy_p)
2016-06-08 07:25:08 +02:00
{
2016-06-22 17:24:02 +02:00
lv_templs_t *style_p;
2016-06-08 07:25:08 +02:00
switch(style) {
2016-06-22 17:24:02 +02:00
case LV_TEMPLS_DEF:
style_p = &lv_templs_def;
2016-06-08 07:25:08 +02:00
break;
default:
2016-06-22 17:24:02 +02:00
style_p = &lv_templs_def;
2016-06-08 07:25:08 +02:00
}
if(copy_p != NULL) {
if(style_p != NULL) memcpy(copy_p, style_p, sizeof(lv_templs_t));
2016-06-22 17:24:02 +02:00
else memcpy(copy_p, &lv_templs_def, sizeof(lv_templs_t));
2016-06-08 07:25:08 +02:00
}
return style_p;
}
/**********************
* STATIC FUNCTIONS
**********************/
/**
2016-06-22 17:24:02 +02:00
* Handle the drawing related tasks of the templates
2016-06-08 07:25:08 +02:00
* @param obj_dp pointer to an object
* @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')
* @param return true/false, depends on 'mode'
*/
2016-06-22 17:24:02 +02:00
static bool lv_templ_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mode_t mode)
2016-06-08 07:25:08 +02:00
{
if(mode == LV_DESIGN_COVER_CHK) {
/*Return false if the object is not covers the mask_p area*/
return false;
}
/*Draw the object*/
return true;
}
#endif