Fix: Response::hover_pos
returns incorrect positions with layer transforms
#4679
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When layer transforms are present, the
Response::hover_pos
function in egui returnstransform * pos
instead oftransform.inverse() * pos
. This is incorrect and isn't consistent with how egui calculates other interaction positions.See: https://github.com/emilk/egui/blob/master/crates/egui/src/response.rs#L471
This PR fixes this bug, changing
transform
totransform.inverse()
. Nothing fancy here, just a one-line change.scripts/check.sh
runs successfully.Below are videos of before and after with a modified version of the web demo. I added another entry after https://github.com/emilk/egui/blob/master/crates/egui_demo_lib/src/demo/pan_zoom.rs#L108 with a debug rectangle drawn at the return value of
hover_pos
:Without the fix:
https://github.com/emilk/egui/assets/104604363/241cfcab-88ab-459b-8f4d-3367da3aa392
With the fix:
https://github.com/emilk/egui/assets/104604363/e52a7263-44c7-42c1-be46-1ecadc025625