remove free_data/ptr and relpace with user_data

This commit is contained in:
Gabor Kiss-Vamosi
2019-03-02 20:53:51 +01:00
parent 13f0b61953
commit e788907d9c
5 changed files with 76 additions and 164 deletions

View File

@@ -61,7 +61,7 @@
#endif
#if LV_MEM_CUSTOM == 0
#ifndef LV_MEM_SIZE
# define LV_MEM_SIZE (16U * 1024U) /*Size memory used by `lv_mem_alloc` in bytes (>= 2kB)*/
# define LV_MEM_SIZE (32U * 1024U) /*Size memory used by `lv_mem_alloc` in bytes (>= 2kB)*/
#endif
#ifndef LV_MEM_ATTR
# define LV_MEM_ATTR /*Complier prefix for big array declaration*/

View File

@@ -182,8 +182,7 @@ typedef void * lv_indev_drv_user_data_t; /*Type of user data in t
/*===================
* LV_OBJ SETTINGS
*==================*/
#define LV_OBJ_FREE_NUM_TYPE uint32_t /*Type of free number attribute (comment out disable free number)*/
#define LV_OBJ_FREE_PTR 1 /*Enable the free pointer attribute*/
typedef void * lv_obj_user_data_t; /*Declare the type of the user data of object (can be e.g. `void *`, `int`, `struct`)*/
#define LV_OBJ_REALIGN 1 /*Enable `lv_obj_realaign()` based on `lv_obj_align()` parameters*/
/*==================

View File

@@ -164,17 +164,19 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, const lv_obj_t * copy)
} else {
new_obj->style_p = &lv_style_scr;
}
/*Set virtual functions*/
/*Set the callbacks*/
lv_obj_set_signal_cb(new_obj, lv_obj_signal);
lv_obj_set_design_cb(new_obj, lv_obj_design);
new_obj->event_cb = NULL;
/*Set free data*/
#ifdef LV_OBJ_FREE_NUM_TYPE
new_obj->free_num = 0;
/*Init. user date*/
#if USE_LV_USER_DATA_SINGLE
memset(&new_obj->user_data, 0, sizeof(lv_obj_user_data_t));
#endif
#if LV_OBJ_FREE_PTR != 0
new_obj->free_ptr = NULL;
#if USE_LV_USER_DATA_MULTI
memset(&new_obj->event_user_data, 0, sizeof(lv_obj_user_data_t));
memset(&new_obj->signal_user_data, 0, sizeof(lv_obj_user_data_t));
memset(&new_obj->design_user_data, 0, sizeof(lv_obj_user_data_t));
#endif
#if USE_LV_GROUP
@@ -232,17 +234,21 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, const lv_obj_t * copy)
new_obj->style_p = &lv_style_plain_color;
}
/*Set callbacks*/
/*Set the callbacks*/
lv_obj_set_signal_cb(new_obj, lv_obj_signal);
lv_obj_set_design_cb(new_obj, lv_obj_design);
new_obj->event_cb = NULL;
/*Set free data*/
#ifdef LV_OBJ_FREE_NUM_TYPE
new_obj->free_num = 0;
/*Init. user date*/
#if USE_LV_USER_DATA_SINGLE
memset(&new_obj->user_data, 0, sizeof(lv_obj_user_data_t));
#endif
#if LV_OBJ_FREE_PTR != 0
new_obj->free_ptr = NULL;
#if USE_LV_USER_DATA_MULTI
memset(&new_obj->event_user_data, 0, sizeof(lv_obj_user_data_t));
memset(&new_obj->signal_user_data, 0, sizeof(lv_obj_user_data_t));
memset(&new_obj->design_user_data, 0, sizeof(lv_obj_user_data_t));
#endif
#if USE_LV_GROUP
new_obj->group_p = NULL;
#endif
@@ -261,16 +267,19 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, const lv_obj_t * copy)
new_obj->ext_attr = NULL;
}
/*Copy the attributes if required*/
if(copy != NULL) {
lv_area_copy(&new_obj->coords, &copy->coords);
new_obj->ext_size = copy->ext_size;
/*Set free data*/
#ifdef LV_OBJ_FREE_NUM_TYPE
new_obj->free_num = copy->free_num;
#if USE_LV_USER_DATA_SINGLE
memcpy(&new_obj->user_data, &copy->user_data, sizeof(lv_obj_user_data_t));
#endif
#if LV_OBJ_FREE_PTR != 0
new_obj->free_ptr = copy->free_ptr;
#if USE_LV_USER_DATA_MULTI
memcpy(&new_obj->event_user_data, &copy->event_user_data, sizeof(lv_obj_user_data_t));
memcpy(&new_obj->signal_user_data, &copy->signal_user_data, sizeof(lv_obj_user_data_t));
memcpy(&new_obj->design_user_data, &copy->design_user_data, sizeof(lv_obj_user_data_t));
#endif
/*Copy realign*/
@@ -282,7 +291,10 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, const lv_obj_t * copy)
new_obj->realign.auto_realign = copy->realign.auto_realign;
#endif
/*Set attributes*/
/*Only copy the `event_cb`. `signal_cb` and `design_cb` will be copied the the derived object type (e.g. `lv_btn`)*/
new_obj-> event_cb = copy->event_cb;
/*Copy attributes*/
new_obj->click = copy->click;
new_obj->drag = copy->drag;
new_obj->drag_throw = copy->drag_throw;
@@ -1150,6 +1162,10 @@ void lv_obj_set_event_cb(lv_obj_t * obj, lv_event_cb_t cb)
void lv_obj_send_event(lv_obj_t * obj, lv_event_t event)
{
if(obj->event_cb) obj->event_cb(obj, event);
if(obj->event_parent && obj->par) {
lv_obj_send_event(obj->par, event);
}
}
/**
@@ -1212,32 +1228,6 @@ void lv_obj_refresh_ext_size(lv_obj_t * obj)
lv_obj_invalidate(obj);
}
#ifdef LV_OBJ_FREE_NUM_TYPE
/**
* Set an application specific number for an object.
* It can help to identify objects in the application.
* @param obj pointer to an object
* @param free_num the new free number
*/
void lv_obj_set_free_num(lv_obj_t * obj, LV_OBJ_FREE_NUM_TYPE free_num)
{
obj->free_num = free_num;
}
#endif
#if LV_OBJ_FREE_PTR != 0
/**
* Set an application specific pointer for an object.
* It can help to identify objects in the application.
* @param obj pointer to an object
* @param free_p the new free pinter
*/
void lv_obj_set_free_ptr(lv_obj_t * obj, void * free_p)
{
obj->free_ptr = free_p;
}
#endif
#if USE_LV_ANIMATION
/**
* Animate an object
@@ -1745,31 +1735,18 @@ void lv_obj_get_type(lv_obj_t * obj, lv_obj_type_t * buf)
}
}
#ifdef LV_OBJ_FREE_NUM_TYPE
#if USE_LV_USER_DATA_SINGLE
/**
* Get the free number
* Get a pointer to the pbject's user data
* @param obj pointer to an object
* @return the free number
*/
LV_OBJ_FREE_NUM_TYPE lv_obj_get_free_num(const lv_obj_t * obj)
lv_obj_user_data_t * lv_obj_get_user_data(lv_obj_t * obj)
{
return obj->free_num;
return &obj->user_data;
}
#endif
#if LV_OBJ_FREE_PTR != 0
/**
* Get the free pointer
* @param obj pointer to an object
* @return the free pointer
*/
void * lv_obj_get_free_ptr(const lv_obj_t * obj)
{
return obj->free_ptr;
}
#endif
#if USE_LV_GROUP
/**
* Get the group of the object

View File

@@ -180,10 +180,6 @@ typedef struct _lv_obj_t
void * ext_attr; /*Object type specific extended data*/
lv_style_t * style_p; /*Pointer to the object's style*/
#if LV_OBJ_FREE_PTR != 0
void * free_ptr; /*Application specific pointer (set it freely)*/
#endif
#if USE_LV_GROUP != 0
void * group_p; /*Pointer to the group of the object*/
#endif
@@ -195,6 +191,7 @@ typedef struct _lv_obj_t
uint8_t hidden :1; /*1: Object is hidden*/
uint8_t top :1; /*1: If the object or its children is clicked it goes to the foreground*/
uint8_t opa_scale_en :1; /*1: opa_scale is set*/
uint8_t event_parent :1; /*1: Send the object's events to the parent too. */
uint8_t protect; /*Automatically happening actions can be prevented. 'OR'ed values from `lv_protect_t`*/
lv_opa_t opa_scale; /*Scale down the opacity by this factor. Effects all children as well*/
@@ -203,9 +200,16 @@ typedef struct _lv_obj_t
lv_reailgn_t realign;
#endif
#ifdef LV_OBJ_FREE_NUM_TYPE
LV_OBJ_FREE_NUM_TYPE free_num; /*Application specific identifier (set it freely)*/
#if USE_LV_USER_DATA_SINGLE
lv_obj_user_data_t user_data;
#endif
#if USE_LV_USER_DATA_MULTI
lv_obj_user_data_t event_user_data;
lv_obj_user_data_t signal_user_data;
lv_obj_user_data_t design_user_data;
#endif
} lv_obj_t;
/*Protect some attributes (max. 8 bit)*/
@@ -539,26 +543,6 @@ void * lv_obj_allocate_ext_attr(lv_obj_t * obj, uint16_t ext_size);
*/
void lv_obj_refresh_ext_size(lv_obj_t * obj);
#ifdef LV_OBJ_FREE_NUM_TYPE
/**
* Set an application specific number for an object.
* It can help to identify objects in the application.
* @param obj pointer to an object
* @param free_num the new free number
*/
void lv_obj_set_free_num(lv_obj_t * obj, LV_OBJ_FREE_NUM_TYPE free_num);
#endif
#if LV_OBJ_FREE_PTR != 0
/**
* Set an application specific pointer for an object.
* It can help to identify objects in the application.
* @param obj pointer to an object
* @param free_p the new free pinter
*/
void lv_obj_set_free_ptr(lv_obj_t * obj, void * free_p);
#endif
#if USE_LV_ANIMATION
/**
* Animate an object
@@ -799,22 +783,14 @@ void * lv_obj_get_ext_attr(const lv_obj_t * obj);
*/
void lv_obj_get_type(lv_obj_t * obj, lv_obj_type_t * buf);
#ifdef LV_OBJ_FREE_NUM_TYPE
#if USE_LV_USER_DATA_SINGLE
/**
* Get the free number
* Get a pointer to the pbject's user data
* @param obj pointer to an object
* @return the free number
*/
LV_OBJ_FREE_NUM_TYPE lv_obj_get_free_num(const lv_obj_t * obj);
#endif
#if LV_OBJ_FREE_PTR != 0
/**
* Get the free pointer
* @param obj pointer to an object
* @return the free pointer
*/
void * lv_obj_get_free_ptr(const lv_obj_t * obj);
lv_obj_user_data_t * lv_obj_get_user_data(lv_obj_t * obj);
#endif
#if USE_LV_GROUP

