Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(arc): arc pressing bounds detection #6188

Merged
merged 1 commit into from May 12, 2024

Conversation

liamHowatt
Copy link
Collaborator

Description of the feature or fix

Fixes #5870

1

Fix an issue where the start and end angle of the arc are not processed correctly if the start angle is smaller than the end angle (and the end angle was <=360 when it was set with the setter).

This is the whole fix

diff --git a/src/widgets/arc/lv_arc.c b/src/widgets/arc/lv_arc.c
index 6d4383971..aa9349a56 100644
--- a/src/widgets/arc/lv_arc.c
+++ b/src/widgets/arc/lv_arc.c
@@ -937,12 +937,12 @@ static bool lv_arc_angle_within_bg_bounds(lv_obj_t * obj, const lv_value_precise
     lv_value_precise_t smaller_angle = 0;
     lv_value_precise_t bigger_angle = 0;
 
     /* Determine which background angle is smaller and bigger */
     if(arc->bg_angle_start < arc->bg_angle_end) {
-        bigger_angle = arc->bg_angle_end;
-        smaller_angle = arc->bg_angle_start;
+        bigger_angle = arc->bg_angle_end - arc->bg_angle_start;
+        smaller_angle = 0;
     }
     else {
         bigger_angle = (360 - arc->bg_angle_start) + arc->bg_angle_end;
         smaller_angle = 0;
     }

It works because the angle parameter in that function is relative to arc->bg_angle_start. The else branch already did the correct thing. I think the else was casually fixed by 84c8cf8

2

I simplified the rest of the function given that smaller_angle is always 0 and all the parameters are non-negative.

@C47D if you can catch anything I oversimplified please comment.

3

I fixed the "big jump prevention logic" which seemed to be misbehaving in master.

Notes

@C47D
Copy link
Contributor

C47D commented May 7, 2024

Hi @liamHowatt , thanks for taking care of this while I was away.

It's also good to remove complex logic, all looks good to me.

Copy link
Member

@kisvegabor kisvegabor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic, thank you Liam!

@W-Mai
Copy link
Contributor

W-Mai commented May 8, 2024

iShot_2024-05-08_14 19 16

I think there may still be some minor problems here. In this case, it will be expected that the knob will get stuck at the boundary instead of going back.

void lv_example_arc_1(void)
{
    lv_obj_t * label = lv_label_create(lv_screen_active());

    /*Create an Arc*/
    lv_obj_t * arc = lv_arc_create(lv_screen_active());
    lv_obj_set_size(arc, 150, 150);
    lv_arc_set_rotation(arc, 135);
    lv_arc_set_bg_angles(arc, 0, 359);
    lv_arc_set_value(arc, 10);
    lv_obj_center(arc);
    lv_obj_add_event_cb(arc, value_changed_event_cb, LV_EVENT_VALUE_CHANGED, label);

    /*Manually update the label for the first time*/
    lv_obj_send_event(arc, LV_EVENT_VALUE_CHANGED, NULL);
}

@liamHowatt
Copy link
Collaborator Author

Thanks for trying it @W-Mai! Yup! I was able to fix the problem you found but not without affecting other good behavior. Let me see.

No one merge this yet.

@FASTSHIFT FASTSHIFT merged commit 152cda6 into lvgl:master May 12, 2024
19 checks passed
@kisvegabor
Copy link
Member

No one merge this yet.

Ups, please open a new PR if you find a good solution. 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

reverse mode for lv_arc
5 participants