1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-30 13:20:05 -04:00

Add web support for zoom_factor (#4260)

Before, when setting the `zoom_factor`, the website was already
enlarged, but the zoom was ignored when calculating the logical window
size and mouse position, causing an offset between the actual cursor and
selected elements. That is addressed here

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
This commit is contained in:
Justus Dieckmann
2024-03-29 11:55:49 +01:00
committed by GitHub
parent 60da4b4f65
commit 7cc98bd38e
5 changed files with 45 additions and 17 deletions

View File

@@ -60,7 +60,9 @@ impl AppRunner {
super::storage::load_memory(&egui_ctx);
egui_ctx.options_mut(|o| {
// On web, the browser controls the zoom factor:
// On web by default egui follows the zoom factor of the browser,
// and lets the browser handle the zoom shortscuts.
// A user can still zoom egui separately by calling [`egui::Context::set_zoom_factor`].
o.zoom_with_keyboard = false;
o.zoom_factor = 1.0;
});
@@ -183,7 +185,7 @@ impl AppRunner {
/// The result can be painted later with a call to [`Self::run_and_paint`] or [`Self::paint`].
pub fn logic(&mut self) {
super::resize_canvas_to_screen_size(self.canvas(), self.web_options.max_size_points);
let canvas_size = super::canvas_size_in_points(self.canvas());
let canvas_size = super::canvas_size_in_points(self.canvas(), self.egui_ctx());
let raw_input = self.input.new_frame(canvas_size);
let full_output = self.egui_ctx.run(raw_input, |egui_ctx| {