fix(arc) minor fixes and example updates

This commit is contained in:
Gabor Kiss-Vamosi
2021-05-07 13:33:53 +02:00
parent 9ab0a09fd2
commit 9c7af6c321
3 changed files with 23 additions and 23 deletions

View File

@@ -6,8 +6,10 @@ void lv_example_arc_1(void)
{ {
/*Create an Arc*/ /*Create an Arc*/
lv_obj_t * arc = lv_arc_create(lv_scr_act()); lv_obj_t * arc = lv_arc_create(lv_scr_act());
lv_arc_set_end_angle(arc, 200);
lv_obj_set_size(arc, 150, 150); lv_obj_set_size(arc, 150, 150);
lv_arc_set_rotation(arc, 135);
lv_arc_set_bg_angles(arc, 0, 270);
lv_arc_set_value(arc, 40);
lv_obj_center(arc); lv_obj_center(arc);
} }

View File

@@ -2,22 +2,9 @@
#if LV_USE_ARC && LV_BUILD_EXAMPLES #if LV_USE_ARC && LV_BUILD_EXAMPLES
/** static void set_angle(void * obj, int32_t v)
* An `lv_timer` to call periodically to set the angles of the arc
* @param t
*/
static void arc_loader(lv_timer_t * t)
{ {
static int16_t a = 270; lv_arc_set_value(obj, v);
a+=5;
lv_arc_set_end_angle(t->user_data, a);
if(a >= 270 + 360) {
lv_timer_del(t);
return;
}
} }
/** /**
@@ -27,13 +14,24 @@ void lv_example_arc_2(void)
{ {
/*Create an Arc*/ /*Create an Arc*/
lv_obj_t * arc = lv_arc_create(lv_scr_act()); lv_obj_t * arc = lv_arc_create(lv_scr_act());
lv_arc_set_rotation(arc, 270);
lv_arc_set_bg_angles(arc, 0, 360); lv_arc_set_bg_angles(arc, 0, 360);
lv_arc_set_angles(arc, 270, 270); lv_obj_remove_style(arc, NULL, LV_PART_KNOB); /*Be sure the knob is not displayed*/
lv_obj_clear_flag(arc, LV_OBJ_FLAG_CLICKABLE); /*To not allow adjusting by click*/
lv_obj_center(arc); lv_obj_center(arc);
/*Create an `lv_timer` to update the arc. lv_anim_t a;
*Store the `arc` in the user data*/ lv_anim_init(&a);
lv_timer_create(arc_loader, 20, arc); lv_anim_set_var(&a, arc);
lv_anim_set_exec_cb(&a, set_angle);
lv_anim_set_time(&a, 1000);
lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE); /*Just for the demo*/
lv_anim_set_repeat_delay(&a, 500);
lv_anim_set_values(&a, 0, 100);
lv_anim_start(&a);
} }
#endif #endif

View File

@@ -498,7 +498,7 @@ static void lv_arc_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj)
arc->min_value = 0; arc->min_value = 0;
arc->max_value = 100; arc->max_value = 100;
arc->dragging = false; arc->dragging = false;
arc->chg_rate = 540; arc->chg_rate = 720;
arc->last_tick = lv_tick_get(); arc->last_tick = lv_tick_get();
arc->last_angle =arc->indic_angle_end; arc->last_angle =arc->indic_angle_end;
@@ -578,8 +578,8 @@ static void lv_arc_event(const lv_obj_class_t * class_p, lv_event_t * e)
/*Do not allow big jumps. /*Do not allow big jumps.
*It's mainly to avoid jumping to the opposite end if the "dead" range between min. an max. is crossed. *It's mainly to avoid jumping to the opposite end if the "dead" range between min. an max. is crossed.
*Check which and was closer on the last valid press (arc->min_close) and prefer that end*/ *Check which was closer on the last valid press (arc->min_close) and prefer that end*/
if(LV_ABS(delta_angle) > 180) { if(LV_ABS(delta_angle) > 280) {
if(arc->min_close) angle = 0; if(arc->min_close) angle = 0;
else angle = deg_range; else angle = deg_range;
} }