2021-04-08 13:07:48 +02:00
|
|
|
#include "../../lv_examples.h"
|
2021-02-08 09:53:03 +01:00
|
|
|
|
2021-02-14 14:56:34 +01:00
|
|
|
#if LV_USE_ARC && LV_BUILD_EXAMPLES
|
2021-02-08 09:53:03 +01:00
|
|
|
|
2022-04-27 14:24:45 +02:00
|
|
|
static void value_changed_event_cb(lv_event_t * e);
|
|
|
|
|
2021-03-31 16:18:24 +08:00
|
|
|
void lv_example_arc_1(void)
|
2021-02-08 09:53:03 +01:00
|
|
|
{
|
2023-10-12 20:37:27 +02:00
|
|
|
lv_obj_t * label = lv_label_create(lv_screen_active());
|
2022-04-27 14:24:45 +02:00
|
|
|
|
2022-02-13 13:59:17 -05:00
|
|
|
/*Create an Arc*/
|
2023-10-12 20:37:27 +02:00
|
|
|
lv_obj_t * arc = lv_arc_create(lv_screen_active());
|
2022-02-13 13:59:17 -05:00
|
|
|
lv_obj_set_size(arc, 150, 150);
|
|
|
|
lv_arc_set_rotation(arc, 135);
|
|
|
|
lv_arc_set_bg_angles(arc, 0, 270);
|
2022-04-27 14:24:45 +02:00
|
|
|
lv_arc_set_value(arc, 10);
|
2022-02-13 13:59:17 -05:00
|
|
|
lv_obj_center(arc);
|
2023-02-20 20:50:58 +01:00
|
|
|
lv_obj_add_event(arc, value_changed_event_cb, LV_EVENT_VALUE_CHANGED, label);
|
2022-04-27 14:24:45 +02:00
|
|
|
|
|
|
|
/*Manually update the label for the first time*/
|
2023-02-20 20:50:58 +01:00
|
|
|
lv_obj_send_event(arc, LV_EVENT_VALUE_CHANGED, NULL);
|
2022-04-27 14:24:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void value_changed_event_cb(lv_event_t * e)
|
|
|
|
{
|
|
|
|
lv_obj_t * arc = lv_event_get_target(e);
|
|
|
|
lv_obj_t * label = lv_event_get_user_data(e);
|
|
|
|
|
|
|
|
lv_label_set_text_fmt(label, "%d%%", lv_arc_get_value(arc));
|
|
|
|
|
|
|
|
/*Rotate the label to the current position of the arc*/
|
|
|
|
lv_arc_rotate_obj_to_angle(arc, label, 25);
|
2021-02-08 09:53:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|