1 #include "../../lv_examples.h"
2
3 #if LV_USE_ARC && LV_BUILD_EXAMPLES
4
5 static void value_changed_event_cb(lv_event_t * e);
6
lv_example_arc_1(void)7 void lv_example_arc_1(void)
8 {
9 lv_obj_t * label = lv_label_create(lv_scr_act());
10
11 /*Create an Arc*/
12 lv_obj_t * arc = lv_arc_create(lv_scr_act());
13 lv_obj_set_size(arc, 150, 150);
14 lv_arc_set_rotation(arc, 135);
15 lv_arc_set_bg_angles(arc, 0, 270);
16 lv_arc_set_value(arc, 10);
17 lv_obj_center(arc);
18 lv_obj_add_event_cb(arc, value_changed_event_cb, LV_EVENT_VALUE_CHANGED, label);
19
20 /*Manually update the label for the first time*/
21 lv_event_send(arc, LV_EVENT_VALUE_CHANGED, NULL);
22 }
23
value_changed_event_cb(lv_event_t * e)24 static void value_changed_event_cb(lv_event_t * e)
25 {
26 lv_obj_t * arc = lv_event_get_target(e);
27 lv_obj_t * label = lv_event_get_user_data(e);
28
29 lv_label_set_text_fmt(label, "%d%%", lv_arc_get_value(arc));
30
31 /*Rotate the label to the current position of the arc*/
32 lv_arc_rotate_obj_to_angle(arc, label, 25);
33 }
34
35 #endif
36