Skip to content

Conversation

@ickshonpe
Copy link
Contributor

@ickshonpe ickshonpe commented Dec 6, 2025

Objective

Allow picking text per section.

Fixes #17477

Solution

In ui_picking whenever a node with text components is below a pointer, don't add the Text node's entity to the hit_nodes list. Instead, iterate the list of text section bounding rects in its TextLayoutInfo component to find which text section the pointer is over, and add that section's entity id to the hit_nodes list.

  • Add optional text components to NodeQuery.
  • New helper function, pick_ui_text. Finds if a text section is hovered and returns its id.
  • Add the entities of text sections to hit_nodes when hovered.
  • Add the target camera entity to hit_nodes, instead of querying for it a second time.
  • When a picked node is a text node and require_markers is enabled, check if the hit section entity has a Pickable component, instead of the text node.

This design might need to be changed later to allow for text selection and copying. But there doesn't seem any need to overcomplicate things for now by considering it.

Testing

I added observers to the TextBackgroundColors example's text entities. The observers turn a text section's text color to white when the pointer hovers them.

cargo run --example text_background_colors

…it a second time.

* Add the entity of the text section hit to `hit_nodes`.

* When picked node is a text node and `require_markers` is enabled, check if the hit section entity is picked.
…The observers turn the section's color to white when the pointer hovers them.
@ickshonpe ickshonpe changed the title Text section picking Per text section picking Dec 6, 2025
@ickshonpe ickshonpe added A-UI Graphical user interfaces, styles, layouts, and widgets A-Text Rendering and layout for characters labels Dec 6, 2025
@ickshonpe ickshonpe changed the title Per text section picking UI per text section picking Dec 6, 2025
@ickshonpe ickshonpe added A-Picking Pointing at and selecting objects of all sorts D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes C-Feature A new feature, making something new possible M-Release-Note Work that should be called out in the blog due to impact S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Dec 6, 2025
@ickshonpe ickshonpe requested a review from viridia December 9, 2025 10:01
Copy link
Contributor

@viridia viridia left a comment

Choose a reason for hiding this comment

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

Looks good.

@ickshonpe ickshonpe added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Dec 10, 2025
@ickshonpe ickshonpe added the M-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide label Dec 10, 2025
@alice-i-cecile alice-i-cecile removed the S-Needs-Review Needs reviewer attention (from anyone!) to move forward label Dec 11, 2025
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Dec 11, 2025
Merged via the queue into bevyengine:main with commit 2d4e140 Dec 11, 2025
36 checks passed
@janhohenheim janhohenheim added this to the 0.18 milestone Dec 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Picking Pointing at and selecting objects of all sorts A-Text Rendering and layout for characters A-UI Graphical user interfaces, styles, layouts, and widgets C-Feature A new feature, making something new possible D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes M-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide M-Release-Note Work that should be called out in the blog due to impact S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow for click detection (mouse picking) of a TextSpan

5 participants