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

core: Implement keyboard navigation #17086

Merged
merged 3 commits into from
Jul 15, 2024
Merged

Conversation

kjarosh
Copy link
Member

@kjarosh kjarosh commented Jul 12, 2024

Related to #5443.

This PR implements keyboard navigation for highlighted interactive elements.

When ordering objects for navigation, they are divided into two main categories:

  1. objects directly behind the origin (taking into account the direction),
  2. other objects.

Objects from category 1 always take precedence over objects from category 2.

Objects from category 1 are ordered according to their horizontal/vertical distance to the origin, and when two objects have the same distance, the default ordering based on the hierarchy is used.

Objects from category 2 are ordered according to their 2D distance to the origin. The distance is calculated between the closest corners of highlight bounds, and when two objects have the same distance, the default ordering based on the hierarchy is used.

In case of navigating down, there's an additional category (between 1 and 2) which contains objects directly to the right/left of the origin. In that category, objects are ordered according to their x-axis distance towards origin.

Note: the following implementation is still a little off. Its general idea is sound, but there are situations where the exact ordering in category 2 is inaccurate. It seems that FP's behavior in that case depends on things other than highlight bounds, (e.g. past iteration order), however this inaccuracy is not very important as keyboard navigation is performed by the user, and they may always navigate in some other way.

The following image visualizes the object selection preference when navigating down.

This behavior has been derived experimentally. In particular for category 2, points where navigation preference between two objects changed (first object constant, second with variable x and y) were always lying on a circle.

@kjarosh kjarosh added waiting-on-review Waiting on review from a Ruffle team member input Issues relating to user input in Flash content labels Jul 12, 2024
Copy link
Contributor

@Dinnerbone Dinnerbone left a comment

Choose a reason for hiding this comment

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

Thank you!

kjarosh added 3 commits July 15, 2024 21:08
This patch implements keyboard navigation, i.e. changing focus using
arrows when an object is highlighted.
This test verifies the behavior of keyboard navigation with arrows.
@Dinnerbone Dinnerbone enabled auto-merge (rebase) July 15, 2024 19:15
@Dinnerbone Dinnerbone merged commit 582f5db into ruffle-rs:master Jul 15, 2024
17 checks passed
@kjarosh kjarosh deleted the keyboard-nav branch July 15, 2024 19:22
@kjarosh kjarosh removed the waiting-on-review Waiting on review from a Ruffle team member label Jul 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
input Issues relating to user input in Flash content newsworthy
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants