From 1de14d2bdd8e968ad9185e3bffe9aecbb1f3f02b Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 22 Nov 2026 11:23:44 -0800 Subject: [PATCH] Display Print Size: a floating window keeps its settled fit while a modal is open A floating OS window whose view fits it and whose display changed density while a dialog or other modal was open settled its zoom, but the window kept the fit from before the change, so the next resize did not fit the view again. The window now keeps the settled zoom and center as its fit while a modal blocks it too. --- crates/ui-egui/src/doc_windows.rs | 13 +++++++++-- crates/ui-egui/src/doc_windows/tests.rs | 30 +++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/doc_windows.rs b/crates/ui-egui/src/doc_windows.rs index 2eb8c0e5bb..9af012b6ee 100644 --- a/crates/ui-egui/src/doc_windows.rs +++ b/crates/ui-egui/src/doc_windows.rs @@ -525,7 +525,7 @@ pub(crate) fn show(app: &mut VectorcraftApp, ctx: &egui::Context) { let Some(win) = find(app, (w.uid, w.view)) else { continue }; let raised = raise == Some((w.uid, w.view)); let mut shown = if native { os_window(app, ctx, &w, (win, blocked), raised) } else { app_window(app, ctx, &w, (win, blocked), raised) }; - take_window_ppi(app, ctx, ((w.uid, w.view), native), win, &mut shown); + take_window_fit(app, ctx, ((w.uid, w.view), native), win, &mut shown); if blocked { continue; } @@ -537,7 +537,6 @@ pub(crate) fn show(app: &mut VectorcraftApp, ctx: &egui::Context) { } x.focused = shown.focused; x.body = shown.body; - x.fit = shown.fit; } over_strip |= shown.over_strip; if shown.close { @@ -613,6 +612,16 @@ fn body(app: &mut VectorcraftApp, ui: &mut egui::Ui, (win, blocked): (Win, bool) (pressed, rect, fit) } +/// Takes the density of the display that `shown`, floating window `key`'s window `win`, was found on +/// ([`take_window_ppi`]), and keeps the fit `shown` holds after it as the window's fit, also while a +/// modal blocks the window. +fn take_window_fit(app: &mut VectorcraftApp, ctx: &egui::Context, ((uid, number), os): ((u64, u32), bool), win: Win, shown: &mut Shown) { + take_window_ppi(app, ctx, ((uid, number), os), win, shown); + if let Some(x) = app.ui.floating.iter_mut().find(|x| x.uid == uid && x.view == number) { + x.fit = shown.fit; + } +} + /// Takes the density of the display that `shown`, floating window `key`'s ([`views::key`]) window /// `win`, was found on, and whether it is an OS window of its own (`os`), and settles the views /// when the density changed ([`VectorcraftApp::settle_window_ppi`]). A view that still has the diff --git a/crates/ui-egui/src/doc_windows/tests.rs b/crates/ui-egui/src/doc_windows/tests.rs index 8043b1002f..977f061f42 100644 --- a/crates/ui-egui/src/doc_windows/tests.rs +++ b/crates/ui-egui/src/doc_windows/tests.rs @@ -1405,3 +1405,33 @@ fn a_fitted_floating_window_moved_to_another_density_keeps_fitting() { assert_ne!(v.zoom, zoom, "the move to a denser display keeps the zoom percentage"); assert_eq!(moved.fit, Some((body.size(), v.zoom, v.center)), "and the fit kept is the settled zoom"); } + +/// A floating OS window whose view fits it, moved to a display of another density while a modal is +/// open, keeps the settled zoom and center as its fit, so the next resize fits it again. +#[test] +fn a_fitted_floating_window_moved_while_a_modal_is_open_keeps_the_settled_fit() { + 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); + take_window_fit(&mut app, &ctx, ((uid, 1), true), win, &mut Shown { ppi: Some(crate::ScreenPpi::Read(Some(91.0))), ..Default::default() }); + app.run("view.fitArtboard", json!({})).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 fit = Some((body.size(), zoom, center)); + if let Some(x) = app.ui.floating.iter_mut().find(|x| x.uid == uid && x.view == 1) { + x.fit = fit; + } + app.ui.about = true; + assert!(crate::panel_docking::modal_open(&app, &ctx), "a modal is open"); + let mut moved = Shown { ppi: Some(crate::ScreenPpi::Read(Some(150.0))), body: Some(body), fit, ..Default::default() }; + take_window_fit(&mut app, &ctx, ((uid, 1), true), win, &mut moved); + let v = app.views[1]; + assert_ne!(v.zoom, zoom, "the move to a denser display keeps the zoom percentage"); + let kept = app.ui.floating.iter().find(|x| x.uid == uid && x.view == 1).and_then(|x| x.fit); + assert_eq!(kept, Some((body.size(), v.zoom, v.center)), "the window keeps the settled zoom and center as its fit"); +}