mirror of
https://github.com/lvgl/lvgl.git
synced 2025-02-04 07:13:00 +08:00
fix(template) udpate lv_objx_template to v8
This commit is contained in:
parent
8cd504d58b
commit
38bb8afc16
@ -5,8 +5,7 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO Remove these instructions
|
* TODO Remove these instructions
|
||||||
* Search an replace: template -> object normal name with lower case (e.g. button, label etc.)
|
* Search an replace: templ -> object short name with lower case(e.g. btn, 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.)
|
* TEMPL -> object short name with upper case (e.g. BTN, LABEL etc.)
|
||||||
*
|
*
|
||||||
* You can remove the defined() clause from the #if statement below. This exists because
|
* You can remove the defined() clause from the #if statement below. This exists because
|
||||||
@ -16,7 +15,6 @@
|
|||||||
/*********************
|
/*********************
|
||||||
* INCLUDES
|
* INCLUDES
|
||||||
*********************/
|
*********************/
|
||||||
#include "../misc/lv_assert.h"
|
|
||||||
//#include "lv_templ.h" /*TODO uncomment this*/
|
//#include "lv_templ.h" /*TODO uncomment this*/
|
||||||
|
|
||||||
#if defined(LV_USE_TEMPL) && LV_USE_TEMPL != 0
|
#if defined(LV_USE_TEMPL) && LV_USE_TEMPL != 0
|
||||||
@ -33,14 +31,24 @@
|
|||||||
/**********************
|
/**********************
|
||||||
* STATIC PROTOTYPES
|
* STATIC PROTOTYPES
|
||||||
**********************/
|
**********************/
|
||||||
static lv_draw_res_t lv_templ_draw(lv_obj_t * templ, const lv_area_t * clip_area, lv_draw_mode_t mode);
|
static void lv_templ_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj);
|
||||||
static lv_res_t lv_templ_signal(lv_obj_t * templ, lv_signal_t sign, void * param);
|
static void lv_templ_destructor(const lv_obj_class_t * class_p, lv_obj_t * obj);
|
||||||
|
static void lv_templ_event(const lv_obj_class_t * class_p, lv_event_t * e);
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* STATIC VARIABLES
|
* STATIC VARIABLES
|
||||||
**********************/
|
**********************/
|
||||||
static lv_signal_cb_t ancestor_signal;
|
const lv_obj_class_t lv_templ_class = {
|
||||||
static lv_draw_cb_t ancestor_draw;
|
.constructor_cb = lv_templ_constructor,
|
||||||
|
.destructor_cb = lv_templ_destructor,
|
||||||
|
.event_cb = lv_templ_event,
|
||||||
|
.width_def = LV_DPI_DEF,
|
||||||
|
.height_def = LV_DPI_DEF,
|
||||||
|
.instance_size = sizeof(lv_templ_t),
|
||||||
|
.group_def = LV_OBJ_CLASS_GROUP_DEF_INHERIT,
|
||||||
|
.editable = LV_OBJ_CLASS_EDITABLE_INHERIT,
|
||||||
|
.base_class = &lv_templ_class
|
||||||
|
};
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* MACROS
|
* MACROS
|
||||||
@ -50,55 +58,13 @@ static lv_draw_cb_t ancestor_draw;
|
|||||||
* GLOBAL FUNCTIONS
|
* GLOBAL FUNCTIONS
|
||||||
**********************/
|
**********************/
|
||||||
|
|
||||||
/**
|
lv_obj_t * lv_templ_create(lv_obj_t * parent)
|
||||||
* Create a template object
|
|
||||||
* @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
|
|
||||||
* @return pointer to the created template
|
|
||||||
*/
|
|
||||||
lv_obj_t * lv_templ_create(lv_obj_t * par, const lv_obj_t * copy)
|
|
||||||
{
|
{
|
||||||
LV_LOG_TRACE("template create started");
|
|
||||||
|
|
||||||
/*Create the ancestor of template*/
|
LV_LOG_INFO("begin");
|
||||||
/*TODO modify it to the ancestor create function*/
|
lv_obj_t * obj = lv_obj_class_create_obj(MY_CLASS, parent);
|
||||||
lv_obj_t * new_templ = lv_ANCESTOR_create(par, copy);
|
lv_obj_class_init_obj(obj);
|
||||||
LV_ASSERT_MALLOC(new_templ);
|
return obj;
|
||||||
if(new_templ == NULL) return NULL;
|
|
||||||
|
|
||||||
/*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);
|
|
||||||
if(ext == NULL) {
|
|
||||||
lv_obj_del(new_templ);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_cb(new_templ);
|
|
||||||
if(ancestor_draw == NULL) ancestor_draw = lv_obj_get_draw_cb(new_templ);
|
|
||||||
|
|
||||||
/*Initialize the allocated 'ext'*/
|
|
||||||
ext->xyz = 0;
|
|
||||||
|
|
||||||
/*The signal and draw functions are not copied so set them here*/
|
|
||||||
lv_obj_set_signal_cb(new_templ, lv_templ_signal);
|
|
||||||
lv_obj_set_draw_cb(new_templ, lv_templ_draw);
|
|
||||||
|
|
||||||
/*Init the new template template*/
|
|
||||||
if(copy == NULL) {
|
|
||||||
|
|
||||||
}
|
|
||||||
/*Copy an existing template*/
|
|
||||||
else {
|
|
||||||
lv_templ_ext_t * copy_ext = lv_obj_get_ext_attr(copy);
|
|
||||||
|
|
||||||
/*Refresh the style with new signal function*/
|
|
||||||
lv_obj_refresh_style(new_templ);
|
|
||||||
}
|
|
||||||
|
|
||||||
LV_LOG_INFO("template created");
|
|
||||||
|
|
||||||
return new_templ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*======================
|
/*======================
|
||||||
@ -117,26 +83,6 @@ lv_obj_t * lv_templ_create(lv_obj_t * par, const lv_obj_t * copy)
|
|||||||
* New object specific "set" functions come here
|
* New object specific "set" functions come here
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
|
||||||
* 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
|
|
||||||
*/
|
|
||||||
void lv_templ_set_style(lv_obj_t * templ, lv_templ_style_t type, const lv_style_t * style)
|
|
||||||
{
|
|
||||||
LV_ASSERT_OBJ(templ, MY_CLASS);
|
|
||||||
|
|
||||||
lv_templ_ext_t * ext = lv_obj_get_ext_attr(templ);
|
|
||||||
|
|
||||||
switch(type) {
|
|
||||||
case LV_TEMPL_STYLE_X:
|
|
||||||
break;
|
|
||||||
case LV_TEMPL_STYLE_Y:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*=====================
|
/*=====================
|
||||||
* Getter functions
|
* Getter functions
|
||||||
*====================*/
|
*====================*/
|
||||||
@ -145,31 +91,6 @@ void lv_templ_set_style(lv_obj_t * templ, lv_templ_style_t type, const lv_style_
|
|||||||
* New object specific "get" functions come here
|
* New object specific "get" functions come here
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
|
||||||
* 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(const lv_obj_t * templ, lv_templ_style_t type)
|
|
||||||
{
|
|
||||||
LV_ASSERT_OBJ(templ, MY_CLASS);
|
|
||||||
|
|
||||||
lv_templ_ext_t * ext = lv_obj_get_ext_attr(templ);
|
|
||||||
lv_style_t * style = NULL;
|
|
||||||
|
|
||||||
switch(type) {
|
|
||||||
case LV_TEMPL_STYLE_X:
|
|
||||||
style = NULL; /*Replace NULL with a pointer to the style*/
|
|
||||||
case LV_TEMPL_STYLE_Y:
|
|
||||||
style = NULL; /*Replace NULL with a pointer to the style*/
|
|
||||||
default:
|
|
||||||
style = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return style;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*=====================
|
/*=====================
|
||||||
* Other functions
|
* Other functions
|
||||||
*====================*/
|
*====================*/
|
||||||
@ -182,54 +103,34 @@ lv_style_t * lv_templ_get_style(const lv_obj_t * templ, lv_templ_style_t type)
|
|||||||
* STATIC FUNCTIONS
|
* STATIC FUNCTIONS
|
||||||
**********************/
|
**********************/
|
||||||
|
|
||||||
/**
|
static void lv_templ_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj)
|
||||||
* Handle the drawing related tasks of the templates
|
|
||||||
* @param templ pointer to an object
|
|
||||||
* @param mask the object will be drawn only in this area
|
|
||||||
* @param mode LV_DRAW_COVER_CHK: only check if the object fully covers the 'mask_p' area
|
|
||||||
* (return 'true' if yes)
|
|
||||||
* LV_DRAW_DRAW: draw the object (always return 'true')
|
|
||||||
* LV_DRAW_DRAW_POST: drawing after every children are drawn
|
|
||||||
* @param return an element of `lv_draw_res_t`
|
|
||||||
*/
|
|
||||||
static lv_draw_res_t lv_templ_draw(lv_obj_t * templ, const lv_area_t * clip_area, lv_draw_mode_t mode)
|
|
||||||
{
|
{
|
||||||
/*Return false if the object is not covers the mask_p area*/
|
LV_UNUSED(class_p);
|
||||||
if(mode == LV_DRAW_COVER_CHK) {
|
LV_TRACE_OBJ_CREATE("begin");
|
||||||
return LV_COVER_RES_NOT_COVER;
|
|
||||||
}
|
|
||||||
/*Draw the object*/
|
|
||||||
else if(mode == LV_DRAW_DRAW_MAIN) {
|
|
||||||
|
|
||||||
}
|
lv_templ_t * templ = (lv_templ_t *)obj;
|
||||||
/*Post draw when the children are drawn*/
|
/*Initialize the widget's data*/
|
||||||
else if(mode == LV_DRAW_DRAW_POST) {
|
|
||||||
}
|
|
||||||
|
|
||||||
return LV_COVER_RES_OK;
|
LV_TRACE_OBJ_CREATE("finished");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
static void lv_templ_destructor(const lv_obj_class_t * class_p, lv_obj_t * obj)
|
||||||
* 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_templ_t * templ = (lv_templ_t *)obj;
|
||||||
|
/*Free the widget specific data*/
|
||||||
|
}
|
||||||
|
|
||||||
|
static void lv_templ_event(const lv_obj_class_t * class_p, lv_event_t * e)
|
||||||
|
{
|
||||||
|
LV_UNUSED(class_p);
|
||||||
|
|
||||||
lv_res_t res;
|
lv_res_t res;
|
||||||
|
|
||||||
/*Call the ancestor's event handler*/
|
/*Call the ancestor's event handler*/
|
||||||
res = ancestor_signal(templ, sign, param);
|
res = lv_obj_event_base(MY_CLASS, e);
|
||||||
if(res != LV_RES_OK) return res;
|
if(res != LV_RES_OK) return;
|
||||||
if(sign == LV_SIGNAL_GET_TYPE) return lv_obj_handle_get_type_signal(param, MY_CLASS);
|
|
||||||
|
|
||||||
if(sign == LV_SIGNAL_CLEANUP) {
|
/*Add the widget specific event handling here*/
|
||||||
/*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/
|
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#else /*Enable this file at the top*/
|
#else /*Enable this file at the top*/
|
||||||
|
@ -5,8 +5,7 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO Remove these instructions
|
* TODO Remove these instructions
|
||||||
* Search an replace: template -> object normal name with lower case (e.g. button, label etc.)
|
* Search an replace: templ -> object short name with lower case(e.g. btn, 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.)
|
* TEMPL -> object short name with upper case (e.g. BTN, LABEL etc.)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -36,28 +35,22 @@ extern "C" {
|
|||||||
**********************/
|
**********************/
|
||||||
/*Data of template*/
|
/*Data of template*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
lv_ANCESTOR_ext_t ANCESTOR; /*Ext. of ancestor*/
|
lv_ANCESTOR_t ancestor; /*The ancestor widget, e.g. lv_slider_t slider*/
|
||||||
/*New data for this type*/
|
/*New data for this type*/
|
||||||
} lv_templ_ext_t;
|
} lv_templ_t;
|
||||||
|
|
||||||
/*Styles*/
|
extern const lv_obj_class_t lv_templ_class;
|
||||||
enum {
|
|
||||||
LV_TEMPL_STYLE_X,
|
|
||||||
LV_TEMPL_STYLE_Y,
|
|
||||||
};
|
|
||||||
typedef uint8_t lv_templ_style_t;
|
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* GLOBAL PROTOTYPES
|
* GLOBAL PROTOTYPES
|
||||||
**********************/
|
**********************/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a template objects
|
* Create a templ objects
|
||||||
* @param par pointer to an object, it will be the parent of the new template
|
* @param parent pointer to an object, it will be the parent of the new templ
|
||||||
* @param copy pointer to a template object, if not NULL then the new object will be copied from it
|
* @return pointer to the created bar
|
||||||
* @return pointer to the created template
|
|
||||||
*/
|
*/
|
||||||
lv_obj_t * lv_templ_create(lv_obj_t * par, const lv_obj_t * copy);
|
lv_obj_t * lv_templ_create(lv_obj_t * parent);
|
||||||
|
|
||||||
/*======================
|
/*======================
|
||||||
* Add/remove functions
|
* Add/remove functions
|
||||||
@ -67,26 +60,10 @@ lv_obj_t * lv_templ_create(lv_obj_t * par, const lv_obj_t * copy);
|
|||||||
* Setter functions
|
* Setter functions
|
||||||
*====================*/
|
*====================*/
|
||||||
|
|
||||||
/**
|
|
||||||
* 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
|
|
||||||
*/
|
|
||||||
void lv_templ_set_style(lv_obj_t * templ, lv_templ_style_t type, const lv_style_t * style);
|
|
||||||
|
|
||||||
/*=====================
|
/*=====================
|
||||||
* Getter functions
|
* Getter functions
|
||||||
*====================*/
|
*====================*/
|
||||||
|
|
||||||
/**
|
|
||||||
* 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(const lv_obj_t * templ, lv_templ_style_t type);
|
|
||||||
|
|
||||||
/*=====================
|
/*=====================
|
||||||
* Other functions
|
* Other functions
|
||||||
*====================*/
|
*====================*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user