diff --git a/src/lv_objx/lv_ddlist.c b/src/lv_objx/lv_ddlist.c index 8b67ec876..46c8936e0 100644 --- a/src/lv_objx/lv_ddlist.c +++ b/src/lv_objx/lv_ddlist.c @@ -375,6 +375,20 @@ uint16_t lv_ddlist_get_selected(const lv_obj_t * ddlist) return ext->sel_opt_id; } +/** + * Get the total number of options + * @param ddlist pointer to drop down list object + * @return the total number of options in the list + */ +uint16_t lv_ddlist_get_option_cnt(const lv_obj_t * ddlist) +{ + LV_ASSERT_OBJ(ddlist, LV_OBJX_NAME); + + lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); + + return ext->option_cnt; +} + /** * Get the current selected option as a string * @param ddlist pointer to ddlist object diff --git a/src/lv_objx/lv_ddlist.h b/src/lv_objx/lv_ddlist.h index 774b52cef..e4d918b17 100644 --- a/src/lv_objx/lv_ddlist.h +++ b/src/lv_objx/lv_ddlist.h @@ -176,6 +176,13 @@ const char * lv_ddlist_get_options(const lv_obj_t * ddlist); */ uint16_t lv_ddlist_get_selected(const lv_obj_t * ddlist); +/** + * Get the total number of options + * @param ddlist pointer to drop down list object + * @return the total number of options in the list + */ +uint16_t lv_ddlist_get_option_cnt(const lv_obj_t * ddlist); + /** * Get the current selected option as a string * @param ddlist pointer to ddlist object diff --git a/src/lv_objx/lv_roller.c b/src/lv_objx/lv_roller.c index 6038dacbe..6b1d33e36 100644 --- a/src/lv_objx/lv_roller.c +++ b/src/lv_objx/lv_roller.c @@ -276,6 +276,24 @@ uint16_t lv_roller_get_selected(const lv_obj_t * roller) } } +/** + * Get the total number of options + * @param roller pointer to a roller object + * @return the total number of options + */ +uint16_t lv_roller_get_option_cnt(const lv_obj_t * roller) +{ + LV_ASSERT_OBJ(roller, LV_OBJX_NAME); + + lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller); + if(ext->mode == LV_ROLLER_MODE_INIFINITE) { + uint16_t real_id_cnt = ext->ddlist.option_cnt / LV_ROLLER_INF_PAGES; + return real_id_cnt; + } else { + return ext->ddlist.option_cnt; + } +} + /** * Get the align attribute. Default alignment after _create is LV_LABEL_ALIGN_CENTER * @param roller pointer to a roller object diff --git a/src/lv_objx/lv_roller.h b/src/lv_objx/lv_roller.h index 5303c3aa1..6375d34c1 100644 --- a/src/lv_objx/lv_roller.h +++ b/src/lv_objx/lv_roller.h @@ -146,6 +146,13 @@ void lv_roller_set_style(lv_obj_t * roller, lv_roller_style_t type, const lv_sty */ uint16_t lv_roller_get_selected(const lv_obj_t * roller); +/** + * Get the total number of options + * @param roller pointer to a roller object + * @return the total number of options in the list + */ +uint16_t lv_roller_get_option_cnt(const lv_obj_t * roller); + /** * Get the current selected option as a string * @param roller pointer to roller object