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  * GLOBAL PROTOTYPES
57  **********************/
58 
59 /**
60  * Create a roller object
61  * @param parent    pointer to an object, it will be the parent of the new roller.
62  * @return          pointer to the created roller
63  */
64 lv_obj_t * lv_roller_create(lv_obj_t * parent);
65 
66 /*=====================
67  * Setter functions
68  *====================*/
69 
70 /**
71  * Set the options on a roller
72  * @param obj       pointer to roller object
73  * @param options   a string with '\n' separated options. E.g. "One\nTwo\nThree"
74  * @param mode      `LV_ROLLER_MODE_NORMAL` or `LV_ROLLER_MODE_INFINITE`
75  */
76 void lv_roller_set_options(lv_obj_t * obj, const char * options, lv_roller_mode_t mode);
77 
78 /**
79  * Set the selected option
80  * @param obj       pointer to a roller object
81  * @param sel_opt   index of the selected option (0 ... number of option - 1);
82  * @param anim_en   LV_ANIM_ON: set with animation; LV_ANOM_OFF set immediately
83  */
84 void lv_roller_set_selected(lv_obj_t * obj, uint16_t sel_opt, lv_anim_enable_t anim);
85 
86 /**
87  * Set the height to show the given number of rows (options)
88  * @param obj       pointer to a roller object
89  * @param row_cnt   number of desired visible rows
90  */
91 void lv_roller_set_visible_row_count(lv_obj_t * obj, uint8_t row_cnt);
92 
93 /*=====================
94  * Getter functions
95  *====================*/
96 
97 /**
98  * Get the index of the selected option
99  * @param obj       pointer to a roller object
100  * @return          index of the selected option (0 ... number of option - 1);
101  */
102 uint16_t lv_roller_get_selected(const lv_obj_t * obj);
103 
104 /**
105  * Get the current selected option as a string.
106  * @param obj       pointer to ddlist object
107  * @param buf       pointer to an array to store the string
108  * @param buf_size  size of `buf` in bytes. 0: to ignore it.
109  */
110 void lv_roller_get_selected_str(const lv_obj_t * obj, char * buf, uint32_t buf_size);
111 
112 /**
113  * Get the options of a roller
114  * @param obj       pointer to roller object
115  * @return          the options separated by '\n'-s (E.g. "Option1\nOption2\nOption3")
116  */
117 const char * lv_roller_get_options(const lv_obj_t * obj);
118 
119 /**
120  * Get the total number of options
121  * @param obj   pointer to a roller object
122  * @return      the total number of options
123  */
124 uint16_t lv_roller_get_option_cnt(const lv_obj_t * obj);
125 
126 /**********************
127  *      MACROS
128  **********************/
129 
130 #endif /*LV_USE_ROLLER*/
131 
132 #ifdef __cplusplus
133 } /*extern "C"*/
134 #endif
135 
136 #endif /*LV_ROLLER_H*/
137