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 #include "../lv_conf_internal.h" 17 18 #if LV_USE_BAR != 0 19 20 #include "../lv_core/lv_obj.h" 21 #include "../lv_misc/lv_anim.h" 22 #include "lv_cont.h" 23 #include "lv_btn.h" 24 #include "lv_label.h" 25 26 /********************* 27 * DEFINES 28 *********************/ 29 30 /** Bar animation start value. (Not the real value of the Bar just indicates process animation)*/ 31 #define LV_BAR_ANIM_STATE_START 0 32 33 /** Bar animation end value. (Not the real value of the Bar just indicates process animation)*/ 34 #define LV_BAR_ANIM_STATE_END 256 35 36 /** Mark no animation is in progress */ 37 #define LV_BAR_ANIM_STATE_INV -1 38 39 /** log2(LV_BAR_ANIM_STATE_END) used to normalize data*/ 40 #define LV_BAR_ANIM_STATE_NORM 8 41 42 /********************** 43 * TYPEDEFS 44 **********************/ 45 46 enum { 47 LV_BAR_TYPE_NORMAL, 48 LV_BAR_TYPE_SYMMETRICAL, 49 LV_BAR_TYPE_CUSTOM 50 }; 51 typedef uint8_t lv_bar_type_t; 52 53 #if LV_USE_ANIMATION 54 typedef struct { 55 lv_obj_t * bar; 56 lv_anim_value_t anim_start; 57 lv_anim_value_t anim_end; 58 lv_anim_value_t anim_state; 59 } lv_bar_anim_t; 60 #endif 61 62 /** Data of bar*/ 63 typedef struct { 64 /*No inherited ext, derived from the base object */ 65 66 /*New data for this type */ 67 int16_t cur_value; /*Current value of the bar*/ 68 int16_t min_value; /*Minimum value of the bar*/ 69 int16_t max_value; /*Maximum value of the bar*/ 70 int16_t start_value; /*Start value of the bar*/ 71 lv_area_t indic_area; /*Save the indicator area. MIght be used by derived types*/ 72 #if LV_USE_ANIMATION 73 lv_anim_value_t anim_time; 74 lv_bar_anim_t cur_value_anim; 75 lv_bar_anim_t start_value_anim; 76 #endif 77 uint8_t type : 2; /*Type of bar*/ 78 lv_style_list_t style_indic; /*Style of the indicator*/ 79 } lv_bar_ext_t; 80 81 /** Bar parts */ 82 enum { 83 LV_BAR_PART_BG, /** Bar background style. */ 84 LV_BAR_PART_INDIC, /** Bar fill area style. */ 85 _LV_BAR_PART_VIRTUAL_LAST 86 }; 87 typedef uint8_t lv_bar_part_t; 88 89 /********************** 90 * GLOBAL PROTOTYPES 91 **********************/ 92 93 /** 94 * Create a bar objects 95 * @param par pointer to an object, it will be the parent of the new bar 96 * @param copy pointer to a bar object, if not NULL then the new object will be copied from it 97 * @return pointer to the created bar 98 */ 99 lv_obj_t * lv_bar_create(lv_obj_t * par, const lv_obj_t * copy); 100 101 /*===================== 102 * Setter functions 103 *====================*/ 104 105 /** 106 * Set a new value on the bar 107 * @param bar pointer to a bar object 108 * @param value new value 109 * @param anim LV_ANIM_ON: set the value with an animation; LV_ANIM_OFF: change the value immediately 110 */ 111 void lv_bar_set_value(lv_obj_t * bar, int16_t value, lv_anim_enable_t anim); 112 113 /** 114 * Set a new start value on the bar 115 * @param bar pointer to a bar object 116 * @param value new start value 117 * @param anim LV_ANIM_ON: set the value with an animation; LV_ANIM_OFF: change the value immediately 118 */ 119 void lv_bar_set_start_value(lv_obj_t * bar, int16_t start_value, lv_anim_enable_t anim); 120 121 /** 122 * Set minimum and the maximum values of a bar 123 * @param bar pointer to the bar object 124 * @param min minimum value 125 * @param max maximum value 126 */ 127 void lv_bar_set_range(lv_obj_t * bar, int16_t min, int16_t max); 128 129 /** 130 * Set the type of bar. 131 * @param bar pointer to bar object 132 * @param type bar type 133 */ 134 void lv_bar_set_type(lv_obj_t * bar, lv_bar_type_t type); 135 136 /** 137 * Set the animation time of the bar 138 * @param bar pointer to a bar object 139 * @param anim_time the animation time in milliseconds. 140 */ 141 void lv_bar_set_anim_time(lv_obj_t * bar, uint16_t anim_time); 142 143 /*===================== 144 * Getter functions 145 *====================*/ 146 147 /** 148 * Get the value of a bar 149 * @param bar pointer to a bar object 150 * @return the value of the bar 151 */ 152 int16_t lv_bar_get_value(const lv_obj_t * bar); 153 154 /** 155 * Get the start value of a bar 156 * @param bar pointer to a bar object 157 * @return the start value of the bar 158 */ 159 int16_t lv_bar_get_start_value(const lv_obj_t * bar); 160 161 /** 162 * Get the minimum value of a bar 163 * @param bar pointer to a bar object 164 * @return the minimum value of the bar 165 */ 166 int16_t lv_bar_get_min_value(const lv_obj_t * bar); 167 168 /** 169 * Get the maximum value of a bar 170 * @param bar pointer to a bar object 171 * @return the maximum value of the bar 172 */ 173 int16_t lv_bar_get_max_value(const lv_obj_t * bar); 174 175 /** 176 * Get the type of bar. 177 * @param bar pointer to bar object 178 * @return bar type 179 */ 180 lv_bar_type_t lv_bar_get_type(lv_obj_t * bar); 181 182 /** 183 * Get the animation time of the bar 184 * @param bar pointer to a bar object 185 * @return the animation time in milliseconds. 186 */ 187 uint16_t lv_bar_get_anim_time(const lv_obj_t * bar); 188 189 /********************** 190 * MACROS 191 **********************/ 192 193 #endif /*LV_USE_BAR*/ 194 195 #ifdef __cplusplus 196 } /* extern "C" */ 197 #endif 198 199 #endif /*LV_BAR_H*/ 200