mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-27 21:29:35 +00:00
Display Print Size: a fit made during a reading counts from the last one
A fit made in the main window while its display was being read counted from 96 points to an inch until the reading arrived, so the zoom field, the tab title and the zoom stops counted from a different density than the window's other views. The fit now counts from the last reading, and the reading, when it comes, keeps the fit's zoom, also when the views are settled again before it arrives. An app that draws no frames now still reads the displays again a minute after the last reading: it asks for a frame then. Tests now cover Actual Size after a fit that gave the same zoom, a Navigator thumbnail click, and a floating OS window's display readings (first display, a move, off every display, a fit, and docking back). docs/mcp.md now states which views keep their zoom at the first reading, that X11 and Wayland are read on Linux only, that headless sessions and the CLI count 96 points to an inch, and that the preference also applies in Pixel Preview. The progress line names the two rules that differ from the help page.
This commit is contained in:
@@ -5,13 +5,16 @@
|
||||
//!
|
||||
//! - macOS: `CGDisplayScreenSize`.
|
||||
//! - Windows: `GetDpiForMonitor`'s raw density (`windows_display_size`).
|
||||
//! - X11, XWayland included: the RandR output's width and height in millimeters.
|
||||
//! - Wayland: the physical width and height of the compositor's `wl_output` for the display.
|
||||
//! - X11 on Linux, XWayland included: the RandR output's width and height in millimeters.
|
||||
//! - Wayland on Linux: the physical width and height of the compositor's `wl_output` for the display.
|
||||
//! - Other systems: no size, so an inch takes 96 points.
|
||||
//!
|
||||
//! A display that reports no size, or a size no display has, gives `None`, and an inch then takes
|
||||
//! 96 points. While the preference is on, the displays are listed once a second while the app
|
||||
//! draws. When the list changes, a background thread reads every display's size, and a later
|
||||
//! frame takes the result. A reading that fails is tried again after [`RETRY_AFTER`] seconds.
|
||||
//! frame takes the result. A reading that fails is tried again after [`RETRY_AFTER`] seconds, and
|
||||
//! the displays are read again [`READ_AGAIN_AFTER`] seconds after the last reading; the app draws a
|
||||
//! frame for each of these when nothing else makes it draw.
|
||||
|
||||
use std::sync::mpsc::{Receiver, TryRecvError};
|
||||
|
||||
@@ -140,6 +143,11 @@ impl Tracker {
|
||||
{
|
||||
let due = (at + RETRY_AFTER).max(self.looked.map_or(0.0, |l| l + LOOK_EVERY));
|
||||
ctx.request_repaint_after(std::time::Duration::from_secs_f64((due - now).clamp(0.0, RETRY_AFTER)));
|
||||
} else if enabled && self.running.is_none() && self.read.is_some() {
|
||||
// An app that is not drawing still lists and reads the displays READ_AGAIN_AFTER seconds
|
||||
// after the last reading.
|
||||
let due = (self.read_at + READ_AGAIN_AFTER).max(self.looked.map_or(0.0, |l| l + LOOK_EVERY));
|
||||
ctx.request_repaint_after(std::time::Duration::from_secs_f64((due - now).clamp(0.0, READ_AGAIN_AFTER)));
|
||||
}
|
||||
densities
|
||||
}
|
||||
|
||||
@@ -174,8 +174,9 @@ impl VectorcraftApp {
|
||||
}
|
||||
|
||||
/// [`Self::settle_screen_ppi`] for window `w` alone. With `keep` false (a fit made for the
|
||||
/// window), the view counts from the display's reading, or from its first reading still to
|
||||
/// come, without a change of zoom.
|
||||
/// window), the view counts from the display's reading, without a change of zoom; while the
|
||||
/// display is being read, it counts from the last reading, and the reading still to come
|
||||
/// leaves its zoom alone.
|
||||
pub(crate) fn settle_window_ppi(&mut self, w: crate::doc_windows::Win, keep: bool) {
|
||||
let on = self.session.prefs.display_print_size;
|
||||
let now = self.window_ppi(w);
|
||||
@@ -185,10 +186,18 @@ impl VectorcraftApp {
|
||||
// keeps the zoom chosen meanwhile.
|
||||
if !on {
|
||||
v.shown_ppi = Some(crate::ScreenPpi::Unread);
|
||||
v.fit_unread = false;
|
||||
return;
|
||||
}
|
||||
if !keep {
|
||||
v.shown_ppi = Some(reading);
|
||||
// While the display is being read, the fit counts from the last reading, as the other
|
||||
// views there do, and the reading keeps its zoom.
|
||||
v.shown_ppi = Some(now);
|
||||
v.fit_unread = reading == crate::ScreenPpi::Unread;
|
||||
return;
|
||||
}
|
||||
// A fit made while its display is being read waits for that reading.
|
||||
if v.fit_unread && reading == crate::ScreenPpi::Unread {
|
||||
return;
|
||||
}
|
||||
// A display that has not answered yet leaves the view counting from the last one read, so
|
||||
@@ -197,11 +206,14 @@ impl VectorcraftApp {
|
||||
v.shown_ppi.get_or_insert(now);
|
||||
return;
|
||||
};
|
||||
let fitted = v.fit_zoom == Some(v.zoom);
|
||||
let before = match v.shown_ppi {
|
||||
_ if fitted && v.fit_unread => None,
|
||||
Some(crate::ScreenPpi::Read(before)) => Some(before),
|
||||
_ if v.fit_zoom == Some(v.zoom) => None,
|
||||
_ if fitted => None,
|
||||
_ => Some(None),
|
||||
};
|
||||
v.fit_unread = false;
|
||||
if let Some(before) = before
|
||||
&& before != after
|
||||
&& let (Some(b), Some(a)) = (crate::state::print_ppi(on, before), crate::state::print_ppi(on, after))
|
||||
|
||||
@@ -8641,6 +8641,8 @@ fn actual_size_and_fits_made_before_a_reading_keep_their_meaning() {
|
||||
assert!(app.set_screen_reading(crate::ScreenPpi::Unread), "the window moved to a display being read");
|
||||
app.run("view.fitArtboard", json!({})).unwrap();
|
||||
let fitted = app.view().unwrap().zoom;
|
||||
assert_eq!(app.print_ppi(), Some(127.0), "meanwhile the fit counts from the last reading, as the window's other views do");
|
||||
app.settle_screen_ppi();
|
||||
assert!(app.set_screen_ppi(Some(190.0)));
|
||||
assert_eq!(app.view().unwrap().zoom, fitted, "the fit was made for this display");
|
||||
assert!(app.set_screen_reading(crate::ScreenPpi::Unread), "and to another display being read");
|
||||
@@ -8649,6 +8651,29 @@ fn actual_size_and_fits_made_before_a_reading_keep_their_meaning() {
|
||||
assert!((app.view().unwrap().zoom * 72.0 - 110.0).abs() < 1e-9, "Actual Size there is 100%: {}", app.view().unwrap().zoom * 72.0);
|
||||
}
|
||||
|
||||
/// Actual Size chosen before the first reading is still 100% when the reading arrives, also when a
|
||||
/// fit made before it gave the view the same zoom. A zoom chosen after a fit made while the display
|
||||
/// is being read keeps its percentage when the reading arrives.
|
||||
#[test]
|
||||
fn actual_size_after_a_fit_of_the_same_zoom_stays_at_100_percent() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.session.execute("file.new", &json!({"width": 300, "height": 100})).unwrap();
|
||||
app.canvas_rect = Some(egui::Rect::from_min_size(Pos2::ZERO, vec2(460.0, 260.0)));
|
||||
app.session.execute("prefs.set", &json!({"key": "displayPrintSize", "value": true})).unwrap();
|
||||
app.run("view.fitArtboard", json!({})).unwrap();
|
||||
assert!((app.view().unwrap().zoom * 72.0 - 96.0).abs() < 1e-9, "the fit has Actual Size's zoom before any reading");
|
||||
app.run("view.actualSize", json!({})).unwrap();
|
||||
assert!(app.set_screen_ppi(Some(127.0)));
|
||||
assert!((app.view().unwrap().zoom * 72.0 - 127.0).abs() < 1e-9, "Actual Size keeps 100%: {}", app.view().unwrap().zoom * 72.0);
|
||||
assert!(app.set_screen_reading(crate::ScreenPpi::Unread), "the window moved to a display being read");
|
||||
app.run("view.fitArtboard", json!({})).unwrap();
|
||||
app.run("view.zoomIn", json!({})).unwrap();
|
||||
let shown = crate::state::zoom_display_percent(app.view().unwrap().zoom, app.print_ppi());
|
||||
assert!(app.set_screen_ppi(Some(150.0)));
|
||||
let now = crate::state::zoom_display_percent(app.view().unwrap().zoom, app.print_ppi());
|
||||
assert!((now - shown).abs() < 1e-9, "a zoom chosen after the fit keeps its percentage: {shown} → {now}");
|
||||
}
|
||||
|
||||
/// Fit Artboard in Window fits the artboard as a rotated view shows it: at 45° every corner is
|
||||
/// on the canvas and one is within the 30-point margin of an edge. At 0° the zoom is unchanged.
|
||||
#[test]
|
||||
|
||||
@@ -1294,3 +1294,40 @@ fn a_floating_window_counts_100_percent_from_its_own_display() {
|
||||
app.settle_screen_ppi_if_changed();
|
||||
assert_eq!(app.views[1].zoom, fitted, "the fit is made for the main window's display");
|
||||
}
|
||||
|
||||
/// What the host found for a floating OS window's display reaches its view: its first display and
|
||||
/// a move to another keep 100%, a window off every display is unread and keeps its zoom, a fit made
|
||||
/// in the frame its window reached a new display stays the fit, and the window drawn in the main
|
||||
/// window again counts from the main window's display.
|
||||
#[test]
|
||||
fn a_floating_os_window_takes_the_density_of_the_display_it_is_found_on() {
|
||||
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("view.actualSize", json!({})).unwrap();
|
||||
app.run("window.arrange.floatInWindow", json!({})).unwrap();
|
||||
let uid = app.session.documents()[1].uid;
|
||||
let win = (1, 1);
|
||||
let found = |ppi: Option<crate::ScreenPpi>| Shown { ppi, ..Default::default() };
|
||||
let inch = |app: &VectorcraftApp| app.views[1].zoom * 72.0;
|
||||
take_window_ppi(&mut app, &ctx, ((uid, 1), true), win, &mut found(Some(crate::ScreenPpi::Read(Some(91.0)))));
|
||||
assert!((inch(&app) - 91.0).abs() < 1e-9, "its first display keeps 100%: {}", inch(&app));
|
||||
take_window_ppi(&mut app, &ctx, ((uid, 1), true), win, &mut found(Some(crate::ScreenPpi::Read(Some(150.0)))));
|
||||
assert!((inch(&app) - 150.0).abs() < 1e-9, "and so does a move to a denser one: {}", inch(&app));
|
||||
take_window_ppi(&mut app, &ctx, ((uid, 1), true), win, &mut found(None));
|
||||
assert_eq!(screen_ppi(&app, win), Some(crate::ScreenPpi::Unread), "off every display it is unread");
|
||||
assert!((inch(&app) - 150.0).abs() < 1e-9, "and keeps its zoom");
|
||||
// A fit made in the frame the window reaches a display of another density stays the fit.
|
||||
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 mut fitted =
|
||||
Shown { ppi: Some(crate::ScreenPpi::Read(Some(110.0))), body: Some(body), fit: Some((body.size(), zoom, center)), ..Default::default() };
|
||||
take_window_ppi(&mut app, &ctx, ((uid, 1), true), win, &mut fitted);
|
||||
assert_eq!(app.views[1].zoom, zoom, "the fit was made for that display");
|
||||
app.run("view.setZoom", json!({"zoom": 100})).unwrap();
|
||||
take_window_ppi(&mut app, &ctx, ((uid, 1), false), win, &mut found(Some(crate::ScreenPpi::Read(Some(110.0)))));
|
||||
assert!((inch(&app) - 127.0).abs() < 1e-9, "drawn in the main window, 100% counts from the main window's display: {}", inch(&app));
|
||||
}
|
||||
|
||||
@@ -437,6 +437,42 @@ mod tests {
|
||||
assert!(min.is_some_and(|m| (m - lo).abs() < 1e-6) && max.is_some_and(|m| (m - hi).abs() < 1e-6), "{min:?} to {max:?}");
|
||||
}
|
||||
|
||||
/// A click on the thumbnail moves the view there and keeps the zoom percentage, here with
|
||||
/// Display Print Size at 100% Zoom on a display of 127 points to an inch.
|
||||
#[test]
|
||||
fn a_click_on_the_thumbnail_keeps_the_zoom() {
|
||||
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
|
||||
app.session.execute("prefs.set", &json!({"key": "displayPrintSize", "value": true})).unwrap();
|
||||
app.set_screen_ppi(Some(127.0));
|
||||
app.session.execute("file.new", &json!({"width": 400, "height": 300})).unwrap();
|
||||
app.canvas_rect = Some(Rect::from_min_size(pos2(0.0, 0.0), vec2(600.0, 400.0)));
|
||||
app.run("view.setZoom", json!({"zoom": 250, "center": [200, 150]})).unwrap();
|
||||
let percent = |app: &VectorcraftApp| crate::state::zoom_display_percent(app.view().unwrap().zoom, app.print_ppi());
|
||||
let before = (app.view().unwrap().center, percent(&app));
|
||||
let ctx = egui::Context::default();
|
||||
let run = |app: &mut VectorcraftApp, events: Vec<egui::Event>| {
|
||||
let mut out = ctx.run_ui(egui::RawInput { events, ..Default::default() }, |ui| show(app, ui));
|
||||
out.textures_delta.clear();
|
||||
out
|
||||
};
|
||||
let pasteboard = Tokens::get(&ctx).pasteboard;
|
||||
let thumb = run(&mut app, vec![])
|
||||
.shapes
|
||||
.iter()
|
||||
.find_map(|c| match &c.shape {
|
||||
egui::Shape::Rect(r) if r.fill == pasteboard => Some(r.rect),
|
||||
_ => None,
|
||||
})
|
||||
.expect("the thumbnail");
|
||||
let at = thumb.left_top() + thumb.size() * 0.25;
|
||||
let button = |pressed| egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() };
|
||||
run(&mut app, vec![egui::Event::PointerMoved(at)]);
|
||||
run(&mut app, vec![button(true)]);
|
||||
run(&mut app, vec![button(false)]);
|
||||
assert_ne!(app.view().unwrap().center, before.0, "the click moved the view");
|
||||
assert!((percent(&app) - before.1).abs() < 1e-9, "and kept {}%: {}%", before.1, percent(&app));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn thumb_mapping_roundtrip() {
|
||||
let region = DRect::new(0.0, 0.0, 200.0, 100.0);
|
||||
|
||||
@@ -54,6 +54,11 @@ pub struct View {
|
||||
/// percentage keeps its percentage then ([`crate::VectorcraftApp::settle_screen_ppi`]).
|
||||
#[serde(skip)]
|
||||
pub(crate) fit_zoom: Option<f64>,
|
||||
/// The fit that gave [`Self::fit_zoom`] was made while the view's display was being read: the
|
||||
/// view counts from the last reading meanwhile, and the reading, when it comes, leaves the zoom
|
||||
/// alone while the view still has it.
|
||||
#[serde(skip)]
|
||||
pub(crate) fit_unread: bool,
|
||||
}
|
||||
|
||||
impl Default for View {
|
||||
@@ -67,6 +72,7 @@ impl Default for View {
|
||||
outline: false,
|
||||
shown_ppi: None,
|
||||
fit_zoom: None,
|
||||
fit_unread: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -94,6 +100,7 @@ impl View {
|
||||
artboard: 0,
|
||||
outline: false,
|
||||
shown_ppi: None,
|
||||
fit_unread: false,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
+11
-7
@@ -8288,13 +8288,17 @@ control channel's `ui.drag` scrubs), `showHomeScreen` (on by default: the Home s
|
||||
off, an empty window, and the Home button or `app.home` still shows the screen), `autoCollapseIconPanels` (off by
|
||||
default: on, a click away from a panel popped out of the icon column puts it away), `displayPrintSize` (on by
|
||||
default, also for saved preferences without the key: View › Actual Size / `view.actualSize` shows one document inch
|
||||
in an inch of the display that shows the document's window, measured from the physical size macOS, Windows, X11 or
|
||||
the Wayland compositor reports for that display. A document under the tabs counts from the main window's display,
|
||||
and a document floating in an OS window of its own counts from that window's display. A window that moves to a
|
||||
display of another density keeps its zoom percentage. Where the system reports no size, as on the web, or a size no
|
||||
display has, an inch is 96 screen points. A view whose zoom counted from 96 points keeps its zoom when the first
|
||||
measurement arrives. Off, 100% is one document point per screen point, and the desktop app does not measure the
|
||||
displays. While it is on, `ui.inspect` gives `screenPpi`, the measured density of the main window's display, and
|
||||
in an inch of the display that shows the document's window, measured from the physical size macOS, Windows, or on
|
||||
Linux X11 or the Wayland compositor reports for that display. A document under the tabs counts from the main
|
||||
window's display, and a document floating in an OS window of its own counts from that window's display. It also
|
||||
applies in Pixel Preview. A window that moves to a display of another density keeps its zoom percentage. Where no
|
||||
display is measured (the web build, the headless backend, `vectorcraft-cli`, and the desktop app on other systems),
|
||||
where the system reports no size, or where it reports a size no display has, an inch is 96 screen points, so Actual
|
||||
Size there shows 4/3 screen points per document point. When the first measurement of a display
|
||||
arrives, a view that still has the zoom a fit or the document's saved view gave it keeps that zoom, and any other
|
||||
view keeps its zoom percentage. Off, 100% is one document point per screen point, and the desktop app does not
|
||||
measure the displays. While it is on, `ui.inspect` gives `screenPpi`, the measured density of the main window's
|
||||
display, and
|
||||
`printPpi`, the points an inch takes at 100% in the current window; both are null while it is off). `uiScaling`
|
||||
scales the interface and not the art: a zoom shows the art at the same size at every UI Scaling. The tool shortcut
|
||||
preference `holdToolKeys` also needs the desktop app. It is on by default: a single-key tool shortcut held for 0.25 s
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user