From 3d43c98c9e8462bbb1a55eb9fd48121490403ea2 Mon Sep 17 00:00:00 2001 From: loki5512344 Date: Sun, 25 Oct 2026 10:23:15 +0100 Subject: [PATCH] test(client): allow rendering UI snapshots at higher pixel density --- src/ui_smoke.rs | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/ui_smoke.rs b/src/ui_smoke.rs index a04abee..da229f6 100644 --- a/src/ui_smoke.rs +++ b/src/ui_smoke.rs @@ -12,18 +12,29 @@ impl Platform for HeadlessPlatform { } } +/// Pixel density of the headless snapshots, 1 by default. `VNOX_UI_SNAPSHOT_SCALE=2` renders +/// the 1280x800 window at 2560x1600 for crisp screenshots. +fn snapshot_scale() -> u32 { + std::env::var("VNOX_UI_SNAPSHOT_SCALE") + .ok() + .and_then(|value| value.parse::().ok()) + .map_or(1, |value| value.clamp(1, 4)) +} + fn render(window: &MainWindow, surface: &MinimalSoftwareWindow, name: &str) { window.window().request_redraw(); - let mut pixels = SharedPixelBuffer::::new(1280, 800); + let scale = snapshot_scale(); + let (width, height) = (1280 * scale, 800 * scale); + let mut pixels = SharedPixelBuffer::::new(width, height); assert!(surface.draw_if_needed(|renderer| { - renderer.render(pixels.make_mut_slice(), 1280); + renderer.render(pixels.make_mut_slice(), width as usize); })); if let Some(directory) = std::env::var_os("VNOX_UI_SNAPSHOT_DIR") { std::fs::create_dir_all(&directory).unwrap(); let mut file = std::fs::File::create(std::path::PathBuf::from(directory).join(format!("{name}.ppm"))) .unwrap(); - write!(file, "P6\n1280 800\n255\n").unwrap(); + write!(file, "P6\n{width} {height}\n255\n").unwrap(); file.write_all(pixels.as_bytes()).unwrap(); } } @@ -94,7 +105,13 @@ fn native_shell_keeps_drafts_settings_and_models_between_ticks() { }; sync(); window.show().unwrap(); - surface.set_size(PhysicalSize::new(1280, 800)); + let scale = snapshot_scale(); + window + .window() + .dispatch_event(WindowEvent::ScaleFactorChanged { + scale_factor: scale as f32, + }); + surface.set_size(PhysicalSize::new(1280 * scale, 800 * scale)); render(&window, &surface, "native-chat"); // Drive the real native editor, not only the generated callback surface.