Conversation
| } else { | ||
| // button event | ||
| let pos = egui::Pos2::new(event_x as f32 / scale, event_y as f32 / scale); | ||
| let pos = app.renderer.pos_from_pixels(event_x as f32, event_y as f32); |
There was a problem hiding this comment.
the renderer exposes new functions for converting positions, accounting for the scale internally
| if let Some(ref mut window) = maybe_window { | ||
| if let Some(ref mut app) = window.maybe_app { | ||
| // events sent to app every frame | ||
| app.renderer.context.set_pixels_per_point(window.dpi_scale); |
There was a problem hiding this comment.
egui's set_pixels_per_point() actually just sets the zoom factor, accounting for the native pixels per point to choose a zoom factor that gives you what you want. Here, we were effectively using the zoom factor to set the native pixels per point, which was fine until we also wanted to use the zoom factor to zoom.
| /// how the app responds to native ppp changes, such as when the app is | ||
| /// moved to a display with a different pixel density. | ||
| pub fn set_native_pixels_per_point(&mut self, native: f32) { | ||
| self.screen.pixels_per_point = native * self.context.zoom_factor(); |
There was a problem hiding this comment.
As a rule of thumb, egui uses "pixels_per_point" to refer to the product of the native pixels per point * the zoom factor. The screen descriptor is expected to use this product, not the native pixels per point.
Native clients are now expected to call this function instead of setting self.screen.pixels_per_point directly so that the zoom factor can be accounted for automatically.
| self.screen.size_in_pixels[1] as f32 / self.screen.pixels_per_point, | ||
| ), | ||
| }); | ||
| self.context |
There was a problem hiding this comment.
Before, we assigned the pixels per point, leaving the native pixels per point at the default 1.0. This assigned a zoom factor that matched the native pixels per point but could not additionally support zooming.
| let zoom = self.ctx.zoom_factor(); | ||
| if zoom != self.cfg.get_zoom_factor() { | ||
| self.cfg.set_zoom_factor(zoom); | ||
| } | ||
|
|
There was a problem hiding this comment.
note: here's where we persist the zoom factor when it changes
Fixes zoom not working on FFI clients and persists the zoom factor.
fixes #3888