1 #include "../../lv_examples.h"
2 #if LV_USE_SPINBOX && LV_BUILD_EXAMPLES
3
4 static lv_obj_t * spinbox;
5
lv_spinbox_increment_event_cb(lv_event_t * e)6 static void lv_spinbox_increment_event_cb(lv_event_t * e)
7 {
8 lv_event_code_t code = lv_event_get_code(e);
9 if(code == LV_EVENT_SHORT_CLICKED || code == LV_EVENT_LONG_PRESSED_REPEAT) {
10 lv_spinbox_increment(spinbox);
11 }
12 }
13
lv_spinbox_decrement_event_cb(lv_event_t * e)14 static void lv_spinbox_decrement_event_cb(lv_event_t * e)
15 {
16 lv_event_code_t code = lv_event_get_code(e);
17 if(code == LV_EVENT_SHORT_CLICKED || code == LV_EVENT_LONG_PRESSED_REPEAT) {
18 lv_spinbox_decrement(spinbox);
19 }
20 }
21
lv_example_spinbox_1(void)22 void lv_example_spinbox_1(void)
23 {
24 spinbox = lv_spinbox_create(lv_scr_act());
25 lv_spinbox_set_range(spinbox, -1000, 25000);
26 lv_spinbox_set_digit_format(spinbox, 5, 2);
27 lv_spinbox_step_prev(spinbox);
28 lv_obj_set_width(spinbox, 100);
29 lv_obj_center(spinbox);
30
31 lv_coord_t h = lv_obj_get_height(spinbox);
32
33 lv_obj_t * btn = lv_btn_create(lv_scr_act());
34 lv_obj_set_size(btn, h, h);
35 lv_obj_align_to(btn, spinbox, LV_ALIGN_OUT_RIGHT_MID, 5, 0);
36 lv_obj_set_style_bg_img_src(btn, LV_SYMBOL_PLUS, 0);
37 lv_obj_add_event_cb(btn, lv_spinbox_increment_event_cb, LV_EVENT_ALL, NULL);
38
39 btn = lv_btn_create(lv_scr_act());
40 lv_obj_set_size(btn, h, h);
41 lv_obj_align_to(btn, spinbox, LV_ALIGN_OUT_LEFT_MID, -5, 0);
42 lv_obj_set_style_bg_img_src(btn, LV_SYMBOL_MINUS, 0);
43 lv_obj_add_event_cb(btn, lv_spinbox_decrement_event_cb, LV_EVENT_ALL, NULL);
44 }
45
46 #endif
47