mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-28 07:03:00 +08:00
Added lv_dropdown_clear_options, convert options when adding
This commit is contained in:
parent
e19ce6b451
commit
f6b8a2f1b6
@ -177,6 +177,26 @@ void lv_dropdown_set_text(lv_obj_t * ddlist, const char * txt)
|
|||||||
lv_obj_invalidate(ddlist);
|
lv_obj_invalidate(ddlist);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear any options in a drop down list. Static or dynamic.
|
||||||
|
* @param ddlist pointer to drop down list object
|
||||||
|
*/
|
||||||
|
void lv_dropdown_clear_options(lv_obj_t * ddlist)
|
||||||
|
{
|
||||||
|
LV_ASSERT_OBJ(ddlist, LV_OBJX_NAME);
|
||||||
|
lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
||||||
|
if(ext->options == NULL) return;
|
||||||
|
|
||||||
|
if(ext->static_txt == 0)
|
||||||
|
lv_mem_free(ext->options);
|
||||||
|
|
||||||
|
ext->options = NULL;
|
||||||
|
ext->static_txt = 0;
|
||||||
|
ext->option_cnt = 0;
|
||||||
|
|
||||||
|
lv_obj_invalidate(ddlist);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the options in a drop down list from a string
|
* Set the options in a drop down list from a string
|
||||||
* @param ddlist pointer to drop down list object
|
* @param ddlist pointer to drop down list object
|
||||||
@ -262,11 +282,17 @@ void lv_dropdown_add_option(lv_obj_t * ddlist, const char * option, uint16_t pos
|
|||||||
|
|
||||||
lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
||||||
|
|
||||||
/*Clear any existing static options*/
|
/*Convert static options to dynmaic*/
|
||||||
if(ext->static_txt != 0) {
|
if(ext->static_txt != 0) {
|
||||||
ext->options = NULL;
|
char * static_options = ext->options;
|
||||||
|
size_t len = strlen(static_options) + 1;
|
||||||
|
|
||||||
|
ext->options = lv_mem_alloc(len);
|
||||||
|
LV_ASSERT_MEM(ext->options);
|
||||||
|
if(ext->options == NULL) return;
|
||||||
|
|
||||||
|
strcpy(ext->options, static_options);
|
||||||
ext->static_txt = 0;
|
ext->static_txt = 0;
|
||||||
ext->option_cnt = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*Allocate space for the new option*/
|
/*Allocate space for the new option*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user