Description
Hi, i’ve been using LVGL for quite a while now. Lately i’ve begun to create some custom widget in order to have a more clean code. Since the custom widget are not documented i’d like to have some information about the creation and the destruction of the widget itself.
What LVGL version are you using?
8.3
What do you want to achieve?
- I’ve noticed that the code of widgets rarely utilize the lv_obj *. For example the slider has this struct:
typedef struct {
lv_bar_t bar;
lv_area_t left_knob_area;
lv_area_t right_knob_area;
int32_t * value_to_set;
uint8_t dragging : 1;
uint8_t left_knob_focus : 1;
} lv_slider_t;
while my custom widgets are tipically :
typedef struct {
lv_obj_t obj;
lv_obj_t * part_of_custom_widget;
} lv_custom_widget_t;
Is there any trouble with this usage of the custom widget?
- The code of the destrutctor of the said custom widget comes as follow:
lv_custom_widget_t * cusWidg = (lv_custom_widget_t *)obj;
lv_mem_free(cusWidg->part_of_custom_widget);
cusWidg->part_of_custom_widget = NULL;
/*Remove all style*/
lv_obj_enable_style_refresh(false); /*No need to refresh the style because the object will be deleted*/
lv_obj_remove_style_all(obj);
lv_obj_enable_style_refresh(true);
/*Remove the animations from this object*/
lv_anim_del(obj, NULL);
/*Delete from the group*/
lv_group_t * group = lv_obj_get_group(obj);
if(group) lv_group_remove_obj(obj);
if(obj->spec_attr) {
if(obj->spec_attr->children) {
lv_mem_free(obj->spec_attr->children);
obj->spec_attr->children = NULL;
}
if(obj->spec_attr->event_dsc) {
lv_mem_free(obj->spec_attr->event_dsc);
obj->spec_attr->event_dsc = NULL;
}
lv_mem_free(obj->spec_attr);
obj->spec_attr = NULL;
}
_lv_event_mark_deleted(obj);
Am i missing something during the distruction of the widget?
Thank you in advance,