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

Add relative position reporting to UI picking #17681

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

bytemunch
Copy link
Contributor

Objective

Add position reporting to HitData sent from the UI picking backend.

Solution

Add the computed normalized relative cursor position to hit_data alongside the Entity.

The position reported in HitData is normalized relative to the node, with (0.,0.,0.) at the top left and (1., 1., 0.) in the bottom right. Coordinates are relative to the entire node, not just the visible region.

HitData needs a Vec3 so I just extended with 0.0. I considered inserting the depth here but thought it would be redundant.

I also considered putting the screen space position in the normal field of HitData, but that would require renaming of the field or a separate data structure.

Testing

Tested with mouse on X11 with entities that have Node components.


Showcase

// Get click position relative to node
fn hit_position(trigger: Trigger<Pointer<Click>>) {
    let hit_pos = trigger.event.hit.position.expect("no position");
    info!("{}", hit_pos);
}

Copy link
Contributor

github-actions bot commented Feb 4, 2025

Welcome, new contributor!

Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨

@ickshonpe ickshonpe added C-Feature A new feature, making something new possible A-UI Graphical user interfaces, styles, layouts, and widgets D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward A-Picking Pointing at and selecting objects of all sorts labels Feb 4, 2025
Copy link
Contributor

@ickshonpe ickshonpe left a comment

Choose a reason for hiding this comment

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

Works fine, added

                .observe(|trigger: Trigger<Pointer<Click>>| {
                    let hit_pos = trigger.event.hit.position.expect("no position");
                    info!("{}", hit_pos);
                });

to the interactable node in the relative_cursor_position example and the position reported by info! matches the position reported by the example's position text.

I think not repurposing the normal field is a good decision as it's potentially confusing.

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-UI Graphical user interfaces, styles, layouts, and widgets C-Feature A new feature, making something new possible D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants