Skip to content

fix(arc): ignore hits that are outside drawn background arc - #6753

Merged
kisvegabor merged 6 commits into
lvgl:masterfrom
triktron:fix_arc_hittest_outside_range
Sep 3, 2024
Merged

kisvegabor merged 6 commits into
lvgl:masterfrom
triktron:fix_arc_hittest_outside_range

Conversation

@triktron

Copy link
Copy Markdown
Contributor

Summary:

When two arcs share the same center and radius but have non-overlapping background angles, the lower arc is not interactable. The current implementation checks whether the interaction is at the correct distance from the center but does not verify if it falls within the correct arc range.

Changes:

Added an arc range check to ensure that the interaction occurs within the specified angles of the arc.

Implementation Details:

The code checks the angular range of the arcs, in addition to the existing distance check, to determine if the interaction should be processed. This logic is based on similar checks already implemented in the LV_EVENT_PRESSING event, as referenced in #4576 .

Example Usage:

lv_obj_t *arc1 = lv_arc_create(scr);
lv_arc_set_bg_angles(arc1, 5, 175);
lv_arc_set_value(arc1, 10);
lv_obj_set_size(arc1, 380, 380);
lv_obj_center(arc1);
lv_obj_add_flag(arc1, LV_OBJ_FLAG_ADV_HITTEST);

lv_obj_t *arc2 = lv_arc_create(scr);
lv_arc_set_bg_angles(arc2, 185, 355);
lv_arc_set_value(arc2, 10);
lv_obj_set_size(arc2, 380, 380);
lv_obj_center(arc2);
lv_obj_add_flag(arc2, LV_OBJ_FLAG_ADV_HITTEST);

Testing:

Tested with overlapping and non-overlapping arcs with the same center and radius.
Verified that interactions are processed correctly based on the angular range.

Notes:

This change ensures that arcs with distinct background angles remain independently interactable even when they share the same center and radius.

Notes:

@liamHowatt liamHowatt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Awesome!

Nice application of LV_OBJ_FLAG_ADV_HITTEST.

Comment thread src/widgets/arc/lv_arc.c Resolved
@kisvegabor

kisvegabor commented Aug 29, 2024 •

Copy link
Copy Markdown
Member

Nice! Could you add a test and mention this behavior in the docs as well?

@liamHowatt

Copy link
Copy Markdown
Contributor

Fyi the CI is failing because lv_value_precise_t can be a float depending on the configuration and % cannot directly be used on floats. I don't know if this is the best fix but maybe we could do something like this? If there's a better idea I'm open to it. Or maybe the while idea is better. Not sure.

In the defines section at the top

#if LV_USE_FLOAT
#define VALUE_PRECISE_MOD(x, y) fmodf((x), (y))
#else
#define VALUE_PRECISE_MOD(x, y) (x) % (y)
#endif

And then you can do

angle = VALUE_PRECISE_MOD(VALUE_PRECISE_MOD(angle, 360) + 360, 360);

@triktron

Copy link
Copy Markdown
Contributor Author

I had a similar idea in mind, but was unsure of it would cause trouble including the math.h lib.
I ended up replacing it locally with this:

while (angle >= 360) angle -= 360;
while (angle < 0) angle += 360;

This works without having to add any dependency, but feels wasteful to me, not that i any test either one would be faster.
This approach would be more readable in my opinion.

I haven't pushed this yet as I'm first trying to set up the unit tests for this case.

@triktron

Copy link
Copy Markdown
Contributor Author

Nice! Could you add a test and mention this behavior in the docs as well?

I wasn't 100% sure what to do for the documentation. would changing the paragraph

lvgl/docs/widgets/arc.rst

Lines 108 to 116 in 2c021b6

Advanced hit test
-----------------
If the :cpp:enumerator:`LV_OBJ_FLAG_ADV_HITTEST` flag is enabled the arc can be
clicked through in the middle. Clicks are recognized only on the ring of
the background arc. :cpp:func:`lv_obj_set_ext_click_size` makes the sensitive
area larger inside and outside with the given number of pixels.
Place another object to the knob
to the following suffice?

Advanced hit test
-----------------

If the :cpp:enumerator:`LV_OBJ_FLAG_ADV_HITTEST` flag is enabled the arc can be
clicked through in the middle. Now, clicks are recognized only when they occur
on the ring of the arc and within the defined start and end angles. The end angles
are extended by :cpp:expr:`lv_dpx(50U)` to allow for a slightly larger interactive area.
Additionally, :cpp:func:`lv_obj_set_ext_click_size` can be used to further increase
the sensitive area both inside and outside the arc by a specified number of pixels.

@kisvegabor

kisvegabor commented Aug 30, 2024 •

Copy link
Copy Markdown
Member

I also vote for while(angle < 0) angle += 360; because it's simpler and equally good.

Regarding the docs: based on the latest code I think this is happening:

Interactive area
----------------

By default :cpp:enumerator:`LV_OBJ_FLAG_ADV_HITTEST` is disabled which 
means the arc's whole area is interactive. 
As usual :cpp:func:`lv_obj_set_ext_click_size` can be used to increase
the sensitive area outside the arc by a specified number of pixels.

If :cpp:enumerator:`LV_OBJ_FLAG_ADV_HITTEST` is enabled the arc will be sensitive only 
in the range of start and end background angles and on the arc itself (not inside the arc). 
In this case ``ext_click_size`` makes the sensitive area ticker both inward and outward. 

Please check if it's correct.

@triktron

Copy link
Copy Markdown
Contributor Author

Sounds good, i think it explains it nicely! I've added a small part to include the extended arc ranges.

@kisvegabor kisvegabor left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Great, thank you!

@liamHowatt liamHowatt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you!

@kisvegabor
kisvegabor merged commit e4e1b26 into lvgl:master Sep 3, 2024
kisvegabor pushed a commit to kisvegabor/lvgl_fork that referenced this pull request Oct 1, 2024
rodb70 pushed a commit to rodb70/lvgl that referenced this pull request Nov 8, 2024
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.

3 participants