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

@@ -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;
}
/**