Files
vectorcraft/crates/ui-egui/src/tests_transparencygrid.rs
T
bflatasticandClaude Opus 5.5 d527349f5a M4.20: Document Setup with bleed, transparency grid, paper and type options
File > Document Setup is a tabbed dialog over one engine command,
document.setup (no params: a query; any keys: one undo step;
document.setUnits stays as the units alias).

- General: units, bleed (four sides with a link toggle), Edit Artboards,
  Show Images in Outline Mode (greyscale pixels under the frame),
  Highlight Substituted Fonts/Glyphs (pink boxes on screen only).
- Transparency: grid size and colour presets or custom colours, Simulate
  Colored Paper, the flattener preset (built-in or saved) and Discard
  White Overprint (Overprint Preview keeps white overprints visible).
- Type: language with its quotes, Use Typographer's Quotes for the Type
  tool and Smart Punctuation, superscript/subscript size and position and
  small caps size (Character panel position/smallCaps; changing the
  setup restyles the text in the same undo step), text export (SVG text
  as text or outlines by default).
- The canvas draws a red bleed outline and the grid in the document's
  colours and cell size as one textured quad, also in rotated views; a
  white Background Contents exports raster formats opaque.

Model: Document.setup (DocSetup, defaulted, skipped when default) and
CharStyle position/small_caps; old files load unchanged.
tests_transparencygrid's helper now finds the grid by its texture (the
grid is one textured mesh instead of per-cell rectangles).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 08:28:16 +07:00

43 lines
2.1 KiB
Rust

//! The canvas draws the transparency grid behind the artboards of the documents that show it
//! (M3.88), and the View menu item follows the active document.
use serde_json::json;
use vectorcraft_engine::Session;
use crate::{VectorcraftApp, canvas, menus};
/// Whether one headless canvas frame paints the grid (one mesh textured with its tile).
fn draws_grid(app: &mut VectorcraftApp) -> bool {
let ctx = egui::Context::default();
let raw = egui::RawInput { screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(800.0, 600.0))), ..Default::default() };
let mut out = ctx.run_ui(raw, |ui| canvas::show(app, ui));
out.textures_delta.clear();
let Some(tile) = ctx.tex_manager().read().allocated().find(|(_, m)| m.name == canvas::TRANSPARENCY_GRID).map(|(id, _)| *id) else { return false };
fn uses(s: &egui::Shape, tile: egui::TextureId) -> bool {
match s {
egui::Shape::Mesh(m) => m.texture_id == tile,
egui::Shape::Vec(v) => v.iter().any(|s| uses(s, tile)),
_ => false,
}
}
out.shapes.iter().any(|c| uses(&c.shape, tile))
}
#[test]
fn the_canvas_shows_the_grid_only_for_documents_that_turn_it_on() {
let mut app = VectorcraftApp::new(Session::new(), Default::default());
app.run("file.new", json!({"width": 200, "height": 200})).unwrap();
app.run("file.new", json!({"width": 200, "height": 200})).unwrap();
assert!(!draws_grid(&mut app));
assert_eq!(menus::dynamic_label(&app, "view.transparencyGrid", ""), "Show Transparency Grid");
// The menu's id reaches the engine command.
assert_eq!(app.run("view.transparencyGrid", json!({})).unwrap(), json!({"on": true}));
assert!(draws_grid(&mut app));
assert_eq!(menus::dynamic_label(&app, "view.transparencyGrid", ""), "Hide Transparency Grid");
app.run("document.activate", json!({"index": 0})).unwrap();
assert!(!draws_grid(&mut app), "the other document keeps its own setting");
assert_eq!(menus::dynamic_label(&app, "view.transparencyGrid", ""), "Show Transparency Grid");
app.run("document.activate", json!({"index": 1})).unwrap();
assert!(draws_grid(&mut app));
}