mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-14 06:42:58 +08:00
fix(roller): Adjust the position of the lv_roller_set_str function in lv_roller. c and lv_roller. h (#7506)
This commit is contained in:
parent
517b307ae3
commit
bd39f984b8
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user