diff --git a/src/widgets/roller/lv_roller.c b/src/widgets/roller/lv_roller.c index d242050ab..13cb5eae2 100644 --- a/src/widgets/roller/lv_roller.c +++ b/src/widgets/roller/lv_roller.c @@ -220,6 +220,33 @@ void lv_roller_set_selected(lv_obj_t * obj, uint32_t sel_opt, lv_anim_enable_t a refr_position(obj, anim); } +bool lv_roller_set_selected_str(lv_obj_t * obj, const char * sel_opt, lv_anim_enable_t anim) +{ + const char * options = lv_roller_get_options(obj); + size_t options_len = lv_strlen(options); + + bool option_found = false; + + uint32_t current_option = 0; + size_t line_start = 0; + + for(size_t i = 0; i < options_len; i++) { + if(options[i] == '\n') { + /* See if this is the correct option */ + if(lv_strncmp(&options[line_start], sel_opt, i - line_start) == 0) { + lv_roller_set_selected(obj, current_option, anim); + option_found = true; + break; + } + + current_option++; + line_start = i + 1; + } + } + + return option_found; +} + void lv_roller_set_visible_row_count(lv_obj_t * obj, uint32_t row_cnt) { LV_ASSERT_OBJ(obj, MY_CLASS); @@ -275,34 +302,6 @@ void lv_roller_get_selected_str(const lv_obj_t * obj, char * buf, uint32_t buf_s buf[c] = '\0'; } -bool lv_roller_set_selected_str(lv_obj_t * obj, const char * sel_opt, lv_anim_enable_t anim) -{ - const char * options = lv_roller_get_options(obj); - size_t options_len = lv_strlen(options); - - bool option_found = false; - - uint32_t current_option = 0; - size_t line_start = 0; - - for(size_t i = 0; i < options_len; i++) { - if(options[i] == '\n') { - /* See if this is the correct option */ - if(lv_strncmp(&options[line_start], sel_opt, i - line_start) == 0) { - lv_roller_set_selected(obj, current_option, anim); - option_found = true; - break; - } - - current_option++; - line_start = i + 1; - } - } - - return option_found; -} - - /** * Get the options of a roller * @param roller pointer to roller object diff --git a/src/widgets/roller/lv_roller.h b/src/widgets/roller/lv_roller.h index 4c8cb3bda..5ba216b25 100644 --- a/src/widgets/roller/lv_roller.h +++ b/src/widgets/roller/lv_roller.h @@ -80,6 +80,15 @@ void lv_roller_set_options(lv_obj_t * obj, const char * options, lv_roller_mode_ */ void lv_roller_set_selected(lv_obj_t * obj, uint32_t sel_opt, lv_anim_enable_t anim); +/** + * Sets the given string as the selection on the roller. Does not alter the current selection on failure. + * @param obj pointer to roller object + * @param sel_opt pointer to the string you want to set as an option + * @param anim LV_ANIM_ON: set with animation; LV_ANOM_OFF set immediately + * @return `true` if set successfully and `false` if the given string does not exist as an option in the roller + */ +bool lv_roller_set_selected_str(lv_obj_t * obj, const char * sel_opt, lv_anim_enable_t anim); + /** * Set the height to show the given number of rows (options) * @param obj pointer to a roller object @@ -106,16 +115,6 @@ uint32_t lv_roller_get_selected(const lv_obj_t * obj); */ void lv_roller_get_selected_str(const lv_obj_t * obj, char * buf, uint32_t buf_size); - -/** - * Sets the given string as the selection on the roller. Does not alter the current selection on failure. - * @param obj pointer to roller object - * @param sel_opt pointer to the string you want to set as an option - * @param anim LV_ANIM_ON: set with animation; LV_ANOM_OFF set immediately - * @return `true` if set successfully and `false` if the given string does not exist as an option in the roller - */ -bool lv_roller_set_selected_str(lv_obj_t * obj, const char * sel_opt, lv_anim_enable_t anim); - /** * Get the options of a roller * @param obj pointer to roller object