egui/crates
Avery Radmacher e06b225dab
Fix: Window position creeps between executions on scaled monitors (#4443)
<!--
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!
-->

* Closes <https://github.com/emilk/egui/issues/4442>
* Refactors active monitor detection so it can be called from multiple
locations.

Compare this gif to the one on the issue report.

![egui_window_position_no_creep](https://github.com/emilk/egui/assets/45777186/8e05d4fb-266e-48b9-9223-b65f16500a99)

### Investigation notes

- [`WindowSettings.inner_position_pixels` and
`WindowSettings.outer_position_pixels`](https://github.com/emilk/egui/blob/master/crates/egui-winit/src/window_settings.rs#L8-L12)
are stored in physical/pixel coordinates.
- `ViewportBuilder::with_position` expects to be passed a position in
_logical_ coordinates.
- Prior to this PR, the position was being passed from `WindowSettings`
to `with_position` [without any
scaling](https://github.com/emilk/egui/blob/master/crates/egui-winit/src/window_settings.rs#L61-L68).
This was the root cause of the issue.
- The fix is to first convert the position to logical coordinates,
respecting the scaling factor of the active monitor. This requires us to
first determine the active monitor, so I factored out some of the logic
in
[`clamp_pos_to_monitor`](https://github.com/emilk/egui/blob/master/crates/egui-winit/src/window_settings.rs#L130)
to find the active monitor.
2024-05-11 16:48:12 +02:00
..
ecolor Remove `extra_asserts` and `extra_debug_asserts` feature flags (#4478) 2024-05-10 19:39:08 +02:00
eframe Fix: Window position creeps between executions on scaled monitors (#4443) 2024-05-11 16:48:12 +02:00
egui Treat `Event::PointerGone` as `PointerEvent::Released` (#4419) 2024-05-11 13:17:58 +02:00
egui-wgpu Fix some clippy warning from Rust 1.78.0 (#4444) 2024-05-02 17:04:25 +02:00
egui-winit Fix: Window position creeps between executions on scaled monitors (#4443) 2024-05-11 16:48:12 +02:00
egui_demo_app Remove `extra_asserts` and `extra_debug_asserts` feature flags (#4478) 2024-05-10 19:39:08 +02:00
egui_demo_lib Treat `Event::PointerGone` as `PointerEvent::Released` (#4419) 2024-05-11 13:17:58 +02:00
egui_extras Remove `extra_asserts` and `extra_debug_asserts` feature flags (#4478) 2024-05-10 19:39:08 +02:00
egui_glow Enable egui_glow's winit feature on wasm (#4420) (#4421) 2024-04-29 10:33:23 +02:00
egui_plot Disable interaction for `ScrollArea` and `Plot` when UI is disabled (#4457) 2024-05-11 00:42:03 +02:00
egui_web Fix typos (#2866) 2023-04-18 15:52:45 +02:00
emath Remove `extra_asserts` and `extra_debug_asserts` feature flags (#4478) 2024-05-10 19:39:08 +02:00
epaint Remove `extra_asserts` and `extra_debug_asserts` feature flags (#4478) 2024-05-10 19:39:08 +02:00