diff --git a/crates/ui-egui/src/doc_windows.rs b/crates/ui-egui/src/doc_windows.rs index 058132f839..2eb8c0e5bb 100644 --- a/crates/ui-egui/src/doc_windows.rs +++ b/crates/ui-egui/src/doc_windows.rs @@ -649,7 +649,10 @@ fn take_window_ppi(app: &mut VectorcraftApp, ctx: &egui::Context, ((uid, number) x.was_read |= matches!(shown.ppi, Some(crate::ScreenPpi::Read(_))); let size = shown.body.map(|b| b.size()); let following = view(app, win).is_some_and(|v| v.fitted && shown.fit.is_some_and(|(s, z, c)| Some(s) == size && z == v.zoom && c == v.center)); - app.settle_window_ppi(win, !(following && (first || fitted_now))); + // A zoom set as a percentage (View › Zoom, Actual Size) is not a fit, and the first reading + // keeps its percentage. + let fit = following && view(app, win).is_some_and(|v| v.fit_zoom == Some(v.zoom)); + app.settle_window_ppi(win, !(fit && (first || fitted_now))); // A view that still fits its window keeps fitting it at the zoom the new density gave it. if following && let (Some((s, _, _)), Some(v)) = (shown.fit, view(app, win)) { shown.fit = Some((s, v.zoom, v.center)); diff --git a/crates/ui-egui/src/doc_windows/tests.rs b/crates/ui-egui/src/doc_windows/tests.rs index fb803249e1..8043b1002f 100644 --- a/crates/ui-egui/src/doc_windows/tests.rs +++ b/crates/ui-egui/src/doc_windows/tests.rs @@ -1355,6 +1355,30 @@ fn a_fit_made_while_a_floating_window_is_unread_counts_from_its_last_reading() { assert_eq!(app.print_ppi_of(Some(win)), Some(110.0)); } +/// A zoom set as a percentage on a floating OS window that has not been read yet is not a fit, +/// even when the window recorded that zoom and center as its fit: the first reading of its display +/// keeps the percentage. +#[test] +fn a_zoom_set_before_a_floating_window_is_first_read_keeps_its_percentage() { + let mut app = app_with(2); + let ctx = egui::Context::default(); + frame(&mut app, &ctx, vec![]); + app.session.execute("prefs.set", &json!({"key": "displayPrintSize", "value": true})).unwrap(); + app.set_screen_ppi(Some(127.0)); + app.run("window.arrange.floatInWindow", json!({})).unwrap(); + let uid = app.session.documents()[1].uid; + let win = (1, 1); + app.run("view.setZoom", json!({"zoom": 100})).unwrap(); + let (zoom, center) = (app.views[1].zoom, app.views[1].center); + let body = egui::Rect::from_min_size(Pos2::ZERO, vec2(500.0, 400.0)); + let mut shown = + Shown { ppi: Some(crate::ScreenPpi::Read(Some(91.0))), body: Some(body), fit: Some((body.size(), zoom, center)), ..Default::default() }; + take_window_ppi(&mut app, &ctx, ((uid, 1), true), win, &mut shown); + let pct = crate::state::zoom_display_percent(app.views[1].zoom, app.print_ppi_of(Some(win))); + assert!((pct - 100.0).abs() < 1e-9, "the first reading keeps 100%: {pct}"); + assert!((app.views[1].zoom * 72.0 - 91.0).abs() < 1e-9, "an inch of the document fills an inch of its display"); +} + /// A floating OS window whose view still fits it, moved between two displays read before, keeps /// fitting it at the zoom the new density gives: the fit this frame keeps is the settled one. #[test]