Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce global zoom_factor #3608

Merged
merged 16 commits into from
Nov 22, 2023
Merged

Introduce global zoom_factor #3608

merged 16 commits into from
Nov 22, 2023

Conversation

emilk
Copy link
Owner

@emilk emilk commented Nov 22, 2023

You can now zoom any egui app by pressing Cmd+Plus, Cmd+Minus or Cmd+0, just like in a browser. This will change the current zoom_factor (default 1.0) which is persisted in the egui memory, and is the same for all viewports.
You can turn off the keyboard shortcuts with ctx.options_mut(|o| o.zoom_with_keyboard = false);

zoom_factor can also be explicitly read/written with ctx.zoom_factor() and ctx.set_zoom_factor().

This redefines pixels_per_point as zoom_factor * native_pixels_per_point, where native_pixels_per_point is whatever is the native scale factor for the monitor that the current viewport is in.

This adds some complexity to the interaction with winit, since we need to know the current zoom_factor in a lot of places, because all egui IO is done in ui points. I'm pretty sure this PR fixes a bunch of subtle bugs though that used to be in this code.

egui::gui_zoom::zoom_with_keyboard_shortcuts is now gone, and is no longer needed, as this is now the default behavior.

Context::set_pixels_per_point is still there, but it is recommended you use Context::set_zoom_factor instead.

@emilk emilk added the egui label Nov 22, 2023
@emilk emilk marked this pull request as ready for review November 22, 2023 17:46
@emilk emilk merged commit 63e48dc into master Nov 22, 2023
35 checks passed
@emilk emilk deleted the emilk/zoom_factor branch November 22, 2023 19:34
@Barugon
Copy link
Contributor

Barugon commented Nov 24, 2023

I really feel that this should not be enabled by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Introduce a persistent zoom_factor
2 participants