1 /** 2 * @file lv_spinner.h 3 * 4 */ 5 6 #ifndef LV_SPINNER_H 7 #define LV_SPINNER_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_SPINNER != 0 19 20 /*Testing of dependencies*/ 21 #if LV_USE_ARC == 0 22 #error "lv_spinner: lv_arc is required. Enable it in lv_conf.h (LV_USE_ARC 1) " 23 #endif 24 25 #if LV_USE_ANIMATION == 0 26 #error "lv_spinner: animations are required. Enable it in lv_conf.h (LV_USE_ANIMATION 1) " 27 #endif 28 29 #include "../lv_core/lv_obj.h" 30 #include "../lv_misc/lv_anim.h" 31 #include "lv_arc.h" 32 33 /********************* 34 * DEFINES 35 *********************/ 36 37 /********************** 38 * TYPEDEFS 39 **********************/ 40 41 /** 42 * Type of spinner. 43 */ 44 enum { 45 LV_SPINNER_TYPE_SPINNING_ARC, 46 LV_SPINNER_TYPE_FILLSPIN_ARC, 47 LV_SPINNER_TYPE_CONSTANT_ARC, 48 }; 49 typedef uint8_t lv_spinner_type_t; 50 51 /** 52 * Direction the spinner should spin. 53 */ 54 enum { 55 LV_SPINNER_DIR_FORWARD, 56 LV_SPINNER_DIR_BACKWARD, 57 }; 58 typedef uint8_t lv_spinner_dir_t; 59 60 /*Data of spinner*/ 61 typedef struct { 62 lv_arc_ext_t arc; /*Ext. of ancestor*/ 63 /*New data for this type */ 64 lv_anim_value_t arc_length; /*Length of the spinning indicator in degree*/ 65 uint16_t time; /*Time of one round*/ 66 lv_spinner_type_t anim_type : 2; /*Type of the arc animation*/ 67 lv_spinner_dir_t anim_dir : 1; /*Animation Direction*/ 68 } lv_spinner_ext_t; 69 70 /*Parts of the spinner*/ 71 enum { 72 LV_SPINNER_PART_BG = LV_ARC_PART_BG, 73 LV_SPINNER_PART_INDIC = LV_ARC_PART_INDIC, 74 _LV_SPINNER_PART_VIRTUAL_LAST, 75 76 _LV_SPINNER_PART_REAL_LAST = _LV_ARC_PART_REAL_LAST, 77 }; 78 typedef uint8_t lv_spinner_style_t; 79 80 /********************** 81 * GLOBAL PROTOTYPES 82 **********************/ 83 84 /** 85 * Create a spinner object 86 * @param par pointer to an object, it will be the parent of the new spinner 87 * @param copy pointer to a spinner object, if not NULL then the new object will be copied from 88 * it 89 * @return pointer to the created spinner 90 */ 91 lv_obj_t * lv_spinner_create(lv_obj_t * par, const lv_obj_t * copy); 92 93 /*====================== 94 * Add/remove functions 95 *=====================*/ 96 97 /** 98 * Set the length of the spinning arc in degrees 99 * @param spinner pointer to a spinner object 100 * @param deg length of the arc 101 */ 102 void lv_spinner_set_arc_length(lv_obj_t * spinner, lv_anim_value_t deg); 103 104 /** 105 * Set the spin time of the arc 106 * @param spinner pointer to a spinner object 107 * @param time time of one round in milliseconds 108 */ 109 void lv_spinner_set_spin_time(lv_obj_t * spinner, uint16_t time); 110 111 /*===================== 112 * Setter functions 113 *====================*/ 114 115 /** 116 * Set the animation type of a spinner. 117 * @param spinner pointer to spinner object 118 * @param type animation type of the spinner 119 * */ 120 void lv_spinner_set_type(lv_obj_t * spinner, lv_spinner_type_t type); 121 122 /** 123 * Set the animation direction of a spinner 124 * @param spinner pointer to spinner object 125 * @param direction animation direction of the spinner 126 */ 127 void lv_spinner_set_dir(lv_obj_t * spinner, lv_spinner_dir_t dir); 128 129 /*===================== 130 * Getter functions 131 *====================*/ 132 133 /** 134 * Get the arc length [degree] of the a spinner 135 * @param spinner pointer to a spinner object 136 */ 137 lv_anim_value_t lv_spinner_get_arc_length(const lv_obj_t * spinner); 138 139 /** 140 * Get the spin time of the arc 141 * @param spinner pointer to a spinner object [milliseconds] 142 */ 143 uint16_t lv_spinner_get_spin_time(const lv_obj_t * spinner); 144 145 /** 146 * Get the animation type of a spinner. 147 * @param spinner pointer to spinner object 148 * @return animation type 149 * */ 150 lv_spinner_type_t lv_spinner_get_type(lv_obj_t * spinner); 151 152 /** 153 * Get the animation direction of a spinner 154 * @param spinner pointer to spinner object 155 * @return animation direction 156 */ 157 lv_spinner_dir_t lv_spinner_get_dir(lv_obj_t * spinner); 158 159 /*===================== 160 * Other functions 161 *====================*/ 162 163 /** 164 * Animator function (exec_cb) to rotate the arc of spinner. 165 * @param ptr pointer to spinner 166 * @param val the current desired value [0..360] 167 */ 168 void lv_spinner_anim_cb(void * ptr, lv_anim_value_t val); 169 170 /********************** 171 * MACROS 172 **********************/ 173 174 #endif /*LV_USE_SPINNER*/ 175 176 #ifdef __cplusplus 177 } /* extern "C" */ 178 #endif 179 180 #endif /*LV_SPINNER_H*/ 181