View File

@@ -34,7 +34,7 @@
**********************/
static lv_res_t lv_tileview_signal(lv_obj_t * tileview, lv_signal_t sign, void * param);
static lv_res_t lv_tileview_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void * param);
static lv_res_t element_signal_func(lv_obj_t * element, lv_signal_t sign, void * param);
static void tileview_scrl_event_cb(lv_obj_t * scrl, lv_event_t event);
static void drag_end_handler(lv_obj_t * tileview);
static bool set_valid_drag_dirs(lv_obj_t * tileview);
@@ -92,6 +92,7 @@ lv_obj_t * lv_tileview_create(lv_obj_t * par, const lv_obj_t * copy)
lv_obj_set_size(new_tileview, LV_DPI * 3, LV_DPI * 3);
lv_obj_set_drag_throw(lv_page_get_scrl(new_tileview), false);
lv_page_set_scrl_fit(new_tileview, LV_FIT_TIGHT);
lv_obj_set_event_cb(ext->page.scrl, tileview_scrl_event_cb);
/*Set the default styles*/
lv_theme_t * th = lv_theme_get_current();
if(th) {
@@ -131,8 +132,9 @@ lv_obj_t * lv_tileview_create(lv_obj_t * par, const lv_obj_t * copy)
*/
void lv_tileview_add_element(lv_obj_t * element)
{
lv_obj_set_free_ptr(element, lv_obj_get_signal_func(element));
lv_obj_set_signal_cb(element, element_signal_func);
/* Let objects eventto propaget to the scrollable part of the tileview.
* It is required the handle dargging of the tileview with the element.*/
element->event_parent = 1;
lv_obj_set_drag_parent(element, true);
}
@@ -422,76 +424,34 @@ static lv_res_t lv_tileview_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void
if(ext->drag_hor == 0) lv_obj_set_x(scrl, - ext->act_id.x * lv_obj_get_width(tileview));
}
}
return res;
}
/**
* This function is applied called for the elements of the tileview. Used when the element is
* @param element
* @param sign
* @param param
* @return
*/
static lv_res_t element_signal_func(lv_obj_t * element, lv_signal_t sign, void * param)
{
lv_res_t res;
/* Include the ancient signal function */
lv_signal_cb_t sign_func = lv_obj_get_free_ptr(element);
res = sign_func(element, sign, param);
if(res != LV_RES_OK) return res;
static void tileview_scrl_event_cb(lv_obj_t * scrl, lv_event_t event)
{
lv_obj_t * tileview = lv_obj_get_parent(scrl);
/*Initialize some variables on PRESS*/
if(sign == LV_SIGNAL_PRESSED) {
/*Get the tileview from the element*/
lv_obj_t * tileview = lv_obj_get_parent(element);
while(tileview) {
if(lv_obj_get_signal_func(tileview) != lv_tileview_signal) tileview = lv_obj_get_parent(tileview);
else break;
}
if(tileview) {
lv_tileview_ext_t * ext = lv_obj_get_ext_attr(tileview);
ext->drag_hor = 0;
ext->drag_ver = 0;
set_valid_drag_dirs(tileview);
}
if(event == LV_EVENT_PRESSED) {
lv_tileview_ext_t * ext = lv_obj_get_ext_attr(tileview);
ext->drag_hor = 0;
ext->drag_ver = 0;
set_valid_drag_dirs(tileview);
}
/*Animate the tabview to the correct location on RELEASE*/
else if(sign == LV_SIGNAL_PRESS_LOST || sign == LV_SIGNAL_RELEASED) {
/*Get the tileview from the element*/
lv_obj_t * tileview = lv_obj_get_parent(element);
while(tileview) {
if(lv_obj_get_signal_func(tileview) != lv_tileview_signal) tileview = lv_obj_get_parent(tileview);
else break;
else if(event == LV_EVENT_PRESS_LOST || event == LV_EVENT_RELEASED) {
/* If the element was dragged and it moved the tileview finish the drag manually to
* let the tileview to finish the move.*/
lv_indev_t * indev = lv_indev_get_act();
lv_tileview_ext_t * ext = lv_obj_get_ext_attr(tileview);
if(lv_indev_is_dragging(indev) && (ext->drag_hor || ext->drag_ver)) {
indev->proc.types.pointer.drag_in_prog = 0;
// if(drag_obj) drag_obj->signal_cb(drag_obj, LV_SIGNAL_DRAG_END, NULL);
}
if(tileview) {
/* If the element was dragged and it moved the tileview finish the drag manually to
* let the tileview to finish the move.*/
lv_indev_t * indev = lv_indev_get_act();
lv_tileview_ext_t * ext = lv_obj_get_ext_attr(tileview);
if(lv_indev_is_dragging(indev) && (ext->drag_hor || ext->drag_ver)) {
lv_obj_t * drag_obj = element;
while(lv_obj_get_drag_parent(drag_obj)) {
drag_obj = lv_obj_get_parent(drag_obj);
if(drag_obj == NULL) break;
}
indev->proc.types.pointer.drag_in_prog = 0;
if(drag_obj) drag_obj->signal_cb(drag_obj, LV_SIGNAL_DRAG_END, NULL);
}
drag_end_handler(tileview);
}
drag_end_handler(tileview);
}
return res;
}
/**