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