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 #ifdef LV_CONF_INCLUDE_SIMPLE
17 #include "lv_conf.h"
18 #else
19 #include "../../lv_conf.h"
20 #endif
21
22 #if LV_USE_SLIDER != 0
23
24 /*Testing of dependencies*/
25 #if LV_USE_BAR == 0
26 #error "lv_slider: lv_bar is required. Enable it in lv_conf.h (LV_USE_BAR 1) "
27 #endif
28
29 #include "../lv_core/lv_obj.h"
30 #include "lv_bar.h"
31
32 /*********************
33 * DEFINES
34 *********************/
35
36 /**********************
37 * TYPEDEFS
38 **********************/
39 /*Data of slider*/
40 typedef struct
41 {
42 lv_bar_ext_t bar; /*Ext. of ancestor*/
43 /*New data for this type */
44 const lv_style_t * style_knob; /*Style of the knob*/
45 int16_t drag_value; /*Store a temporal value during press until release (Handled by the library)*/
46 uint8_t knob_in : 1; /*1: Draw the knob inside the bar*/
47 } lv_slider_ext_t;
48
49 /** Built-in styles of slider*/
50 enum {
51 LV_SLIDER_STYLE_BG, /** Slider background style. */
52 LV_SLIDER_STYLE_INDIC, /** Slider indicator (filled area) style. */
53 LV_SLIDER_STYLE_KNOB, /** Slider knob style. */
54 };
55 typedef uint8_t lv_slider_style_t;
56
57 /**********************
58 * GLOBAL PROTOTYPES
59 **********************/
60
61 /**
62 * Create a slider objects
63 * @param par pointer to an object, it will be the parent of the new slider
64 * @param copy pointer to a slider object, if not NULL then the new object will be copied from it
65 * @return pointer to the created slider
66 */
67 lv_obj_t * lv_slider_create(lv_obj_t * par, const lv_obj_t * copy);
68
69 /*=====================
70 * Setter functions
71 *====================*/
72
73 /**
74 * Set a new value on the slider
75 * @param slider pointer to a slider object
76 * @param value new value
77 * @param anim LV_ANIM_ON: set the value with an animation; LV_ANIM_OFF: change the value immediately
78 */
lv_slider_set_value(lv_obj_t * slider,int16_t value,lv_anim_enable_t anim)79 static inline void lv_slider_set_value(lv_obj_t * slider, int16_t value, lv_anim_enable_t anim)
80 {
81 lv_bar_set_value(slider, value, anim);
82 }
83
84 /**
85 * Set minimum and the maximum values of a bar
86 * @param slider pointer to the slider object
87 * @param min minimum value
88 * @param max maximum value
89 */
lv_slider_set_range(lv_obj_t * slider,int16_t min,int16_t max)90 static inline void lv_slider_set_range(lv_obj_t * slider, int16_t min, int16_t max)
91 {
92 lv_bar_set_range(slider, min, max);
93 }
94
95 /**
96 * Set the animation time of the slider
97 * @param slider pointer to a bar object
98 * @param anim_time the animation time in milliseconds.
99 */
lv_slider_set_anim_time(lv_obj_t * slider,uint16_t anim_time)100 static inline void lv_slider_set_anim_time(lv_obj_t * slider, uint16_t anim_time)
101 {
102 lv_bar_set_anim_time(slider, anim_time);
103 }
104
105 /**
106 * Set the 'knob in' attribute of a slider
107 * @param slider pointer to slider object
108 * @param in true: the knob is drawn always in the slider;
109 * false: the knob can be out on the edges
110 */
111 void lv_slider_set_knob_in(lv_obj_t * slider, bool in);
112
113 /**
114 * Set a style of a slider
115 * @param slider pointer to a slider object
116 * @param type which style should be set
117 * @param style pointer to a style
118 */
119 void lv_slider_set_style(lv_obj_t * slider, lv_slider_style_t type, const lv_style_t * style);
120
121 /*=====================
122 * Getter functions
123 *====================*/
124
125 /**
126 * Get the value of a slider
127 * @param slider pointer to a slider object
128 * @return the value of the slider
129 */
130 int16_t lv_slider_get_value(const lv_obj_t * slider);
131
132 /**
133 * Get the minimum value of a slider
134 * @param slider pointer to a slider object
135 * @return the minimum value of the slider
136 */
lv_slider_get_min_value(const lv_obj_t * slider)137 static inline int16_t lv_slider_get_min_value(const lv_obj_t * slider)
138 {
139 return lv_bar_get_min_value(slider);
140 }
141
142 /**
143 * Get the maximum value of a slider
144 * @param slider pointer to a slider object
145 * @return the maximum value of the slider
146 */
lv_slider_get_max_value(const lv_obj_t * slider)147 static inline int16_t lv_slider_get_max_value(const lv_obj_t * slider)
148 {
149 return lv_bar_get_max_value(slider);
150 }
151
152 /**
153 * Give the slider is being dragged or not
154 * @param slider pointer to a slider object
155 * @return true: drag in progress false: not dragged
156 */
157 bool lv_slider_is_dragged(const lv_obj_t * slider);
158
159 /**
160 * Get the 'knob in' attribute of a slider
161 * @param slider pointer to slider object
162 * @return true: the knob is drawn always in the slider;
163 * false: the knob can be out on the edges
164 */
165 bool lv_slider_get_knob_in(const lv_obj_t * slider);
166
167 /**
168 * Get a style of a slider
169 * @param slider pointer to a slider object
170 * @param type which style should be get
171 * @return style pointer to a style
172 */
173 const lv_style_t * lv_slider_get_style(const lv_obj_t * slider, lv_slider_style_t type);
174
175 /**********************
176 * MACROS
177 **********************/
178
179 #endif /*LV_USE_SLIDER*/
180
181 #ifdef __cplusplus
182 } /* extern "C" */
183 #endif
184
185 #endif /*LV_SLIDER_H*/
186