1 /** 2 * @file lv_spinbox.h 3 * 4 */ 5 6 #ifndef LV_SPINBOX_H 7 #define LV_SPINBOX_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_SPINBOX != 0 19 20 /*Testing of dependencies*/ 21 #if LV_USE_TEXTAREA == 0 22 #error "lv_spinbox: lv_ta is required. Enable it in lv_conf.h (LV_USE_TEXTAREA 1) " 23 #endif 24 25 #include "../lv_core/lv_obj.h" 26 #include "../lv_widgets/lv_textarea.h" 27 28 /********************* 29 * DEFINES 30 *********************/ 31 #define LV_SPINBOX_MAX_DIGIT_COUNT 10 32 33 /********************** 34 * TYPEDEFS 35 **********************/ 36 37 /*Data of spinbox*/ 38 typedef struct { 39 lv_textarea_ext_t ta; /*Ext. of ancestor*/ 40 /*New data for this type */ 41 int32_t value; 42 int32_t range_max; 43 int32_t range_min; 44 int32_t step; 45 uint8_t rollover : 1; // Set to true for rollover functionality 46 uint16_t digit_count : 4; 47 uint16_t dec_point_pos : 4; /*if 0, there is no separator and the number is an integer*/ 48 uint16_t digit_padding_left : 4; 49 } lv_spinbox_ext_t; 50 51 /*Styles*/ 52 enum { 53 LV_SPINBOX_PART_BG = LV_TEXTAREA_PART_BG, 54 LV_SPINBOX_PART_CURSOR = LV_TEXTAREA_PART_CURSOR, 55 _LV_SPINBOX_PART_VIRTUAL_LAST = _LV_TEXTAREA_PART_VIRTUAL_LAST, 56 _LV_SPINBOX_PART_REAL_LAST = _LV_TEXTAREA_PART_REAL_LAST, 57 }; 58 typedef uint8_t lv_spinbox_part_t; 59 60 /********************** 61 * GLOBAL PROTOTYPES 62 **********************/ 63 64 /** 65 * Create a spinbox objects 66 * @param par pointer to an object, it will be the parent of the new spinbox 67 * @param copy pointer to a spinbox object, if not NULL then the new object will be copied from it 68 * @return pointer to the created spinbox 69 */ 70 lv_obj_t * lv_spinbox_create(lv_obj_t * par, const lv_obj_t * copy); 71 72 /*===================== 73 * Setter functions 74 *====================*/ 75 76 /** 77 * Set spinbox rollover function 78 * @param spinbox pointer to spinbox 79 * @param b true or false to enable or disable (default) 80 */ 81 void lv_spinbox_set_rollover(lv_obj_t * spinbox, bool b); 82 83 /** 84 * Set spinbox value 85 * @param spinbox pointer to spinbox 86 * @param i value to be set 87 */ 88 void lv_spinbox_set_value(lv_obj_t * spinbox, int32_t i); 89 90 /** 91 * Set spinbox digit format (digit count and decimal format) 92 * @param spinbox pointer to spinbox 93 * @param digit_count number of digit excluding the decimal separator and the sign 94 * @param separator_position number of digit before the decimal point. If 0, decimal point is not 95 * shown 96 */ 97 void lv_spinbox_set_digit_format(lv_obj_t * spinbox, uint8_t digit_count, uint8_t separator_position); 98 99 /** 100 * Set spinbox step 101 * @param spinbox pointer to spinbox 102 * @param step steps on increment/decrement 103 */ 104 void lv_spinbox_set_step(lv_obj_t * spinbox, uint32_t step); 105 106 /** 107 * Set spinbox value range 108 * @param spinbox pointer to spinbox 109 * @param range_min maximum value, inclusive 110 * @param range_max minimum value, inclusive 111 */ 112 void lv_spinbox_set_range(lv_obj_t * spinbox, int32_t range_min, int32_t range_max); 113 114 /** 115 * Set spinbox left padding in digits count (added between sign and first digit) 116 * @param spinbox pointer to spinbox 117 * @param cb Callback function called on value change event 118 */ 119 void lv_spinbox_set_padding_left(lv_obj_t * spinbox, uint8_t padding); 120 121 /*===================== 122 * Getter functions 123 *====================*/ 124 125 /** 126 * Get spinbox rollover function status 127 * @param spinbox pointer to spinbox 128 */ 129 bool lv_spinbox_get_rollover(lv_obj_t * spinbox); 130 131 /** 132 * Get the spinbox numeral value (user has to convert to float according to its digit format) 133 * @param spinbox pointer to spinbox 134 * @return value integer value of the spinbox 135 */ 136 int32_t lv_spinbox_get_value(lv_obj_t * spinbox); 137 138 /*===================== 139 * Other functions 140 *====================*/ 141 142 /** 143 * Select next lower digit for edition by dividing the step by 10 144 * @param spinbox pointer to spinbox 145 */ 146 void lv_spinbox_step_next(lv_obj_t * spinbox); 147 148 /** 149 * Select next higher digit for edition by multiplying the step by 10 150 * @param spinbox pointer to spinbox 151 */ 152 void lv_spinbox_step_prev(lv_obj_t * spinbox); 153 154 /** 155 * Increment spinbox value by one step 156 * @param spinbox pointer to spinbox 157 */ 158 void lv_spinbox_increment(lv_obj_t * spinbox); 159 160 /** 161 * Decrement spinbox value by one step 162 * @param spinbox pointer to spinbox 163 */ 164 void lv_spinbox_decrement(lv_obj_t * spinbox); 165 166 /********************** 167 * MACROS 168 **********************/ 169 170 #endif /*LV_USE_SPINBOX*/ 171 172 #ifdef __cplusplus 173 } /* extern "C" */ 174 #endif 175 176 #endif /*LV_SPINBOX_H*/ 177