1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-21 06:53:01 +08:00
lvgl/examples/widgets/meter/lv_example_meter_2.c

60 lines
1.7 KiB
C
Raw Normal View History

2021-02-08 09:53:03 +01:00
#include "../../../lvgl.h"
2021-02-14 14:56:34 +01:00
#if LV_USE_METER && LV_BUILD_EXAMPLES
2021-02-08 09:53:03 +01:00
static lv_obj_t * meter;
2021-02-22 20:27:46 +01:00
static void set_value(void * indic, int32_t v)
2021-02-08 09:53:03 +01:00
{
lv_meter_set_indicator_end_value(meter, indic, v);
}
/**
* A meter with multiple arcs
*/
void lv_example_meter_2(void)
{
meter = lv_meter_create(lv_scr_act());
lv_obj_center(meter);
2021-02-08 09:53:03 +01:00
/*Remove the circle from the middle*/
lv_obj_remove_style(meter, NULL, LV_PART_INDICATOR);
2021-02-08 09:53:03 +01:00
/*Add a scale first*/
lv_meter_scale_t * scale = lv_meter_add_scale(meter);
lv_meter_set_scale_ticks(meter, scale, 11, 2, 10, lv_color_grey());
2021-02-08 09:53:03 +01:00
lv_meter_set_scale_major_ticks(meter, scale, 1, 2, 30, lv_color_hex3(0xeee), 10);
lv_meter_set_scale_range(meter, scale, 0, 100, 270, 90);
/*Add a three arc indicator*/
lv_meter_indicator_t * indic1 = lv_meter_add_arc(meter, scale, 10, lv_color_red(), 0);
lv_meter_indicator_t * indic2 = lv_meter_add_arc(meter, scale, 10, lv_color_green(), -10);
lv_meter_indicator_t * indic3 = lv_meter_add_arc(meter, scale, 10, lv_color_blue(), -20);
2021-02-08 09:53:03 +01:00
/*Create an animation to set the value*/
lv_anim_t a;
lv_anim_init(&a);
2021-02-22 20:27:46 +01:00
lv_anim_set_exec_cb(&a, set_value);
2021-02-08 09:53:03 +01:00
lv_anim_set_values(&a, 0, 100);
lv_anim_set_repeat_delay(&a, 100);
lv_anim_set_playback_delay(&a, 100);
lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE);
lv_anim_set_time(&a, 2000);
lv_anim_set_playback_time(&a, 500);
lv_anim_set_var(&a, indic1);
lv_anim_start(&a);
lv_anim_set_time(&a, 1000);
lv_anim_set_playback_time(&a, 1000);
lv_anim_set_var(&a, indic2);
lv_anim_start(&a);
lv_anim_set_time(&a, 1000);
lv_anim_set_playback_time(&a, 2000);
lv_anim_set_var(&a, indic3);
lv_anim_start(&a);
}
#endif