Skip to content

Introduce global zoom_factor - #3608

Merged
emilk merged 16 commits into
masterfrom
emilk/zoom_factor
Nov 22, 2023
Merged

emilk merged 16 commits into
masterfrom
emilk/zoom_factor

Conversation

@emilk

@emilk emilk commented Nov 22, 2023

Copy link
Copy Markdown
Owner

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 force-pushed the emilk/zoom_factor branch from 3ce14e2 to 12da7c3 Compare November 22, 2023 16:16
@emilk
emilk force-pushed the emilk/zoom_factor branch from 7fe5deb to a206f0b Compare November 22, 2023 16:39
@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
@emilk
emilk deleted the emilk/zoom_factor branch November 22, 2023 19:34
@Barugon

Barugon commented Nov 24, 2023

Copy link
Copy Markdown
Contributor

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