1 /**
2  * @file lv_slider.h
3  *
4  */
5 
6 #ifndef LV_SLIDER_H
7 #define LV_SLIDER_H
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 /*********************
14  *      INCLUDES
15  *********************/
16 #include "../bar/lv_bar.h"
17 
18 #if LV_USE_SLIDER != 0
19 
20 /*Testing of dependencies*/
21 #if LV_USE_BAR == 0
22 #error "lv_slider: lv_bar is required. Enable it in lv_conf.h (LV_USE_BAR 1)"
23 #endif
24 
25 /*********************
26  *      DEFINES
27  *********************/
28 
29 /**********************
30  *      TYPEDEFS
31  **********************/
32 typedef enum {
33     LV_SLIDER_MODE_NORMAL = LV_BAR_MODE_NORMAL,
34     LV_SLIDER_MODE_SYMMETRICAL = LV_BAR_MODE_SYMMETRICAL,
35     LV_SLIDER_MODE_RANGE = LV_BAR_MODE_RANGE
36 } lv_slider_mode_t;
37 
38 typedef enum {
39     LV_SLIDER_ORIENTATION_AUTO = LV_BAR_ORIENTATION_AUTO,
40     LV_SLIDER_ORIENTATION_HORIZONTAL = LV_BAR_ORIENTATION_HORIZONTAL,
41     LV_SLIDER_ORIENTATION_VERTICAL = LV_BAR_ORIENTATION_VERTICAL
42 } lv_slider_orientation_t;
43 
44 LV_ATTRIBUTE_EXTERN_DATA extern const lv_obj_class_t lv_slider_class;
45 
46 #if LV_USE_OBJ_PROPERTY
47 enum {
48     LV_PROPERTY_ID2(SLIDER, VALUE,          LV_PROPERTY_TYPE_INT,   LV_PROPERTY_TYPE_BOOL,  0),
49     LV_PROPERTY_ID2(SLIDER, LEFT_VALUE,     LV_PROPERTY_TYPE_INT,   LV_PROPERTY_TYPE_BOOL,  1),
50     LV_PROPERTY_ID2(SLIDER, RANGE,          LV_PROPERTY_TYPE_INT,   LV_PROPERTY_TYPE_INT,   2),
51     LV_PROPERTY_ID(SLIDER, MIN_VALUE,       LV_PROPERTY_TYPE_INT,       4),
52     LV_PROPERTY_ID(SLIDER, MAX_VALUE,       LV_PROPERTY_TYPE_INT,       5),
53     LV_PROPERTY_ID(SLIDER, MODE,            LV_PROPERTY_TYPE_INT,       6),
54     LV_PROPERTY_ID(SLIDER, IS_DRAGGED,      LV_PROPERTY_TYPE_BOOL,      7),
55     LV_PROPERTY_ID(SLIDER, IS_SYMMETRICAL,  LV_PROPERTY_TYPE_BOOL,      8),
56     LV_PROPERTY_SLIDER_END,
57 };
58 #endif
59 /**********************
60  * GLOBAL PROTOTYPES
61  **********************/
62 
63 /**
64  * Create a slider object
65  * @param parent    pointer to an object, it will be the parent of the new slider.
66  * @return          pointer to the created slider
67  */
68 lv_obj_t * lv_slider_create(lv_obj_t * parent);
69 
70 /*=====================
71  * Setter functions
72  *====================*/
73 
74 /**
75  * Set a new value on the slider
76  * @param obj       pointer to a slider object
77  * @param value     the new value
78  * @param anim      LV_ANIM_ON: set the value with an animation; LV_ANIM_OFF: change the value immediately
79  */
80 void lv_slider_set_value(lv_obj_t * obj, int32_t value, lv_anim_enable_t anim);
81 
82 /**
83  * Set a new value for the left knob of a slider
84  * @param obj       pointer to a slider object
85  * @param value     new value
86  * @param anim      LV_ANIM_ON: set the value with an animation; LV_ANIM_OFF: change the value immediately
87  */
88 void lv_slider_set_left_value(lv_obj_t * obj, int32_t value, lv_anim_enable_t anim);
89 
90 /**
91  * Set minimum and the maximum values of a bar
92  * @param obj       pointer to the slider object
93  * @param min       minimum value
94  * @param max       maximum value
95  */
96 void lv_slider_set_range(lv_obj_t * obj, int32_t min, int32_t max);
97 
98 /**
99  * Set the mode of slider.
100  * @param obj       pointer to a slider object
101  * @param mode      the mode of the slider. See `lv_slider_mode_t`
102  */
103 void lv_slider_set_mode(lv_obj_t * obj, lv_slider_mode_t mode);
104 
105 /**
106  * Set the orientation of slider.
107  * @param obj           pointer to a slider object
108  * @param orientation   slider  orientation from `lv_slider_orientation_t`
109  */
110 void lv_slider_set_orientation(lv_obj_t * obj, lv_slider_orientation_t orientation);
111 
112 /*=====================
113  * Getter functions
114  *====================*/
115 
116 /**
117  * Get the value of the main knob of a slider
118  * @param obj       pointer to a slider object
119  * @return          the value of the main knob of the slider
120  */
121 int32_t lv_slider_get_value(const lv_obj_t * obj);
122 
123 /**
124  * Get the value of the left knob of a slider
125  * @param obj       pointer to a slider object
126  * @return          the value of the left knob of the slider
127  */
128 int32_t lv_slider_get_left_value(const lv_obj_t * obj);
129 
130 /**
131  * Get the minimum value of a slider
132  * @param obj       pointer to a slider object
133  * @return          the minimum value of the slider
134  */
135 int32_t lv_slider_get_min_value(const lv_obj_t * obj);
136 
137 /**
138  * Get the maximum value of a slider
139  * @param obj       pointer to a slider object
140  * @return          the maximum value of the slider
141  */
142 int32_t lv_slider_get_max_value(const lv_obj_t * obj);
143 
144 /**
145  * Give the slider is being dragged or not
146  * @param obj       pointer to a slider object
147  * @return          true: drag in progress false: not dragged
148  */
149 bool lv_slider_is_dragged(const lv_obj_t * obj);
150 
151 /**
152  * Get the mode of the slider.
153  * @param slider       pointer to a slider object
154  * @return          see `lv_slider_mode_t`
155  */
156 lv_slider_mode_t lv_slider_get_mode(lv_obj_t * slider);
157 
158 /**
159  * Get the orientation of slider.
160  * @param obj       pointer to a slider object
161  * @return          slider orientation from `lv_slider_orientation_t`
162  */
163 lv_slider_orientation_t lv_slider_get_orientation(lv_obj_t * slider);
164 
165 /**
166  * Give the slider is in symmetrical mode or not
167  * @param obj       pointer to slider object
168  * @return          true: in symmetrical mode false : not in
169 */
170 bool lv_slider_is_symmetrical(lv_obj_t * obj);
171 
172 /**********************
173  *      MACROS
174  **********************/
175 
176 #endif /*LV_USE_SLIDER*/
177 
178 #ifdef __cplusplus
179 } /*extern "C"*/
180 #endif
181 
182 #endif /*LV_SLIDER_H*/
183