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 "../../core/lv_obj.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 "../label/lv_label.h"
26 
27 /*********************
28  *      DEFINES
29  *********************/
30 
31 /**********************
32  *      TYPEDEFS
33  **********************/
34 
35 /** Roller mode. */
36 typedef enum {
37     LV_ROLLER_MODE_NORMAL,   /**< Normal mode (roller ends at the end of the options). */
38     LV_ROLLER_MODE_INFINITE, /**< Infinite mode (roller can be scrolled forever). */
39 } lv_roller_mode_t;
40 
41 #if LV_USE_OBJ_PROPERTY
42 enum {
43     LV_PROPERTY_ID2(ROLLER, OPTIONS,            LV_PROPERTY_TYPE_TEXT,  LV_PROPERTY_TYPE_INT,   0),
44     LV_PROPERTY_ID2(ROLLER, SELECTED,           LV_PROPERTY_TYPE_INT,   LV_PROPERTY_TYPE_INT, 1),
45     LV_PROPERTY_ID(ROLLER, VISIBLE_ROW_COUNT,   LV_PROPERTY_TYPE_INT,   2),
46     LV_PROPERTY_ROLLER_END,
47 };
48 #endif
49 
50 LV_ATTRIBUTE_EXTERN_DATA extern const lv_obj_class_t lv_roller_class;
51 
52 /**********************
53  * GLOBAL PROTOTYPES
54  **********************/
55 
56 /**
57  * Create a roller object
58  * @param parent    pointer to an object, it will be the parent of the new roller.
59  * @return          pointer to the created roller
60  */
61 lv_obj_t * lv_roller_create(lv_obj_t * parent);
62 
63 /*=====================
64  * Setter functions
65  *====================*/
66 
67 /**
68  * Set the options on a roller
69  * @param obj       pointer to roller object
70  * @param options   a string with '\n' separated options. E.g. "One\nTwo\nThree"
71  * @param mode      `LV_ROLLER_MODE_NORMAL` or `LV_ROLLER_MODE_INFINITE`
72  */
73 void lv_roller_set_options(lv_obj_t * obj, const char * options, lv_roller_mode_t mode);
74 
75 /**
76  * Set the selected option
77  * @param obj       pointer to a roller object
78  * @param sel_opt   index of the selected option (0 ... number of option - 1);
79  * @param anim   LV_ANIM_ON: set with animation; LV_ANOM_OFF set immediately
80  */
81 void lv_roller_set_selected(lv_obj_t * obj, uint32_t sel_opt, lv_anim_enable_t anim);
82 
83 /**
84  * Sets the given string as the selection on the roller. Does not alter the current selection on failure.
85  * @param obj               pointer to roller object
86  * @param sel_opt   pointer to the string you want to set as an option
87  * @param anim          LV_ANIM_ON: set with animation; LV_ANOM_OFF set immediately
88  * @return                  `true` if set successfully and `false` if the given string does not exist as an option in the roller
89  */
90 bool lv_roller_set_selected_str(lv_obj_t * obj, const char * sel_opt, lv_anim_enable_t anim);
91 
92 /**
93  * Set the height to show the given number of rows (options)
94  * @param obj       pointer to a roller object
95  * @param row_cnt   number of desired visible rows
96  */
97 void lv_roller_set_visible_row_count(lv_obj_t * obj, uint32_t row_cnt);
98 
99 /*=====================
100  * Getter functions
101  *====================*/
102 
103 /**
104  * Get the index of the selected option
105  * @param obj       pointer to a roller object
106  * @return          index of the selected option (0 ... number of option - 1);
107  */
108 uint32_t lv_roller_get_selected(const lv_obj_t * obj);
109 
110 /**
111  * Get the current selected option as a string.
112  * @param obj       pointer to roller object
113  * @param buf       pointer to an array to store the string
114  * @param buf_size  size of `buf` in bytes. 0: to ignore it.
115  */
116 void lv_roller_get_selected_str(const lv_obj_t * obj, char * buf, uint32_t buf_size);
117 
118 /**
119  * Get the options of a roller
120  * @param obj       pointer to roller object
121  * @return          the options separated by '\n'-s (E.g. "Option1\nOption2\nOption3")
122  */
123 const char * lv_roller_get_options(const lv_obj_t * obj);
124 
125 /**
126  * Get the total number of options
127  * @param obj   pointer to a roller object
128  * @return      the total number of options
129  */
130 uint32_t lv_roller_get_option_count(const lv_obj_t * obj);
131 
132 /**********************
133  *      MACROS
134  **********************/
135 
136 #endif /*LV_USE_ROLLER*/
137 
138 #ifdef __cplusplus
139 } /*extern "C"*/
140 #endif
141 
142 #endif /*LV_ROLLER_H*/
143