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

UI Text picking #17775

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from
Draft

UI Text picking #17775

wants to merge 15 commits into from

Conversation

bytemunch
Copy link
Contributor

@bytemunch bytemunch commented Feb 10, 2025

Objective

Add text picking backends.

Fixes #17477 + fixes #17706

Solution

Write a backend that emits text specific pointer events for UI text.

Testing

examples/picking/text_picking.rs

Next steps

  • More visual example, perhaps showing selectable text showcasing dragging observers.

  • Performance concerns: Iterating every glyph on every hover event is a LOT of iterating. Maybe leave getting a PositionedGlyph from a Cursor up to a helper function

  • Fix window scale factor issues

  • Consider fully decoupling from Pointer, Like read PointerHits directly, or even create a separate TextPointerHits channel. Lots of duplicated functionality though.


Showcase

Currently returns a cosmic Cursor in a new TextPointer event that can be used in observers similar to Pointer events.

@bytemunch bytemunch mentioned this pull request Feb 10, 2025
Copy link
Contributor

The generated examples/README.md is out of sync with the example metadata in Cargo.toml or the example readme template. Please run cargo run -p build-templated-pages -- update examples to update it, and commit the file change.

@alice-i-cecile alice-i-cecile added C-Feature A new feature, making something new possible A-Text Rendering and layout for characters A-Picking Pointing at and selecting objects of all sorts M-Needs-Release-Note Work that should be called out in the blog due to impact S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Feb 10, 2025
@alice-i-cecile
Copy link
Member

I'm merging #17681; can you update this PR to use that? :)

@bytemunch
Copy link
Contributor Author

Yeah absolutely, thanks :)

@alice-i-cecile
Copy link
Member

And I'm merging #17748, which will create some more merge conflicts for you <3

@NicTanghe
Copy link

NicTanghe commented Feb 13, 2025

interesting.
I wonder if i can make this output the position starting from the index of the char in a text.

@bytemunch
Copy link
Contributor Author

Yeah it's possible with some APIs in this PR, this is very work-in-progress at the moment so I wouldn't rely on anything here being available in bevy any time soon if at all, but everything I've implemented should be possible in third party space. Getting the PositionedGlyph from a text pick is and will be possible, just working out the best way of giving access to that. Once you have access to the glyph it's just a bit of transform math and you should have the location :)

@bytemunch
Copy link
Contributor Author

I think I'll refocus this PR to just UI text picking, once all the kinks are done there I'll have another look at Text2d, code changes getting a bit heavy

@bytemunch bytemunch changed the title Text picking UI Text picking Feb 13, 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 C-Feature A new feature, making something new possible M-Needs-Release-Note Work that should be called out in the blog due to impact S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Text Picking Allow for click detection (mouse picking) of a TextSpan
3 participants