Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(template) udpate lv_objx_template to v8
  • Loading branch information
kisvegabor committed Jun 7, 2021
1 parent 8cd504d commit 38bb8af
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 170 deletions.
179 changes: 40 additions & 139 deletions src/widgets/lv_objx_templ.c
Expand Up @@ -5,8 +5,7 @@

/**
* 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)
* Search an replace: templ -> object short name with lower 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
Expand All @@ -16,7 +15,6 @@
/*********************
* INCLUDES
*********************/
#include "../misc/lv_assert.h"
//#include "lv_templ.h" /*TODO uncomment this*/

#if defined(LV_USE_TEMPL) && LV_USE_TEMPL != 0
Expand All @@ -33,14 +31,24 @@
/**********************
* 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 lv_res_t lv_templ_signal(lv_obj_t * templ, lv_signal_t sign, void * param);
static void lv_templ_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj);
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 lv_signal_cb_t ancestor_signal;
static lv_draw_cb_t ancestor_draw;
const lv_obj_class_t lv_templ_class = {
.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
Expand All @@ -50,55 +58,13 @@ static lv_draw_cb_t ancestor_draw;
* GLOBAL FUNCTIONS
**********************/

/**
* 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_obj_t * lv_templ_create(lv_obj_t * parent)
{
LV_LOG_TRACE("template create started");

/*Create the ancestor of template*/
/*TODO modify it to the ancestor create function*/
lv_obj_t * new_templ = lv_ANCESTOR_create(par, copy);
LV_ASSERT_MALLOC(new_templ);
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;
LV_LOG_INFO("begin");
lv_obj_t * obj = lv_obj_class_create_obj(MY_CLASS, parent);
lv_obj_class_init_obj(obj);
return obj;
}

/*======================
Expand All @@ -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
*/

/**
* 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
*====================*/
Expand All @@ -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
*/

/**
* 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
*====================*/
Expand All @@ -182,54 +103,34 @@ lv_style_t * lv_templ_get_style(const lv_obj_t * templ, lv_templ_style_t type)
* STATIC FUNCTIONS
**********************/

/**
* 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)
static void lv_templ_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj)
{
/*Return false if the object is not covers the mask_p area*/
if(mode == LV_DRAW_COVER_CHK) {
return LV_COVER_RES_NOT_COVER;
}
/*Draw the object*/
else if(mode == LV_DRAW_DRAW_MAIN) {

}
/*Post draw when the children are drawn*/
else if(mode == LV_DRAW_DRAW_POST) {
}

return LV_COVER_RES_OK;
LV_UNUSED(class_p);
LV_TRACE_OBJ_CREATE("begin");

lv_templ_t * templ = (lv_templ_t *)obj;
/*Initialize the widget's data*/

LV_TRACE_OBJ_CREATE("finished");
}

/**
* 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)
static void lv_templ_destructor(const lv_obj_class_t * class_p, lv_obj_t * obj)
{
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;

/*Call the ancestor's event handler*/
res = ancestor_signal(templ, sign, param);
if(res != LV_RES_OK) return res;
if(sign == LV_SIGNAL_GET_TYPE) return lv_obj_handle_get_type_signal(param, MY_CLASS);

if(sign == LV_SIGNAL_CLEANUP) {
/*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/
}
res = lv_obj_event_base(MY_CLASS, e);
if(res != LV_RES_OK) return;

return res;
/*Add the widget specific event handling here*/
}

#else /*Enable this file at the top*/
Expand Down
39 changes: 8 additions & 31 deletions src/widgets/lv_objx_templ.h
Expand Up @@ -5,8 +5,7 @@

/**
* 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)
* Search an replace: templ -> object short name with lower case(e.g. btn, label etc)
* TEMPL -> object short name with upper case (e.g. BTN, LABEL etc.)
*
*/
Expand Down Expand Up @@ -36,28 +35,22 @@ extern "C" {
**********************/
/*Data of template*/
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*/
} lv_templ_ext_t;
} lv_templ_t;

/*Styles*/
enum {
LV_TEMPL_STYLE_X,
LV_TEMPL_STYLE_Y,
};
typedef uint8_t lv_templ_style_t;
extern const lv_obj_class_t lv_templ_class;

/**********************
* GLOBAL PROTOTYPES
**********************/

/**
* Create a template objects
* @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
* Create a templ objects
* @param parent pointer to an object, it will be the parent of the new templ
* @return pointer to the created bar
*/
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
Expand All @@ -67,26 +60,10 @@ lv_obj_t * lv_templ_create(lv_obj_t * par, const lv_obj_t * copy);
* 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
*====================*/

/**
* 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
*====================*/
Expand Down

0 comments on commit 38bb8af

Please sign in to comment.