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_PAGE == 0
22 #error "lv_roller: lv_page is required. Enable it in lv_conf.h (LV_USE_PAGE 1) "
23 #endif
24 
25 #include "../lv_core/lv_obj.h"
26 #include "lv_page.h"
27 #include "lv_label.h"
28 
29 /*********************
30  *      DEFINES
31  *********************/
32 
33 /**********************
34  *      TYPEDEFS
35  **********************/
36 
37 /** Roller mode. */
38 enum {
39     LV_ROLLER_MODE_NORMAL, /**< Normal mode (roller ends at the end of the options). */
40     LV_ROLLER_MODE_INIFINITE, /**< Infinite mode (roller can be scrolled forever). */
41 };
42 
43 typedef uint8_t lv_roller_mode_t;
44 
45 
46 
47 /*Data of roller*/
48 typedef struct {
49     lv_page_ext_t page; /*Ext. of ancestor*/
50 
51     /*New data for this type */
52     lv_style_list_t style_sel; /*Style of the selected option*/
53     uint16_t option_cnt;          /*Number of options*/
54     uint16_t sel_opt_id;          /*Index of the current option*/
55     uint16_t sel_opt_id_ori;      /*Store the original index on focus*/
56     lv_roller_mode_t mode : 1;
57     uint8_t auto_fit : 1;         /*1: Automatically set the width*/
58 } lv_roller_ext_t;
59 
60 enum {
61     LV_ROLLER_PART_BG = LV_PAGE_PART_BG,
62     LV_ROLLER_PART_SELECTED = _LV_PAGE_PART_VIRTUAL_LAST,
63     _LV_ROLLER_PART_VIRTUAL_LAST,
64 };
65 typedef uint8_t lv_roller_part_t;
66 
67 /**********************
68  * GLOBAL PROTOTYPES
69  **********************/
70 
71 /**
72  * Create a roller object
73  * @param par pointer to an object, it will be the parent of the new roller
74  * @param copy pointer to a roller object, if not NULL then the new object will be copied from it
75  * @return pointer to the created roller
76  */
77 lv_obj_t * lv_roller_create(lv_obj_t * par, const lv_obj_t * copy);
78 
79 /*=====================
80  * Setter functions
81  *====================*/
82 
83 /**
84  * Set the options on a roller
85  * @param roller pointer to roller object
86  * @param options a string with '\n' separated options. E.g. "One\nTwo\nThree"
87  * @param mode `LV_ROLLER_MODE_NORMAL` or `LV_ROLLER_MODE_INFINITE`
88  */
89 void lv_roller_set_options(lv_obj_t * roller, const char * options, lv_roller_mode_t mode);
90 
91 /**
92  * Set the align of the roller's options (left, right or center[default])
93  * @param roller - pointer to a roller object
94  * @param align - one of lv_label_align_t values (left, right, center)
95  */
96 void lv_roller_set_align(lv_obj_t * roller, lv_label_align_t align);
97 
98 /**
99  * Set the selected option
100  * @param roller pointer to a roller object
101  * @param sel_opt id of the selected option (0 ... number of option - 1);
102  * @param anim LV_ANOM_ON: set with animation; LV_ANIM_OFF set immediately
103  */
104 void lv_roller_set_selected(lv_obj_t * roller, uint16_t sel_opt, lv_anim_enable_t anim);
105 
106 /**
107  * Set the height to show the given number of rows (options)
108  * @param roller pointer to a roller object
109  * @param row_cnt number of desired visible rows
110  */
111 void lv_roller_set_visible_row_count(lv_obj_t * roller, uint8_t row_cnt);
112 
113 /**
114  * Allow automatically setting the width of roller according to it's content.
115  * @param roller pointer to a roller object
116  * @param auto_fit true: enable auto fit
117  */
118 void lv_roller_set_auto_fit(lv_obj_t * roller, bool auto_fit);
119 
120 /**
121  * Set the open/close animation time.
122  * @param roller pointer to a roller object
123  * @param anim_time: open/close animation time [ms]
124  */
lv_roller_set_anim_time(lv_obj_t * roller,uint16_t anim_time)125 static inline void lv_roller_set_anim_time(lv_obj_t * roller, uint16_t anim_time)
126 {
127     lv_page_set_anim_time(roller, anim_time);
128 }
129 
130 /*=====================
131  * Getter functions
132  *====================*/
133 /**
134  * Get the id of the selected option
135  * @param roller pointer to a roller object
136  * @return id of the selected option (0 ... number of option - 1);
137  */
138 uint16_t lv_roller_get_selected(const lv_obj_t * roller);
139 
140 /**
141  * Get the total number of options
142  * @param roller pointer to a roller object
143  * @return the total number of options in the list
144  */
145 uint16_t lv_roller_get_option_cnt(const lv_obj_t * roller);
146 
147 /**
148  * Get the current selected option as a string
149  * @param roller pointer to roller object
150  * @param buf pointer to an array to store the string
151  * @param buf_size size of `buf` in bytes. 0: to ignore it.
152  */
153 void lv_roller_get_selected_str(const lv_obj_t * roller, char * buf, uint32_t buf_size);
154 
155 /**
156  * Get the align attribute. Default alignment after _create is LV_LABEL_ALIGN_CENTER
157  * @param roller pointer to a roller object
158  * @return LV_LABEL_ALIGN_LEFT, LV_LABEL_ALIGN_RIGHT or LV_LABEL_ALIGN_CENTER
159  */
160 lv_label_align_t lv_roller_get_align(const lv_obj_t * roller);
161 
162 /**
163  * Get whether the auto fit option is enabled or not.
164  * @param roller pointer to a roller object
165  * @return true: auto fit is enabled
166  */
167 bool lv_roller_get_auto_fit(lv_obj_t * roller);
168 
169 /**
170  * Get the options of a roller
171  * @param roller pointer to roller object
172  * @return the options separated by '\n'-s (E.g. "Option1\nOption2\nOption3")
173  */
174 const char * lv_roller_get_options(const lv_obj_t * roller);
175 
176 /**
177  * Get the open/close animation time.
178  * @param roller pointer to a roller
179  * @return open/close animation time [ms]
180  */
lv_roller_get_anim_time(const lv_obj_t * roller)181 static inline uint16_t lv_roller_get_anim_time(const lv_obj_t * roller)
182 {
183     return lv_page_get_anim_time(roller);
184 }
185 
186 
187 /**********************
188  *      MACROS
189  **********************/
190 
191 #endif /*LV_USE_ROLLER*/
192 
193 #ifdef __cplusplus
194 } /* extern "C" */
195 #endif
196 
197 #endif /*LV_ROLLER_H*/
198