1 /** 2 * @file lv_roller.h 3 * 4 */ 5 6 #ifndef LV_ROLLER_H 7 #define LV_ROLLER_H 8 9 #ifdef __cplusplus 10 extern "C" { 11 #endif 12 13 /********************* 14 * INCLUDES 15 *********************/ 16 #include "../lv_conf_internal.h" 17 18 #if LV_USE_ROLLER != 0 19 20 /*Testing of dependencies*/ 21 #if LV_USE_LABEL == 0 22 #error "lv_roller: lv_label is required. Enable it in lv_conf.h (LV_USE_ROLLER 1)" 23 #endif 24 25 #include "../core/lv_obj.h" 26 #include "lv_label.h" 27 28 /********************* 29 * DEFINES 30 *********************/ 31 32 /********************** 33 * TYPEDEFS 34 **********************/ 35 36 /** Roller mode.*/ 37 enum { 38 LV_ROLLER_MODE_NORMAL, /**< Normal mode (roller ends at the end of the options).*/ 39 LV_ROLLER_MODE_INFINITE, /**< Infinite mode (roller can be scrolled forever).*/ 40 }; 41 42 typedef uint8_t lv_roller_mode_t; 43 44 typedef struct { 45 lv_obj_t obj; 46 uint16_t option_cnt; /**< Number of options*/ 47 uint16_t sel_opt_id; /**< Index of the current option*/ 48 uint16_t sel_opt_id_ori; /**< Store the original index on focus*/ 49 lv_roller_mode_t mode : 1; 50 uint32_t moved : 1; 51 } lv_roller_t; 52 53 extern const lv_obj_class_t lv_roller_class; 54 55 56 /********************** 57 * GLOBAL PROTOTYPES 58 **********************/ 59 60 /** 61 * Create a roller object 62 * @param parent pointer to an object, it will be the parent of the new roller. 63 * @return pointer to the created roller 64 */ 65 lv_obj_t * lv_roller_create(lv_obj_t * parent); 66 67 /*===================== 68 * Setter functions 69 *====================*/ 70 71 /** 72 * Set the options on a roller 73 * @param obj pointer to roller object 74 * @param options a string with '\n' separated options. E.g. "One\nTwo\nThree" 75 * @param mode `LV_ROLLER_MODE_NORMAL` or `LV_ROLLER_MODE_INFINITE` 76 */ 77 void lv_roller_set_options(lv_obj_t * obj, const char * options, lv_roller_mode_t mode); 78 79 /** 80 * Set the selected option 81 * @param obj pointer to a roller object 82 * @param sel_opt index of the selected option (0 ... number of option - 1); 83 * @param anim_en LV_ANIM_ON: set with animation; LV_ANOM_OFF set immediately 84 */ 85 void lv_roller_set_selected(lv_obj_t * obj, uint16_t sel_opt, lv_anim_enable_t anim); 86 87 /** 88 * Set the height to show the given number of rows (options) 89 * @param obj pointer to a roller object 90 * @param row_cnt number of desired visible rows 91 */ 92 void lv_roller_set_visible_row_count(lv_obj_t * obj, uint8_t row_cnt); 93 94 /*===================== 95 * Getter functions 96 *====================*/ 97 98 /** 99 * Get the index of the selected option 100 * @param obj pointer to a roller object 101 * @return index of the selected option (0 ... number of option - 1); 102 */ 103 uint16_t lv_roller_get_selected(const lv_obj_t * obj); 104 105 /** 106 * Get the current selected option as a string. 107 * @param obj pointer to ddlist object 108 * @param buf pointer to an array to store the string 109 * @param buf_size size of `buf` in bytes. 0: to ignore it. 110 */ 111 void lv_roller_get_selected_str(const lv_obj_t * obj, char * buf, uint32_t buf_size); 112 113 114 /** 115 * Get the options of a roller 116 * @param obj pointer to roller object 117 * @return the options separated by '\n'-s (E.g. "Option1\nOption2\nOption3") 118 */ 119 const char * lv_roller_get_options(const lv_obj_t * obj); 120 121 /** 122 * Get the total number of options 123 * @param obj pointer to a roller object 124 * @return the total number of options 125 */ 126 uint16_t lv_roller_get_option_cnt(const lv_obj_t * obj); 127 128 /********************** 129 * MACROS 130 **********************/ 131 132 #endif /*LV_USE_ROLLER*/ 133 134 #ifdef __cplusplus 135 } /*extern "C"*/ 136 #endif 137 138 #endif /*LV_ROLLER_H*/ 139