feat(dropdown): add lv_dropdown_get_option_index
This commit is contained in:
@@ -398,6 +398,26 @@ void lv_dropdown_get_selected_str(const lv_obj_t * obj, char * buf, uint32_t buf
|
||||
buf[c] = '\0';
|
||||
}
|
||||
|
||||
int32_t lv_dropdown_get_option_index(lv_obj_t * obj, const char * option)
|
||||
{
|
||||
const char * opts = lv_dropdown_get_options(obj);
|
||||
uint32_t char_i = 0;
|
||||
uint32_t opt_i = 0;
|
||||
const char * start = opts;
|
||||
|
||||
while(start[char_i] != '\0') {
|
||||
for(char_i = 0; (start[char_i] != '\n') && (start[char_i] != '\0'); char_i++);
|
||||
|
||||
if(memcmp(start, option, LV_MIN(strlen(option), char_i)) == 0) return opt_i;
|
||||
start = &start[char_i];
|
||||
if(start[0] == '\n') start++;
|
||||
opt_i++;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
const char * lv_dropdown_get_symbol(lv_obj_t * obj)
|
||||
{
|
||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||
|
||||
@@ -189,6 +189,14 @@ uint16_t lv_dropdown_get_option_cnt(const lv_obj_t * obj);
|
||||
*/
|
||||
void lv_dropdown_get_selected_str(const lv_obj_t * obj, char * buf, uint32_t buf_size);
|
||||
|
||||
/**
|
||||
* Get the index of an option.
|
||||
* @param obj pointer to drop-down object
|
||||
* @param option an option as string
|
||||
* @return index of `option` in the list of all options. -1 if not found.
|
||||
*/
|
||||
int32_t lv_dropdown_get_option_index(lv_obj_t * obj, const char * option);
|
||||
|
||||
/**
|
||||
* Get the symbol on the drop-down list. Typically a down caret or arrow.
|
||||
* @param obj pointer to drop-down list object
|
||||
|
||||
Reference in New Issue
Block a user