egui/crates
Colin Cai cd3e9ea5b6
Fix: `Response::hover_pos` returns incorrect positions with layer transforms (#4679)
<!--
Please read the "Making a PR" section of
[`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/master/CONTRIBUTING.md)
before opening a Pull Request!

* Keep your PR:s small and focused.
* The PR title is what ends up in the changelog, so make it descriptive!
* If applicable, add a screenshot or gif.
* If it is a non-trivial addition, consider adding a demo for it to
`egui_demo_lib`, or a new example.
* Do NOT open PR:s from your `master` branch, as that makes it hard for
maintainers to add commits to your PR.
* Remember to run `cargo fmt` and `cargo clippy`.
* Open the PR as a draft until you have self-reviewed it and run
`./scripts/check.sh`.
* When you have addressed a PR comment, mark it as resolved.

Please be patient! I will review your PR, but my time is limited!
-->

When layer transforms are present, the `Response::hover_pos` function in
egui returns `transform * pos` instead of `transform.inverse() * pos`.
This is incorrect and isn't consistent with [how egui calculates other
interaction
positions](https://github.com/emilk/egui/blob/master/crates/egui/src/context.rs#L1193).

See:
https://github.com/emilk/egui/blob/master/crates/egui/src/response.rs#L471

This PR fixes this bug, changing `transform` to `transform.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`:
```rust
(
    egui::Pos2::new(120.0, 120.0),
    Box::new(|ui, _state| {
        let response =
            ui.allocate_response(egui::Vec2::splat(128.0), egui::Sense::hover());
        ui.painter().rect_filled(
            egui::Rect::from_center_size(
                response.hover_pos().unwrap_or_default(),
                egui::Vec2::splat(8.0),
            ),
            egui::Rounding::ZERO,
            egui::Color32::DEBUG_COLOR,
        );
        response
    }),
),
```

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
2024-06-20 10:43:51 +02:00
..
ecolor Add `Color32::lerp_to_gamma` (#4627) 2024-06-06 15:41:10 +02:00
eframe Fix dragging of `custom_window_frame` example on Windows (#4656) 2024-06-19 16:19:41 +02:00
egui Fix: `Response::hover_pos` returns incorrect positions with layer transforms (#4679) 2024-06-20 10:43:51 +02:00
egui-wgpu Fix doclinks in egui-wgpu docs (#4677) 2024-06-19 11:26:26 +02:00
egui-winit Fix dragging of `custom_window_frame` example on Windows (#4656) 2024-06-19 16:19:41 +02:00
egui_demo_app `egui_extras`: Make `serde` an optional feature (#4641) 2024-06-18 22:27:48 +02:00
egui_demo_lib Fix dead link to mycomarkup in easy_mark sample (#4643) 2024-06-18 22:36:56 +02:00
egui_extras Gif support (#4620) 2024-06-19 14:05:05 +02:00
egui_glow Fix dragging of `custom_window_frame` example on Windows (#4656) 2024-06-19 16:19:41 +02:00
egui_plot egui_plot: use `f64` for translate (#4637) 2024-06-18 22:55:08 +02:00
egui_web Fix typos (#2866) 2023-04-18 15:52:45 +02:00
emath Add `Rect::from_pos` 2024-06-19 11:27:33 +02:00
epaint Bug fix: ui opacity and gray-out not affecting strokes (#4581) 2024-05-29 22:37:55 +02:00