egui-winit: Receive window scale factor and size via events #7760
+105
−97
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.
We found in our application (with custom
eguirenderer) that thescreen_rectinRawInputwas mismatching with thewinitevents that we processed earlier (in particular on resize on MacOS, which raises a lot of small size changes).One of the contributing factors was
egui-winitreading theWindowsize and scale factor over and over again separate from processed events, causing a mismatch on some platforms because this value would already change ahead of consuming aResizedevent. Secondly, some existing event processing may rely on this value being consistent with the event stream.There is currently no guarantee -at least I don't see it in the documentation- that
winitensures thatinner_size()will always return a consistent value until the user has consumed aResizedevent. This gets worse when certain functions (likeupdate_viewport_info()) are possibly called on a separate thread because bothegui::Contextandwinit::Windoware thread-safe.Those also have an extra draw-back of roundtripping to the event loop on the main thread to query these values, as a
Windowis not actually thread-safe on all platforms.This is still opened as a draft because it has not been tested on all platforms, and there are far more odd calls to
window.inner_size(),window.outer_size()andwindow.scale_factor()than anticipated which might all suffer from the same behaviour; not all immediately have access to the latest state inRawInputthough.Secondly it was surprising to see the viewport code that updates
native_pixels_per_pointin a very disconnected way fromRawInput::pixels_per_point, which I'd like to understand better before making any more changes here. It seems like this was already all carefully crafted (ie. #4211) and battle-tested to circumnavigate the inconsistency issues above... 😕