Skip to content

Commit

Permalink
editor: allow hit testing over text and text runs
Browse files Browse the repository at this point in the history
This PR includes all the changes on the editor and the runtime side to make text and text runs listen to mouse events.

This PR is best reviewed commit-by-commit. Roughly the changes include,
1. Previously, all hit targets had to be world transform components. I had to relax this and added a `isEligibleListenerTarget` function on Component
2. I refactored the adding listener logic to be... recursive. I thought this was easier to reason than to add the same text run logic in many places, since the scrolling handler part would also use this. I'm not sure if they should actually be different though. Moreover, because of HitDrawable's set up to hold a reference to both a drawable and the component, I changed the constructor to account for both. AFAIK, it needs a drawable for the opaque objects check. For text runs, the drawable is actually the parent, not itself. I'm not super happy about this, suggestions welcome.
3. The actual text run hit logic is that I added a 'cached' contours property on the text run, and it is calculated whenever the text recalculates its render styles. I did it here because only the Text object has context on what glyphs should render when clipping or ellipsis is applied.
4. I made sure that only the text runs that are targets would store contours. This is captured in the `Hittable` abstraction. I also made Shapes hittable, and reused the shape's _HitShape for both shapes and text runs.
5. All this logic is also applied to the runtime side. I also ported over the contour finding logic from dart.

I made sure that a hover effect works on a text run, as well as on the whole text (which just delegates to its constituent text runs), both in the editor playback and in a nested artboard. I'd like to write some editor tests to make sure the hover gets captured ok. But it could take me a while, so I'm sending this out first.

Some relevant Slack discussion: https://2dimensions.slack.com/archives/C07HQ4GS0BH/p1733523977504739

Testing
1. New editor tests
2. Verified hit testing works in scrolling containers and in layouts

Diffs=
f19a9c9399 editor: allow hit testing over text and text runs (#8719)
  • Loading branch information
susan101566 committed Dec 18, 2024
1 parent a8d104f commit 31a1955
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .rive_head
Original file line number Diff line number Diff line change
@@ -1 +1 @@
e37a0f285f937042974686b5022c002b0dd143bb
f19a9c9399997a1e1b4571fe860faf2ed60b7d49

0 comments on commit 31a1955

Please sign in to comment.