Skip to content

ws: zoom#4259

Merged
tvanderstad merged 3 commits intomasterfrom
ws-zoom
Mar 12, 2026
Merged

ws: zoom#4259
tvanderstad merged 3 commits intomasterfrom
ws-zoom

Conversation

@tvanderstad
Copy link
Copy Markdown
Contributor

Fixes zoom not working on FFI clients and persists the zoom factor.

fixes #3888

} 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);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +49 to +53
let zoom = self.ctx.zoom_factor();
if zoom != self.cfg.get_zoom_factor() {
self.cfg.set_zoom_factor(zoom);
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: here's where we persist the zoom factor when it changes

@tvanderstad tvanderstad merged commit a534778 into master Mar 12, 2026
1 check passed
@tvanderstad tvanderstad deleted the ws-zoom branch March 12, 2026 05:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Zoom support

1 participant