1 /**
2  * @file lv_bar.h
3  *
4  */
5 
6 #ifndef LV_BAR_H
7 #define LV_BAR_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_BAR != 0
23 
24 #include "../lv_core/lv_obj.h"
25 #include "../lv_misc/lv_anim.h"
26 #include "lv_cont.h"
27 #include "lv_btn.h"
28 #include "lv_label.h"
29 
30 /*********************
31  *      DEFINES
32  *********************/
33 
34 /** Bar animation start value. (Not the real value of the Bar just indicates process animation)*/
35 #define LV_BAR_ANIM_STATE_START 0
36 
37 /** Bar animation end value.  (Not the real value of the Bar just indicates process animation)*/
38 #define LV_BAR_ANIM_STATE_END 256
39 
40 /** Mark no animation is in progress */
41 #define LV_BAR_ANIM_STATE_INV -1
42 
43 /** log2(LV_BAR_ANIM_STATE_END) used to normalize data*/
44 #define LV_BAR_ANIM_STATE_NORM 8
45 
46 /**********************
47  *      TYPEDEFS
48  **********************/
49 
50 /** Data of bar*/
51 typedef struct
52 {
53     /*No inherited ext, derived from the base object */
54 
55     /*New data for this type */
56     int16_t cur_value; /*Current value of the bar*/
57     int16_t min_value; /*Minimum value of the bar*/
58     int16_t max_value; /*Maximum value of the bar*/
59 #if LV_USE_ANIMATION
60     lv_anim_value_t anim_start;
61     lv_anim_value_t anim_end;
62     lv_anim_value_t anim_state;
63     lv_anim_value_t anim_time;
64 #endif
65     uint8_t sym : 1;                /*Symmetric: means the center is around zero value*/
66     const lv_style_t * style_indic; /*Style of the indicator*/
67 } lv_bar_ext_t;
68 
69 /** Bar styles. */
70 enum {
71     LV_BAR_STYLE_BG, /** Bar background style. */
72     LV_BAR_STYLE_INDIC, /** Bar fill area style. */
73 };
74 typedef uint8_t lv_bar_style_t;
75 
76 /**********************
77  * GLOBAL PROTOTYPES
78  **********************/
79 
80 /**
81  * Create a bar objects
82  * @param par pointer to an object, it will be the parent of the new bar
83  * @param copy pointer to a bar object, if not NULL then the new object will be copied from it
84  * @return pointer to the created bar
85  */
86 lv_obj_t * lv_bar_create(lv_obj_t * par, const lv_obj_t * copy);
87 
88 /*=====================
89  * Setter functions
90  *====================*/
91 
92 /**
93  * Set a new value on the bar
94  * @param bar pointer to a bar object
95  * @param value new value
96  * @param anim LV_ANIM_ON: set the value with an animation; LV_ANIM_OFF: change the value immediately
97  */
98 void lv_bar_set_value(lv_obj_t * bar, int16_t value, lv_anim_enable_t anim);
99 
100 /**
101  * Set minimum and the maximum values of a bar
102  * @param bar pointer to the bar object
103  * @param min minimum value
104  * @param max maximum value
105  */
106 void lv_bar_set_range(lv_obj_t * bar, int16_t min, int16_t max);
107 
108 /**
109  * Make the bar symmetric to zero. The indicator will grow from zero instead of the minimum
110  * position.
111  * @param bar pointer to a bar object
112  * @param en true: enable disable symmetric behavior; false: disable
113  */
114 void lv_bar_set_sym(lv_obj_t * bar, bool en);
115 
116 /**
117  * Set the animation time of the bar
118  * @param bar pointer to a bar object
119  * @param anim_time the animation time in milliseconds.
120  */
121 void lv_bar_set_anim_time(lv_obj_t * bar, uint16_t anim_time);
122 
123 /**
124  * Set a style of a bar
125  * @param bar pointer to a bar object
126  * @param type which style should be set
127  * @param style pointer to a style
128  */
129 void lv_bar_set_style(lv_obj_t * bar, lv_bar_style_t type, const lv_style_t * style);
130 
131 /*=====================
132  * Getter functions
133  *====================*/
134 
135 /**
136  * Get the value of a bar
137  * @param bar pointer to a bar object
138  * @return the value of the bar
139  */
140 int16_t lv_bar_get_value(const lv_obj_t * bar);
141 
142 /**
143  * Get the minimum value of a bar
144  * @param bar pointer to a bar object
145  * @return the minimum value of the bar
146  */
147 int16_t lv_bar_get_min_value(const lv_obj_t * bar);
148 
149 /**
150  * Get the maximum value of a bar
151  * @param bar pointer to a bar object
152  * @return the maximum value of the bar
153  */
154 int16_t lv_bar_get_max_value(const lv_obj_t * bar);
155 
156 /**
157  * Get whether the bar is symmetric or not.
158  * @param bar pointer to a bar object
159  * @return true: symmetric is enabled; false: disable
160  */
161 bool lv_bar_get_sym(lv_obj_t * bar);
162 
163 /**
164  * Get the animation time of the bar
165  * @param bar pointer to a bar object
166  * @return the animation time in milliseconds.
167  */
168 uint16_t lv_bar_get_anim_time(lv_obj_t * bar);
169 
170 /**
171  * Get a style of a bar
172  * @param bar pointer to a bar object
173  * @param type which style should be get
174  * @return style pointer to a style
175  */
176 const lv_style_t * lv_bar_get_style(const lv_obj_t * bar, lv_bar_style_t type);
177 
178 /**********************
179  *      MACROS
180  **********************/
181 
182 #endif /*LV_USE_BAR*/
183 
184 #ifdef __cplusplus
185 } /* extern "C" */
186 #endif
187 
188 #endif /*LV_BAR_H*/
189