mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-04 13:02:50 -05:00
Merge main into feat/vector-3d-materials
This commit is contained in:
commit
0f3aee366c
37 files changed
+1300
-320
No files matched your search
Generated
+183
-181
File diff suppressed because it is too large.
Load diff
+52
-52
@@ -4,59 +4,59 @@ members = ["crates/*", "apps/*", "xtask"]
|
||||
default-members = ["crates/*", "apps/vectorcraft", "apps/vectorcraft-cli", "xtask"]
|
||||
|
||||
[workspace.package]
|
||||
version = "0.25.0"
|
||||
version = "0.25.1"
|
||||
edition = "2024"
|
||||
license = "MIT OR Apache-2.0"
|
||||
rust-version = "1.95"
|
||||
|
||||
[workspace.dependencies]
|
||||
craft-cms = { git = "https://github.com/storytold/craft-libs", rev = "186a229c8da8db5916f8a863dfd894f1879af735" }
|
||||
craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "186a229c8da8db5916f8a863dfd894f1879af735", default-features = false, features = ["interpret", "write"] }
|
||||
craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "186a229c8da8db5916f8a863dfd894f1879af735" }
|
||||
craft-proof = { git = "https://github.com/storytold/craft-libs", rev = "186a229c8da8db5916f8a863dfd894f1879af735" }
|
||||
craft-cms = { git = "https://github.com/storytold/craft-libs", rev = "2680a3b3fe464c7afa3d260b33a828fa94e12f6d" }
|
||||
craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "2680a3b3fe464c7afa3d260b33a828fa94e12f6d", default-features = false, features = ["interpret", "write"] }
|
||||
craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2680a3b3fe464c7afa3d260b33a828fa94e12f6d" }
|
||||
craft-proof = { git = "https://github.com/storytold/craft-libs", rev = "2680a3b3fe464c7afa3d260b33a828fa94e12f6d" }
|
||||
# Language packs: the Craft apps' shared font store installs them (#4936).
|
||||
craft-font-store = { git = "https://github.com/storytold/craft-libs", rev = "186a229c8da8db5916f8a863dfd894f1879af735" }
|
||||
craft-font-catalog = { git = "https://github.com/storytold/craft-libs", rev = "186a229c8da8db5916f8a863dfd894f1879af735" }
|
||||
craft-font-store = { git = "https://github.com/storytold/craft-libs", rev = "2680a3b3fe464c7afa3d260b33a828fa94e12f6d" }
|
||||
craft-font-catalog = { git = "https://github.com/storytold/craft-libs", rev = "2680a3b3fe464c7afa3d260b33a828fa94e12f6d" }
|
||||
# The `.vectorcraft` envelope: its members, version, embedded images and the data after the JSON.
|
||||
craft-vectorcraft-format = { git = "https://github.com/storytold/craft-libs", rev = "186a229c8da8db5916f8a863dfd894f1879af735" }
|
||||
craft-gzip = { git = "https://github.com/storytold/craft-libs", rev = "186a229c8da8db5916f8a863dfd894f1879af735" }
|
||||
craft-vectorcraft-format = { git = "https://github.com/storytold/craft-libs", rev = "2680a3b3fe464c7afa3d260b33a828fa94e12f6d" }
|
||||
craft-gzip = { git = "https://github.com/storytold/craft-libs", rev = "2680a3b3fe464c7afa3d260b33a828fa94e12f6d" }
|
||||
# `.pcraft` documents: their manifest, full-size composite, preview, layer pixels and ICC profile.
|
||||
craft-doc = { git = "https://github.com/storytold/craft-libs", rev = "186a229c8da8db5916f8a863dfd894f1879af735", features = ["pcraft-pixels"] }
|
||||
craft-doc = { git = "https://github.com/storytold/craft-libs", rev = "2680a3b3fe464c7afa3d260b33a828fa94e12f6d", features = ["pcraft-pixels"] }
|
||||
# Native Affinity documents (craft-libs#914).
|
||||
craft-affinity = { git = "https://github.com/storytold/craft-libs", rev = "186a229c8da8db5916f8a863dfd894f1879af735" }
|
||||
craft-affinity = { git = "https://github.com/storytold/craft-libs", rev = "2680a3b3fe464c7afa3d260b33a828fa94e12f6d" }
|
||||
# Bounded CDR (v1-v27) and CMX (32-bit) reader (craft-libs#778).
|
||||
craft-cdr = { git = "https://github.com/storytold/craft-libs", rev = "186a229c8da8db5916f8a863dfd894f1879af735" }
|
||||
craft-cdr = { git = "https://github.com/storytold/craft-libs", rev = "2680a3b3fe464c7afa3d260b33a828fa94e12f6d" }
|
||||
# SVG parsing, limits, SVGZ and writer (craft-libs#778).
|
||||
craft-svg = { git = "https://github.com/storytold/craft-libs", rev = "186a229c8da8db5916f8a863dfd894f1879af735", features = ["tree"] }
|
||||
craft-mime = { git = "https://github.com/storytold/craft-libs", rev = "186a229c8da8db5916f8a863dfd894f1879af735" }
|
||||
craft-svg = { git = "https://github.com/storytold/craft-libs", rev = "2680a3b3fe464c7afa3d260b33a828fa94e12f6d", features = ["tree"] }
|
||||
craft-mime = { git = "https://github.com/storytold/craft-libs", rev = "2680a3b3fe464c7afa3d260b33a828fa94e12f6d" }
|
||||
# EPS container, previews, ASCII85 and DSC comments (craft-libs#778).
|
||||
craft-eps = { git = "https://github.com/storytold/craft-libs", rev = "186a229c8da8db5916f8a863dfd894f1879af735" }
|
||||
craft-eps = { git = "https://github.com/storytold/craft-libs", rev = "2680a3b3fe464c7afa3d260b33a828fa94e12f6d" }
|
||||
# DXF tags, reader and writer (craft-libs#778, #926, #927).
|
||||
craft-plotter = { git = "https://github.com/storytold/craft-libs", rev = "186a229c8da8db5916f8a863dfd894f1879af735" }
|
||||
craft-dxf = { git = "https://github.com/storytold/craft-libs", rev = "186a229c8da8db5916f8a863dfd894f1879af735" }
|
||||
craft-plotter = { git = "https://github.com/storytold/craft-libs", rev = "2680a3b3fe464c7afa3d260b33a828fa94e12f6d" }
|
||||
craft-dxf = { git = "https://github.com/storytold/craft-libs", rev = "2680a3b3fe464c7afa3d260b33a828fa94e12f6d" }
|
||||
# WMF, EMF and EMF+ reader (craft-libs#778).
|
||||
craft-metafile = { git = "https://github.com/storytold/craft-libs", rev = "186a229c8da8db5916f8a863dfd894f1879af735" }
|
||||
craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "186a229c8da8db5916f8a863dfd894f1879af735" }
|
||||
craft-image-codecs = { git = "https://github.com/storytold/craft-libs", rev = "186a229c8da8db5916f8a863dfd894f1879af735" }
|
||||
craft-gif = { git = "https://github.com/storytold/craft-libs", rev = "186a229c8da8db5916f8a863dfd894f1879af735" }
|
||||
craft-tiff = { git = "https://github.com/storytold/craft-libs", rev = "186a229c8da8db5916f8a863dfd894f1879af735" }
|
||||
craft-ps = { git = "https://github.com/storytold/craft-libs", rev = "186a229c8da8db5916f8a863dfd894f1879af735", default-features = false, features = ["read", "write"] }
|
||||
craft-psd = { git = "https://github.com/storytold/craft-libs", rev = "186a229c8da8db5916f8a863dfd894f1879af735" }
|
||||
craft-stream-codecs = { git = "https://github.com/storytold/craft-libs", rev = "186a229c8da8db5916f8a863dfd894f1879af735" }
|
||||
craft-jxl = { git = "https://github.com/storytold/craft-libs", rev = "186a229c8da8db5916f8a863dfd894f1879af735" }
|
||||
craft-codepage = { git = "https://github.com/storytold/craft-libs", rev = "186a229c8da8db5916f8a863dfd894f1879af735" }
|
||||
craft-metafile = { git = "https://github.com/storytold/craft-libs", rev = "2680a3b3fe464c7afa3d260b33a828fa94e12f6d" }
|
||||
craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "2680a3b3fe464c7afa3d260b33a828fa94e12f6d" }
|
||||
craft-image-codecs = { git = "https://github.com/storytold/craft-libs", rev = "2680a3b3fe464c7afa3d260b33a828fa94e12f6d" }
|
||||
craft-gif = { git = "https://github.com/storytold/craft-libs", rev = "2680a3b3fe464c7afa3d260b33a828fa94e12f6d" }
|
||||
craft-tiff = { git = "https://github.com/storytold/craft-libs", rev = "2680a3b3fe464c7afa3d260b33a828fa94e12f6d" }
|
||||
craft-ps = { git = "https://github.com/storytold/craft-libs", rev = "2680a3b3fe464c7afa3d260b33a828fa94e12f6d", default-features = false, features = ["read", "write"] }
|
||||
craft-psd = { git = "https://github.com/storytold/craft-libs", rev = "2680a3b3fe464c7afa3d260b33a828fa94e12f6d" }
|
||||
craft-stream-codecs = { git = "https://github.com/storytold/craft-libs", rev = "2680a3b3fe464c7afa3d260b33a828fa94e12f6d" }
|
||||
craft-jxl = { git = "https://github.com/storytold/craft-libs", rev = "2680a3b3fe464c7afa3d260b33a828fa94e12f6d" }
|
||||
craft-codepage = { git = "https://github.com/storytold/craft-libs", rev = "2680a3b3fe464c7afa3d260b33a828fa94e12f6d" }
|
||||
# The metallic-roughness BRDF and environment light the 3D effects' Roughness and Metallic shade with.
|
||||
craft-pbr = { git = "https://github.com/storytold/craft-libs", rev = "186a229c8da8db5916f8a863dfd894f1879af735" }
|
||||
craft-pbr = { git = "https://github.com/storytold/craft-libs", rev = "2680a3b3fe464c7afa3d260b33a828fa94e12f6d" }
|
||||
# The framework facade (`craft::ui`, `craft::settings`, `craft::platform`, ...). No default features: each crate names
|
||||
# the members it imports.
|
||||
craft = { git = "https://github.com/storytold/craft-libs", rev = "186a229c8da8db5916f8a863dfd894f1879af735" }
|
||||
craft = { git = "https://github.com/storytold/craft-libs", rev = "2680a3b3fe464c7afa3d260b33a828fa94e12f6d" }
|
||||
# Below the egui layer, so not through the facade: the colour harmony rules and their settings (craft-color-ui
|
||||
# without its `ui` feature), the colour type they work in, and the craft-fonts tables the text crate's build writes.
|
||||
craft-color-ui = { git = "https://github.com/storytold/craft-libs", rev = "186a229c8da8db5916f8a863dfd894f1879af735" }
|
||||
craft-theme = { git = "https://github.com/storytold/craft-libs", rev = "186a229c8da8db5916f8a863dfd894f1879af735" }
|
||||
craft-fonts-build = { git = "https://github.com/storytold/craft-libs", rev = "186a229c8da8db5916f8a863dfd894f1879af735" }
|
||||
craft-color-ui = { git = "https://github.com/storytold/craft-libs", rev = "2680a3b3fe464c7afa3d260b33a828fa94e12f6d" }
|
||||
craft-theme = { git = "https://github.com/storytold/craft-libs", rev = "2680a3b3fe464c7afa3d260b33a828fa94e12f6d" }
|
||||
craft-fonts-build = { git = "https://github.com/storytold/craft-libs", rev = "2680a3b3fe464c7afa3d260b33a828fa94e12f6d" }
|
||||
# Nightly profile isolation, launch protocol, and security fence.
|
||||
craft-nightly = { git = "https://github.com/storytold/craft-libs", rev = "1f6c3a21f85ed96f8fd4ddd5a959d4e1edbedb24" }
|
||||
craft-nightly = { git = "https://github.com/storytold/craft-libs", rev = "2680a3b3fe464c7afa3d260b33a828fa94e12f6d" }
|
||||
# internal
|
||||
vectorcraft-geom = { path = "crates/geom" }
|
||||
vectorcraft-color = { path = "crates/color" }
|
||||
@@ -196,22 +196,22 @@ lto = "thin"
|
||||
codegen-units = 1
|
||||
|
||||
[patch.crates-io]
|
||||
hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "186a229c8da8db5916f8a863dfd894f1879af735" }
|
||||
hayro-interpret = { git = "https://github.com/storytold/craft-libs", rev = "186a229c8da8db5916f8a863dfd894f1879af735" }
|
||||
hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "186a229c8da8db5916f8a863dfd894f1879af735" }
|
||||
hayro-cmap = { git = "https://github.com/storytold/craft-libs", rev = "186a229c8da8db5916f8a863dfd894f1879af735" }
|
||||
hayro-postscript = { git = "https://github.com/storytold/craft-libs", rev = "186a229c8da8db5916f8a863dfd894f1879af735" }
|
||||
krilla = { git = "https://github.com/storytold/craft-libs", rev = "186a229c8da8db5916f8a863dfd894f1879af735" }
|
||||
linesweeper = { git = "https://github.com/storytold/craft-libs", rev = "186a229c8da8db5916f8a863dfd894f1879af735" }
|
||||
ecolor = { git = "https://github.com/storytold/egui.git", rev = "14c39fed181756be6f357c284354e0ab55b64443" }
|
||||
emath = { git = "https://github.com/storytold/egui.git", rev = "14c39fed181756be6f357c284354e0ab55b64443" }
|
||||
epaint = { git = "https://github.com/storytold/egui.git", rev = "14c39fed181756be6f357c284354e0ab55b64443" }
|
||||
epaint_default_fonts = { git = "https://github.com/storytold/egui.git", rev = "14c39fed181756be6f357c284354e0ab55b64443" }
|
||||
egui = { git = "https://github.com/storytold/egui.git", rev = "14c39fed181756be6f357c284354e0ab55b64443" }
|
||||
egui-winit = { git = "https://github.com/storytold/egui.git", rev = "14c39fed181756be6f357c284354e0ab55b64443" }
|
||||
egui-wgpu = { git = "https://github.com/storytold/egui.git", rev = "14c39fed181756be6f357c284354e0ab55b64443" }
|
||||
egui_glow = { git = "https://github.com/storytold/egui.git", rev = "14c39fed181756be6f357c284354e0ab55b64443" }
|
||||
egui_extras = { git = "https://github.com/storytold/egui.git", rev = "14c39fed181756be6f357c284354e0ab55b64443" }
|
||||
egui_kittest = { git = "https://github.com/storytold/egui.git", rev = "14c39fed181756be6f357c284354e0ab55b64443" }
|
||||
eframe = { git = "https://github.com/storytold/egui.git", rev = "14c39fed181756be6f357c284354e0ab55b64443" }
|
||||
winit = { git = "https://github.com/storytold/winit.git", rev = "a517b3846ee8457d84ee4975110bfda6797c44dc" }
|
||||
hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "2680a3b3fe464c7afa3d260b33a828fa94e12f6d" }
|
||||
hayro-interpret = { git = "https://github.com/storytold/craft-libs", rev = "2680a3b3fe464c7afa3d260b33a828fa94e12f6d" }
|
||||
hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "2680a3b3fe464c7afa3d260b33a828fa94e12f6d" }
|
||||
hayro-cmap = { git = "https://github.com/storytold/craft-libs", rev = "2680a3b3fe464c7afa3d260b33a828fa94e12f6d" }
|
||||
hayro-postscript = { git = "https://github.com/storytold/craft-libs", rev = "2680a3b3fe464c7afa3d260b33a828fa94e12f6d" }
|
||||
krilla = { git = "https://github.com/storytold/craft-libs", rev = "2680a3b3fe464c7afa3d260b33a828fa94e12f6d" }
|
||||
linesweeper = { git = "https://github.com/storytold/craft-libs", rev = "2680a3b3fe464c7afa3d260b33a828fa94e12f6d" }
|
||||
ecolor = { git = "https://github.com/storytold/egui.git", rev = "07c20531f89717e461c0f387dd1f9649553f9321" }
|
||||
emath = { git = "https://github.com/storytold/egui.git", rev = "07c20531f89717e461c0f387dd1f9649553f9321" }
|
||||
epaint = { git = "https://github.com/storytold/egui.git", rev = "07c20531f89717e461c0f387dd1f9649553f9321" }
|
||||
epaint_default_fonts = { git = "https://github.com/storytold/egui.git", rev = "07c20531f89717e461c0f387dd1f9649553f9321" }
|
||||
egui = { git = "https://github.com/storytold/egui.git", rev = "07c20531f89717e461c0f387dd1f9649553f9321" }
|
||||
egui-winit = { git = "https://github.com/storytold/egui.git", rev = "07c20531f89717e461c0f387dd1f9649553f9321" }
|
||||
egui-wgpu = { git = "https://github.com/storytold/egui.git", rev = "07c20531f89717e461c0f387dd1f9649553f9321" }
|
||||
egui_glow = { git = "https://github.com/storytold/egui.git", rev = "07c20531f89717e461c0f387dd1f9649553f9321" }
|
||||
egui_extras = { git = "https://github.com/storytold/egui.git", rev = "07c20531f89717e461c0f387dd1f9649553f9321" }
|
||||
egui_kittest = { git = "https://github.com/storytold/egui.git", rev = "07c20531f89717e461c0f387dd1f9649553f9321" }
|
||||
eframe = { git = "https://github.com/storytold/egui.git", rev = "07c20531f89717e461c0f387dd1f9649553f9321" }
|
||||
winit = { git = "https://github.com/storytold/winit.git", rev = "0dfcec0eb62fda5904137a63a6dd0c3d83295f45" }
|
||||
@@ -28,7 +28,7 @@ egui_extras = { workspace = true }
|
||||
# `wgpu` pulls egui-wgpu's defaults: WebGPU plus the WebGL2 fallback.
|
||||
eframe = { workspace = true, features = ["default_fonts", "wgpu", "accesskit"] }
|
||||
# The page command API (storytold/craft-libs#413): the request plumbing behind window.vectorcraft.
|
||||
craft-web-api = { git = "https://github.com/storytold/craft-libs", rev = "186a229c8da8db5916f8a863dfd894f1879af735", version = "0.1.0" }
|
||||
craft-web-api = { git = "https://github.com/storytold/craft-libs", rev = "2680a3b3fe464c7afa3d260b33a828fa94e12f6d", version = "0.1.0" }
|
||||
|
||||
wasm-bindgen = "0.2"
|
||||
serde_json = { workspace = true }
|
||||
|
||||
@@ -112,6 +112,43 @@ use prefs::{load_prefs, log_dir, open_store, prefs_enabled};
|
||||
const DEFAULT_SIZE: [f32; 2] = [1440.0, 900.0];
|
||||
const MIN_SIZE: [f32; 2] = [800.0, 500.0];
|
||||
|
||||
/// Apply the saved main-window placement before the first frame. On a first launch the
|
||||
/// framework maximizes the window when its default size would not fit the current screen.
|
||||
fn restore_main_window(window: &winit::window::Window, store: &Store, legacy: Option<vectorcraft_ui_egui::state::LegacyWindow>, wayland: bool) {
|
||||
use craft::behavior::placement::{Defaults, Placement, place};
|
||||
use craft::behavior::{Monitor, MonitorKey};
|
||||
use winit::dpi::{LogicalSize, PhysicalPosition};
|
||||
|
||||
let handles: Vec<_> = window.available_monitors().collect();
|
||||
let monitors: Vec<_> = handles
|
||||
.iter()
|
||||
.map(|monitor| {
|
||||
let size = monitor.size();
|
||||
let size = [size.width, size.height];
|
||||
let position = monitor.position();
|
||||
Monitor::new(MonitorKey::new(monitor.name().unwrap_or_default(), size), [position.x, position.y], size, monitor.scale_factor() as f32)
|
||||
})
|
||||
.collect();
|
||||
let home = window.current_monitor().or_else(|| window.primary_monitor()).and_then(|monitor| handles.iter().position(|m| *m == monitor));
|
||||
let defaults = Defaults::new(DEFAULT_SIZE, MIN_SIZE).with_no_position(wayland);
|
||||
let saved = store.get(craft::window::restore::MAIN).or_else(|| {
|
||||
let old = legacy?;
|
||||
let mut placement = Placement::new(old.size, window.scale_factor() as f32);
|
||||
placement.position_px = old.pos;
|
||||
placement.maximized = old.maximized;
|
||||
placement.repaired()
|
||||
});
|
||||
let placement = place(saved.as_ref(), &monitors, home, &defaults);
|
||||
if let Some([x, y]) = placement.position_px {
|
||||
window.set_outer_position(PhysicalPosition::new(x, y));
|
||||
}
|
||||
let [width, height] = placement.normal.size;
|
||||
let _ = window.request_inner_size(LogicalSize::new(width, height));
|
||||
if placement.maximized {
|
||||
window.set_maximized(true);
|
||||
}
|
||||
}
|
||||
|
||||
/// The window, Dock, taskbar and app-switcher icon (`assets/app-icon/`, see its README). macOS gets
|
||||
/// the version with Apple's transparent margin; elsewhere the full-bleed tile. The app ID matches
|
||||
/// `packaging/linux/ai.storyteller.vectorcraft.desktop` so Wayland docks find the launcher icon.
|
||||
@@ -781,9 +818,13 @@ fn main() -> std::process::ExitCode {
|
||||
Box::new(move |cc| {
|
||||
let ctx = &cc.egui_ctx;
|
||||
let winit_window = cc.winit_window().cloned();
|
||||
let placement = placement_store();
|
||||
if let Some(window) = &winit_window {
|
||||
restore_main_window(window, &placement, settings.lock().get().ui.legacy_window, wayland);
|
||||
}
|
||||
let spec = InstallSpec::new(shell_info, Arc::new(SystemWindows))
|
||||
.app_id(vectorcraft_ui_egui::os_window::app_id())
|
||||
.placement(Arc::new(Mutex::new(placement_store())))
|
||||
.placement(Arc::new(Mutex::new(placement)))
|
||||
.frame(decision);
|
||||
let spec = match start_pen(&winit_window) {
|
||||
Some(pen) => spec.pen(pen),
|
||||
@@ -798,7 +839,7 @@ fn main() -> std::process::ExitCode {
|
||||
};
|
||||
let (files, file_panels) = file_service(wake, folders);
|
||||
let files = Arc::new(files);
|
||||
craft::host::Host::builder(AppInfo {
|
||||
let host = craft::host::Host::builder(AppInfo {
|
||||
id: vectorcraft_ui_egui::os_window::SETTINGS_APP_ID,
|
||||
name: vectorcraft_ui_egui::os_window::name(),
|
||||
version: vectorcraft_ui_egui::os_window::version(),
|
||||
@@ -806,7 +847,8 @@ fn main() -> std::process::ExitCode {
|
||||
.i18n(vectorcraft_ui_egui::i18n::shared())
|
||||
.settings(Arc::new(settings.clone()))
|
||||
.files(files.clone())
|
||||
.install(ctx);
|
||||
.build();
|
||||
host.clone().install(ctx);
|
||||
let mut session = Session::new();
|
||||
// The profiles loaded before come back before the preferences name any of them.
|
||||
prefs_dir::attach_profile_store(&mut session);
|
||||
@@ -831,6 +873,7 @@ fn main() -> std::process::ExitCode {
|
||||
prefs_dir::attach_proof_setups(&mut session);
|
||||
prefs_dir::attach_script_data(&mut session);
|
||||
let mut app = VectorcraftApp::new(session, services(winit_window.clone()));
|
||||
app.host = Arc::new(host);
|
||||
app.adopt_context(&cc.egui_ctx);
|
||||
// A nightly is updated by the Launcher: it never checks for a stable release, which
|
||||
// would install this program's own updater over the nightly build.
|
||||
|
||||
@@ -267,6 +267,8 @@ thread_local! {
|
||||
pub(crate) static FORMS_MADE: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
|
||||
/// Tests: how many times [`outlines`] made the outline of a highlighted object on this thread.
|
||||
pub(crate) static OUTLINES_MADE: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
|
||||
/// Tests: how many objects [`matches`] looked at on this thread.
|
||||
pub(crate) static OBJECTS_WALKED: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
|
||||
}
|
||||
|
||||
impl Form {
|
||||
@@ -527,6 +529,8 @@ fn matches(s: &Session, o: &Options) -> Result<Vec<(NodeId, Affine)>> {
|
||||
let mut cache = st.global_edit_forms.0.borrow_mut();
|
||||
let mut pass = cache.forms.pass();
|
||||
super::select::walk_selectable(d, st.isolation, |n| {
|
||||
#[cfg(test)]
|
||||
OBJECTS_WALKED.with(|c| c.set(c.get() + 1));
|
||||
if n.id == *id || out.len() >= MAX_MEMBERS {
|
||||
return false;
|
||||
}
|
||||
@@ -1075,34 +1079,178 @@ pub fn highlights(s: &Session) -> std::sync::Arc<Highlights> {
|
||||
out
|
||||
}
|
||||
|
||||
/// [`similar`]'s outlines as of a document revision and the options they were found with.
|
||||
pub type SimilarCache = std::cell::RefCell<Option<(u64, Options, std::sync::Arc<Highlights>)>>;
|
||||
/// [`similar`]'s outlines as of a document revision, with what they were found from.
|
||||
pub type SimilarCache = std::cell::RefCell<Option<Similar>>;
|
||||
|
||||
/// [`similar`]'s outlines and what they were found from.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Similar {
|
||||
revision: u64,
|
||||
options: Options,
|
||||
/// The document, the one selected object and the isolated object they were found with.
|
||||
doc: Arc<Document>,
|
||||
key: NodeId,
|
||||
isolation: Option<NodeId>,
|
||||
out: Arc<Highlights>,
|
||||
}
|
||||
|
||||
/// Before Global Edit starts: with one supported object selected, the outlines of the other
|
||||
/// objects Start Global Edit would take now with the session's Global Edit Options, so the canvas
|
||||
/// shows them as soon as the object is selected. None while an interaction (a drag) is in
|
||||
/// progress, or when fewer than two objects would be taken. Kept per document revision and
|
||||
/// options, as finding them walks the whole document.
|
||||
/// options, as finding them walks the whole document. After an edit that replaced only the
|
||||
/// selected object, and left what the others are compared with as it was (a move), the outlines
|
||||
/// found before are kept without a walk.
|
||||
pub fn similar(s: &Session) -> std::sync::Arc<Highlights> {
|
||||
let Some(st) = s.active() else { return NO_HIGHLIGHTS.clone() };
|
||||
if st.global_edit.is_some() || st.interaction.is_some() || st.selection.objects.len() != 1 {
|
||||
// Global Edit is refused while an object of a dynamic symbol instance's art is selected.
|
||||
if st.global_edit.is_some() || st.interaction.is_some() || st.selection.objects.len() != 1 || super::edit::refuse_symbol_part(s).is_err() {
|
||||
return NO_HIGHLIGHTS.clone();
|
||||
}
|
||||
let o = &s.global_edit_options;
|
||||
if let Some((rev, opts, out)) = &*st.similar_outlines.borrow()
|
||||
&& *rev == st.revision
|
||||
&& opts == o
|
||||
let key = st.selection.objects[0];
|
||||
if let Some(c) = &mut *st.similar_outlines.borrow_mut()
|
||||
&& c.options == *o
|
||||
&& c.key == key
|
||||
&& c.isolation == st.isolation
|
||||
&& (c.revision == st.revision || Arc::ptr_eq(&c.doc, &st.doc) || only_key_changed(&c.doc, &st.doc, key))
|
||||
{
|
||||
return out.clone();
|
||||
c.revision = st.revision;
|
||||
c.doc = st.doc.clone();
|
||||
return c.out.clone();
|
||||
}
|
||||
let out = Highlights::new(match matches(s, o) {
|
||||
Ok(m) if m.len() >= 2 => outlines(st, &m),
|
||||
_ => vec![],
|
||||
});
|
||||
*st.similar_outlines.borrow_mut() = Some((st.revision, o.clone(), out.clone()));
|
||||
*st.similar_outlines.borrow_mut() =
|
||||
Some(Similar { revision: st.revision, options: o.clone(), doc: st.doc.clone(), key, isolation: st.isolation, out: out.clone() });
|
||||
out
|
||||
}
|
||||
|
||||
/// Would [`matches`] find the same objects in `now` as in `then`, with `key` selected in both?
|
||||
/// True when the layers differ only in `key` and in the layers and groups that hold it (the same
|
||||
/// apart from their contents), `key` is compared with the others as before ([`same_key`]), and the
|
||||
/// rest of the document is the same. A group that holds `key` is never like it (its form holds
|
||||
/// `key`'s and more), so the walk looks into it before and after alike.
|
||||
fn only_key_changed(then: &Document, now: &Document, key: NodeId) -> bool {
|
||||
let mut found = None;
|
||||
let same_symbol = |a: &vectorcraft_doc::Symbol, b: &vectorcraft_doc::Symbol| {
|
||||
a.name == b.name && a.dynamic == b.dynamic && (Arc::ptr_eq(&a.art, &b.art) || a.art == b.art)
|
||||
};
|
||||
// Everything else in the document (artboards, symbol settings, editing modes) as it was: the
|
||||
// symbols' art is compared on its own, as one copy when no edit changed it.
|
||||
let rest = |d: &Document| {
|
||||
let mut d = d.clone();
|
||||
d.layers.clear();
|
||||
d.symbols.clear();
|
||||
d
|
||||
};
|
||||
if then.symbols.len() != now.symbols.len()
|
||||
|| !then.symbols.iter().zip(&now.symbols).all(|(a, b)| same_symbol(a, b))
|
||||
|| rest(then) != rest(now)
|
||||
|| !changed_only(&then.layers, &now.layers, key, &mut found)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
found.is_none_or(|(a, b)| same_key(a, b, &now.symbol_boxes()))
|
||||
}
|
||||
|
||||
/// Do `then` and `now` hold the same objects, apart from `key` and the layers and groups on the way
|
||||
/// to it? `found` takes the two versions of `key` when it changed.
|
||||
fn changed_only<'a>(then: &'a [Arc<Node>], now: &'a [Arc<Node>], key: NodeId, found: &mut Option<(&'a Node, &'a Node)>) -> bool {
|
||||
if then.len() != now.len() {
|
||||
return false;
|
||||
}
|
||||
then.iter().zip(now).all(|(a, b)| {
|
||||
if Arc::ptr_eq(a, b) {
|
||||
return true;
|
||||
}
|
||||
if a.id != b.id {
|
||||
return false;
|
||||
}
|
||||
if a.id == key {
|
||||
return found.replace((a, b)).is_none();
|
||||
}
|
||||
match (holder_children(a), holder_children(b)) {
|
||||
(Some(x), Some(y)) => same_holder(a, b) && changed_only(x, y, key, found),
|
||||
_ => false,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// The objects in a layer or a group.
|
||||
fn holder_children(n: &Node) -> Option<&[Arc<Node>]> {
|
||||
match &n.kind {
|
||||
NodeKind::Layer { children, .. } | NodeKind::Group { children, .. } => Some(children),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Are two versions of a layer or a group the same apart from the objects in them?
|
||||
fn same_holder(a: &Node, b: &Node) -> bool {
|
||||
let Node { id, name, visible, locked, opacity, blend, isolate, knockout, knockout_shape, appearance, kind, bbox_angle, extras } = a;
|
||||
let kinds = match (kind, &b.kind) {
|
||||
(
|
||||
NodeKind::Layer { color, template, printable, children: _, clip, preview, dim_images },
|
||||
NodeKind::Layer { color: c, template: t, printable: p, children: _, clip: cl, preview: pv, dim_images: di },
|
||||
) => color == c && template == t && printable == p && clip == cl && preview == pv && dim_images == di,
|
||||
(NodeKind::Group { children: _, clip }, NodeKind::Group { children: _, clip: c }) => clip == c,
|
||||
_ => false,
|
||||
};
|
||||
kinds
|
||||
&& *id == b.id
|
||||
&& *name == b.name
|
||||
&& *visible == b.visible
|
||||
&& *locked == b.locked
|
||||
&& *opacity == b.opacity
|
||||
&& *blend == b.blend
|
||||
&& *isolate == b.isolate
|
||||
&& *knockout == b.knockout
|
||||
&& *knockout_shape == b.knockout_shape
|
||||
&& *appearance == b.appearance
|
||||
&& *bbox_angle == b.bbox_angle
|
||||
&& *extras == b.extras
|
||||
}
|
||||
|
||||
/// How far apart two versions of the selected object's form may lie, in its unit box, and how much
|
||||
/// their sizes may differ (relative), for [`similar`] to keep the objects found like the first: a
|
||||
/// millionth of [`SAME`]. A move leaves the form the same but for rounding (the form is placed in
|
||||
/// its unit box by a transform that includes the move), well within this.
|
||||
const KEPT: f64 = 1e-12;
|
||||
|
||||
/// Are two versions of the selected object compared with the other objects in the same way by
|
||||
/// [`matches`]: the same form in a box of the same size and the same geometric size (a perspective
|
||||
/// projection changes that alone), within [`KEPT`], and the same fill and stroke in each object in
|
||||
/// them?
|
||||
fn same_key(a: &Node, b: &Node, symbols: &vectorcraft_doc::SymbolBoxes<'_>) -> bool {
|
||||
let near = |x: f64, y: f64| (x - y).abs() <= KEPT * x.abs().max(y.abs()).max(1.0);
|
||||
fn same_look(a: &Node, b: &Node) -> bool {
|
||||
fill_of(a) == fill_of(b)
|
||||
&& stroke_of(a) == stroke_of(b)
|
||||
&& match (a.children(), b.children()) {
|
||||
(Some(x), Some(y)) => x.len() == y.len() && x.iter().zip(y).all(|(p, q)| same_look(p, q)),
|
||||
(x, y) => x.is_none() && y.is_none(),
|
||||
}
|
||||
}
|
||||
if !(supported(a) && supported(b)) {
|
||||
return false;
|
||||
}
|
||||
let (Some(f), Some(g)) = (Form::of(a), Form::of(b)) else { return false };
|
||||
let (fl, gl) = (f.frame.as_coeffs(), g.frame.as_coeffs());
|
||||
let sizes = match (a.geometric_bounds_with(symbols), b.geometric_bounds_with(symbols)) {
|
||||
(Some(x), Some(y)) => near(x.width(), y.width()) && near(x.height(), y.height()),
|
||||
(x, y) => x.is_none() && y.is_none(),
|
||||
};
|
||||
f.tag == g.tag
|
||||
&& f.symbols == g.symbols
|
||||
&& f.points.len() == g.points.len()
|
||||
&& f.points.iter().zip(&g.points).all(|(p, q)| p.distance(*q) <= KEPT)
|
||||
&& fl[..4].iter().zip(&gl[..4]).all(|(x, y)| near(*x, *y))
|
||||
&& sizes
|
||||
&& same_look(a, b)
|
||||
}
|
||||
|
||||
/// The outlines of `members` that are not selected, hold no selected object and sit inside no
|
||||
/// selected object, in their layer's color.
|
||||
fn outlines(st: &crate::DocState, members: &[(NodeId, Affine)]) -> Outlines {
|
||||
|
||||
@@ -192,7 +192,11 @@ fn apply_transform_moving_guides(
|
||||
if copy { vec![] } else { ids }
|
||||
} else {
|
||||
let kept = if copy { preview_copies(s, &ids, with_guides, below)? } else { None };
|
||||
s.edit(label, |d, sel| {
|
||||
// A move of whole objects, not of copies (which `reindex` covers): the document before it,
|
||||
// and the moved objects as the transform left them, for [`moved_by`] to check after the edit.
|
||||
let from = (objects && !areas && !reindex && c[..4] == [1.0, 0.0, 0.0, 1.0]).then(|| s.doc().map(|st| st.doc.clone())).transpose()?;
|
||||
let mut held: Vec<(NodeId, Arc<Node>)> = vec![];
|
||||
let targets = s.edit(label, |d, sel| {
|
||||
let mut targets = match &kept {
|
||||
// The document becomes the snapshot with the kept copies, untransformed, and the
|
||||
// loop below transforms only the copies.
|
||||
@@ -229,6 +233,10 @@ fn apply_transform_moving_guides(
|
||||
transform_node(n, xf, sc, objects);
|
||||
}
|
||||
}
|
||||
// Holding them makes any later change to them copy them first, which `moved_by` sees.
|
||||
if from.is_some() {
|
||||
held = targets.iter().filter_map(|id| Some((*id, node_arc(d, paths.get(id)?)?))).collect();
|
||||
}
|
||||
if objects {
|
||||
for id in &targets {
|
||||
super::pixelgrid::keep_compound_aligned(d, *id, sc);
|
||||
@@ -248,7 +256,10 @@ fn apply_transform_moving_guides(
|
||||
targets.extend(d.transform_ruler_guides(sel, xf));
|
||||
}
|
||||
Ok(targets)
|
||||
})?
|
||||
})?;
|
||||
let st = s.doc_mut()?;
|
||||
st.moved = from.and_then(|from| moved_by(&from, st, &held, Vec2::new(c[4], c[5])));
|
||||
targets
|
||||
};
|
||||
let st = s.doc_mut()?;
|
||||
if st.interaction.is_none() {
|
||||
@@ -266,6 +277,47 @@ fn apply_transform_moving_guides(
|
||||
Ok(json!({ "ids": ids.iter().map(|i| i.0).collect::<Vec<_>>() }))
|
||||
}
|
||||
|
||||
/// The node at index path `path` of `d`, shared.
|
||||
fn node_arc(d: &Document, path: &[usize]) -> Option<Arc<Node>> {
|
||||
let (first, rest) = path.split_first()?;
|
||||
let mut cur = d.layers.get(*first)?;
|
||||
for &i in rest {
|
||||
cur = cur.children()?.get(i)?;
|
||||
}
|
||||
Some(cur.clone())
|
||||
}
|
||||
|
||||
/// The [`crate::Moved`] of a move by `by` that took `from` to the document of `st`, given the moved
|
||||
/// objects as the transform left them (`held`). `None` unless every moved object is still that
|
||||
/// node, none is a member of a blend (whose spine follows its members), and every object the
|
||||
/// selection shows, the key object and the key anchor's object included, is a moved object or
|
||||
/// inside one. A pass after the transform that changes a moved object, such as the one that snaps
|
||||
/// moved pixel-aligned objects to the pixel grid again ([`super::pixelgrid::refresh`]), copies it
|
||||
/// first, so it is no longer that node.
|
||||
fn moved_by(from: &Arc<Document>, st: &crate::DocState, held: &[(NodeId, Arc<Node>)], by: Vec2) -> Option<crate::Moved> {
|
||||
let d = &st.doc;
|
||||
let unchanged = |(id, n): &(NodeId, Arc<Node>)| d.node(*id).is_some_and(|now| std::ptr::eq(now, Arc::as_ptr(n)));
|
||||
if held.is_empty() || !held.iter().all(unchanged) {
|
||||
return None;
|
||||
}
|
||||
let in_blend = |id: NodeId| d.parent_of(id).and_then(|p| d.node(p)).is_some_and(|p| matches!(p.kind, NodeKind::Blend { .. }));
|
||||
if held.iter().any(|(id, _)| in_blend(*id)) {
|
||||
return None;
|
||||
}
|
||||
let mut moved = std::collections::HashSet::new();
|
||||
for (_, n) in held {
|
||||
n.walk(&mut |c| {
|
||||
moved.insert(c.id);
|
||||
});
|
||||
}
|
||||
let sel = &st.selection;
|
||||
let mut shown = sel.objects.iter().copied().chain(sel.key).chain(sel.key_anchor.map(|(id, _)| id));
|
||||
if !shown.all(|id| moved.contains(&id)) {
|
||||
return None;
|
||||
}
|
||||
Some(crate::Moved { from: Arc::downgrade(from), to: Arc::downgrade(d), by, selection: sel.clone() })
|
||||
}
|
||||
|
||||
/// Returns the copies of `roots` for a transform or a perspective edit with `copy` in an interaction
|
||||
/// whose document is still its snapshot, as in a preview ([`Session::preview`] puts the snapshot
|
||||
/// back first). These are the copies the interaction keeps when they were made of that snapshot for
|
||||
|
||||
@@ -203,6 +203,24 @@ pub struct DocState {
|
||||
/// The selected objects as [`crate::Session::select`] last checked them or the proxies last
|
||||
/// read them, with the document they were checked in ([`SelectionRecord`]). Not saved.
|
||||
pub(crate) selection_record: Option<SelectionRecord>,
|
||||
/// The last move of the selected objects that changed nothing else they show ([`Moved`]).
|
||||
/// Not saved.
|
||||
pub moved: Option<Moved>,
|
||||
}
|
||||
|
||||
/// A move of whole objects that took document `from` to document `to`: each object the selection
|
||||
/// shows, the key object and the key anchor included, is the one in `from` moved by `by`, and
|
||||
/// nothing else they are drawn from changed (no member snapped to the pixel grid, no blend spine
|
||||
/// they follow, no pass after the edit). A view that drew the selection of `from` can
|
||||
/// move what it drew by `by` instead of building it again. It holds the documents as
|
||||
/// [`SelectionRecord::doc`] holds one, so a document changed in place no longer matches.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Moved {
|
||||
pub from: std::sync::Weak<Document>,
|
||||
pub to: std::sync::Weak<Document>,
|
||||
pub by: vectorcraft_geom::Vec2,
|
||||
/// The selection the move was made with, which is also the selection after it.
|
||||
pub selection: Selection,
|
||||
}
|
||||
|
||||
/// A selection of objects alone ([`objects_only`]) with the document it was checked or read in:
|
||||
@@ -522,6 +540,7 @@ impl DocState {
|
||||
measured_in_own: None,
|
||||
inline_resolved: None,
|
||||
selection_record: None,
|
||||
moved: None,
|
||||
}
|
||||
}
|
||||
/// The [`SelectionRecord`] of the selection now: `None` when the document or the selected
|
||||
|
||||
@@ -512,7 +512,7 @@ pub(crate) use command_sets::SELECTS_GIVEN_IDS;
|
||||
#[cfg(test)]
|
||||
use command_sets::given_ids;
|
||||
pub use command_sets::{DRAWS_SHAPE, FIT_ACTIVE_ARTBOARD, ON_ACTIVE_ARTBOARD, waits_for_plugin_loads, waits_for_tool_edit};
|
||||
pub use doc_state::{DocState, LayersReveal, OpenRows, RecalledSelection, WindowView};
|
||||
pub use doc_state::{DocState, LayersReveal, Moved, OpenRows, RecalledSelection, WindowView};
|
||||
pub use error::{EngineError, READ_ONLY_LOCATION, Result, SCRIPT_BUSY};
|
||||
#[cfg(test)]
|
||||
use history::history_budget_for;
|
||||
|
||||
@@ -118,6 +118,7 @@ mod livecorners;
|
||||
mod maskview;
|
||||
pub(super) mod menucmds;
|
||||
mod mesh_picks;
|
||||
mod moved;
|
||||
mod nativefile;
|
||||
mod newart;
|
||||
mod newdoc;
|
||||
|
||||
@@ -137,7 +137,7 @@ fn after_an_edit_only_the_changed_objects_are_compared_again_from_scratch() {
|
||||
s.execute("object.move", &json!({"dx": 5, "dy": 0})).unwrap();
|
||||
let before = made();
|
||||
assert_eq!(highlights(&s).len(), 39);
|
||||
assert_eq!(since(before), (1, 0), "the selected object only: the copies are unchanged");
|
||||
assert_eq!(since(before), (2, 0), "the selected object before and after the move only: the copies are unchanged");
|
||||
sel(&mut s, &[copies[0]]);
|
||||
s.execute("object.scale", &json!({"sx": 200, "sy": 100})).unwrap();
|
||||
sel(&mut s, &[copies[1]]);
|
||||
@@ -156,6 +156,207 @@ fn after_an_edit_only_the_changed_objects_are_compared_again_from_scratch() {
|
||||
assert_eq!(crate::cmd::globaledit::match_count(&s), 38);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_edit_to_the_selected_object_alone_keeps_the_similar_objects_without_a_walk() {
|
||||
use crate::cmd::globaledit::{OBJECTS_WALKED, highlights};
|
||||
let walked = || OBJECTS_WALKED.with(std::cell::Cell::get);
|
||||
// The outlines `highlights` gives, and how many objects it looked at for them.
|
||||
let shown = |s: &Session| {
|
||||
let before = walked();
|
||||
let out = highlights(s);
|
||||
(out, walked() - before)
|
||||
};
|
||||
// The outlines in each layer color.
|
||||
let paths = |h: &crate::cmd::globaledit::Highlights| h.groups.iter().map(|(c, p)| (*c, p.to_vec())).collect::<Vec<_>>();
|
||||
// The outlines a walk finds, the options set again so that nothing is kept.
|
||||
let fresh = |s: &mut Session| {
|
||||
let size = s.global_edit_options.size;
|
||||
s.execute("select.globalEditOptions", &json!({"size": !size})).unwrap();
|
||||
highlights(s);
|
||||
s.execute("select.globalEditOptions", &json!({"size": size})).unwrap();
|
||||
let before = walked();
|
||||
let out = highlights(s);
|
||||
assert!(walked() > before, "a walk");
|
||||
paths(&out)
|
||||
};
|
||||
let mut s = session();
|
||||
let key = rect(&mut s, 0.37, 0.91, 10.3, 10.3);
|
||||
let copies: Vec<NodeId> = (1..40).map(|i| rect(&mut s, 20.0 * f64::from(i % 20), 100.0 + 20.0 * f64::from(i / 20), 10.3, 10.3)).collect();
|
||||
sel(&mut s, &[key]);
|
||||
let (first, n) = shown(&s);
|
||||
assert_eq!(first.len(), 39);
|
||||
assert!(n >= 40, "the first preview walks every object");
|
||||
|
||||
// The move rounds the form in its unit box differently; the same objects are like it.
|
||||
s.execute("object.move", &json!({"dx": 3.17, "dy": 1.29})).unwrap();
|
||||
let (out, n) = shown(&s);
|
||||
assert_eq!(n, 0, "a move of the selected object alone compares the others as before");
|
||||
assert!(std::sync::Arc::ptr_eq(&out, &first), "the canvas keeps the outlines it stroked");
|
||||
assert_eq!(paths(&out), fresh(&mut s));
|
||||
|
||||
// Another object moved: it is shown where it is now.
|
||||
sel(&mut s, &[copies[0]]);
|
||||
s.execute("object.move", &json!({"dx": 300, "dy": 0})).unwrap();
|
||||
sel(&mut s, &[key]);
|
||||
let (out, n) = shown(&s);
|
||||
assert!(n > 0, "another object changed");
|
||||
let moved = node(&s, copies[0]).stroke_path().unwrap();
|
||||
assert!(out.groups.iter().flat_map(|(_, p)| p.iter()).any(|p| *p == moved), "the moved copy is shown where it is now");
|
||||
assert_eq!(paths(&out), fresh(&mut s));
|
||||
|
||||
// The selected object took another shape: none of the squares is like it.
|
||||
s.execute("object.scale", &json!({"sx": 200, "sy": 100})).unwrap();
|
||||
let (out, n) = shown(&s);
|
||||
assert!(n > 0 && out.is_empty(), "the widened square matches none of the squares");
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
assert_eq!(shown(&s).0.len(), 39);
|
||||
|
||||
// With Size, a larger copy of the selected square is another size.
|
||||
s.execute("select.globalEditOptions", &json!({"size": true})).unwrap();
|
||||
assert_eq!(shown(&s).0.len(), 39);
|
||||
s.execute("object.scale", &json!({"sx": 200, "sy": 200})).unwrap();
|
||||
let (out, n) = shown(&s);
|
||||
assert!(n > 0 && out.is_empty(), "the enlarged square has the size of none of them");
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
s.execute("select.globalEditOptions", &json!({"size": false})).unwrap();
|
||||
|
||||
// With Appearance, another fill on the selected square leaves the others out.
|
||||
s.execute("select.globalEditOptions", &json!({"appearance": true})).unwrap();
|
||||
assert_eq!(shown(&s).0.len(), 39);
|
||||
s.execute("paint.setFill", &json!({"color": "#12ab34"})).unwrap();
|
||||
let (out, n) = shown(&s);
|
||||
assert!(n > 0 && out.is_empty(), "the others have another fill now");
|
||||
s.execute("select.globalEditOptions", &json!({"appearance": false})).unwrap();
|
||||
|
||||
// Reflected, the selected kite keeps its size but is no longer like its copy.
|
||||
let lone = kite(&mut s, 0.0, 500.0, 1.0);
|
||||
kite(&mut s, 200.0, 500.0, 1.0);
|
||||
sel(&mut s, &[lone]);
|
||||
assert_eq!(shown(&s).0.len(), 1);
|
||||
s.execute("object.reflect", &json!({"axis": "vertical"})).unwrap();
|
||||
let (out, n) = shown(&s);
|
||||
assert!(n > 0 && out.is_empty(), "a reflected copy is not like it");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn another_layer_locked_leaves_its_objects_out_of_the_similar_objects() {
|
||||
use crate::cmd::globaledit::highlights;
|
||||
let mut s = session();
|
||||
let key = rect(&mut s, 0.0, 0.0, 10.0, 10.0);
|
||||
rect(&mut s, 20.0, 0.0, 10.0, 10.0);
|
||||
let other = NodeId(s.execute("layer.new", &json!({})).unwrap()["id"].as_u64().unwrap());
|
||||
rect(&mut s, 40.0, 0.0, 10.0, 10.0);
|
||||
rect(&mut s, 60.0, 0.0, 10.0, 10.0);
|
||||
sel(&mut s, &[key]);
|
||||
assert_eq!(highlights(&s).len(), 3);
|
||||
s.execute("layer.setProps", &json!({"id": other.0, "locked": true})).unwrap();
|
||||
assert_eq!(s.doc().unwrap().selection.objects, [key]);
|
||||
assert_eq!(highlights(&s).len(), 1, "the squares on the locked layer are left out");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_new_artboard_brings_the_objects_on_it_into_the_similar_objects() {
|
||||
use crate::cmd::globaledit::highlights;
|
||||
let mut s = session();
|
||||
let key = rect(&mut s, 0.0, 0.0, 10.0, 10.0);
|
||||
rect(&mut s, 20.0, 0.0, 10.0, 10.0);
|
||||
rect(&mut s, 1100.0, 100.0, 10.0, 10.0);
|
||||
s.execute("select.globalEditOptions", &json!({"includeCanvas": false})).unwrap();
|
||||
sel(&mut s, &[key]);
|
||||
assert_eq!(highlights(&s).len(), 1, "the square on the canvas is left out");
|
||||
s.execute("artboard.new", &json!({"x": 1000, "y": 0, "width": 400, "height": 400})).unwrap();
|
||||
sel(&mut s, &[key]);
|
||||
assert_eq!(highlights(&s).len(), 2, "the square is on an artboard now");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_symbol_redrawn_brings_its_instances_onto_the_artboard() {
|
||||
use crate::cmd::globaledit::highlights;
|
||||
let mut s = session();
|
||||
let r = rect(&mut s, 0.0, 0.0, 40.0, 40.0);
|
||||
let key = NodeId(s.execute("symbol.new", &json!({"ids": [r.0], "name": "Tile"})).unwrap()["id"].as_u64().unwrap());
|
||||
s.execute("symbol.place", &json!({"name": "Tile", "x": 1000, "y": 300})).unwrap();
|
||||
s.execute("select.globalEditOptions", &json!({"includeCanvas": false})).unwrap();
|
||||
sel(&mut s, &[key]);
|
||||
assert!(highlights(&s).is_empty(), "the other instance is on the canvas");
|
||||
// The symbol's art drawn 400 pt to the left: the other instance lies on the artboard.
|
||||
let st = s.doc_mut().unwrap();
|
||||
let d = std::sync::Arc::make_mut(&mut st.doc);
|
||||
let art = std::sync::Arc::make_mut(&mut d.symbols[0].art);
|
||||
art.transform(Affine::translate((-400.0, 0.0)), vectorcraft_doc::Scaling::default());
|
||||
st.revision += 1;
|
||||
assert_eq!(highlights(&s).len(), 1, "the other instance is on the artboard now");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_symbol_instance_put_in_perspective_has_another_size() {
|
||||
use crate::cmd::globaledit::highlights;
|
||||
let mut s = session();
|
||||
s.execute("perspective.grid.preset", &json!({"kind": 2})).unwrap();
|
||||
let r = rect(&mut s, 450.0, 300.0, 100.0, 100.0);
|
||||
let key = NodeId(s.execute("symbol.new", &json!({"ids": [r.0], "name": "Tile"})).unwrap()["id"].as_u64().unwrap());
|
||||
s.execute("symbol.place", &json!({"name": "Tile", "x": 100, "y": 100})).unwrap();
|
||||
s.execute("select.globalEditOptions", &json!({"size": true})).unwrap();
|
||||
sel(&mut s, &[key]);
|
||||
assert_eq!(highlights(&s).len(), 1);
|
||||
let size = |s: &Session| bounds(s, key).size();
|
||||
let was = size(&s);
|
||||
s.execute("perspective.attach", &json!({"ids": [key.0], "plane": "right"})).unwrap();
|
||||
sel(&mut s, &[key]);
|
||||
assert_ne!(size(&s), was, "the projection changes the instance's size");
|
||||
assert!(highlights(&s).is_empty(), "the other instance has the size the selected one had");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_part_of_a_dynamic_symbol_instance_selected_shows_no_similar_objects() {
|
||||
use crate::cmd::globaledit::highlights;
|
||||
let mut s = session();
|
||||
let a = rect(&mut s, 0.0, 0.0, 10.0, 10.0);
|
||||
let b = rect(&mut s, 20.0, 0.0, 10.0, 10.0);
|
||||
let inst = NodeId(s.execute("symbol.new", &json!({"name": "Pair", "ids": [a.0, b.0], "type": "dynamic"})).unwrap()["id"].as_u64().unwrap());
|
||||
s.execute("symbol.place", &json!({"name": "Pair", "x": 300, "y": 300})).unwrap();
|
||||
sel(&mut s, &[inst]);
|
||||
assert_eq!(highlights(&s).len(), 1);
|
||||
s.execute("symbol.instance.selectPart", &json!({"id": inst.0, "path": [1]})).unwrap();
|
||||
assert_eq!(s.doc().unwrap().selection.objects, [inst]);
|
||||
assert!(highlights(&s).is_empty(), "Global Edit does not take a part of the art");
|
||||
sel(&mut s, &[inst]);
|
||||
assert_eq!(highlights(&s).len(), 1, "the whole instance again");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_group_selected_inside_a_group_keeps_its_similar_objects_after_a_move() {
|
||||
use crate::cmd::globaledit::{OBJECTS_WALKED, highlights};
|
||||
let walked = || OBJECTS_WALKED.with(std::cell::Cell::get);
|
||||
let mut s = session();
|
||||
let group = |s: &mut Session, ids: &[NodeId]| {
|
||||
sel(s, ids);
|
||||
NodeId(s.execute("object.group", &json!({})).unwrap()["id"].as_u64().unwrap())
|
||||
};
|
||||
// A group of two squares inside an outer group with a third square, and a copy of both: the
|
||||
// copy's inner group is like the selected inner group.
|
||||
let a = [rect(&mut s, 0.0, 0.0, 10.0, 10.0), rect(&mut s, 20.0, 0.0, 10.0, 10.0)];
|
||||
let inner = group(&mut s, &a);
|
||||
let third = rect(&mut s, 40.0, 0.0, 10.0, 10.0);
|
||||
let outer = group(&mut s, &[inner, third]);
|
||||
let b = [rect(&mut s, 0.0, 100.0, 10.0, 10.0), rect(&mut s, 20.0, 100.0, 10.0, 10.0)];
|
||||
let inner_copy = group(&mut s, &b);
|
||||
let third_copy = rect(&mut s, 40.0, 100.0, 10.0, 10.0);
|
||||
group(&mut s, &[inner_copy, third_copy]);
|
||||
sel(&mut s, &[inner]);
|
||||
let first = highlights(&s);
|
||||
assert_eq!(crate::cmd::globaledit::match_count(&s), 2, "the copy's inner group; the outer group {outer} holds the selected one");
|
||||
assert!(!first.is_empty());
|
||||
s.execute("object.move", &json!({"dx": 5, "dy": 0})).unwrap();
|
||||
let before = walked();
|
||||
assert!(std::sync::Arc::ptr_eq(&highlights(&s), &first));
|
||||
assert_eq!(walked(), before, "the outer group changed with the selected group only");
|
||||
s.execute("select.globalEditOptions", &json!({"size": true})).unwrap();
|
||||
s.execute("select.globalEditOptions", &json!({"size": false})).unwrap();
|
||||
assert_eq!(highlights(&s).groups, first.groups, "a walk finds the same");
|
||||
assert!(walked() > before);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_canvas_highlights_similar_objects_before_the_start_with_the_selection_tool_only() {
|
||||
let mut s = session();
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
//! [`DocState::moved`]: a move of whole objects names the documents before and after it and how far
|
||||
//! it went, and only when every object the selection shows is the one before it, moved that far.
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use serde_json::{Value, json};
|
||||
use vectorcraft_geom::Vec2;
|
||||
|
||||
use crate::*;
|
||||
|
||||
fn session() -> Session {
|
||||
let mut s = Session::new();
|
||||
s.execute("file.new", &json!({"width": 400, "height": 300})).unwrap();
|
||||
s
|
||||
}
|
||||
|
||||
fn id_of(v: &Value) -> NodeId {
|
||||
NodeId(v["id"].as_u64().unwrap())
|
||||
}
|
||||
|
||||
fn rect(s: &mut Session, x: f64) -> NodeId {
|
||||
id_of(&s.execute("shape.rectangle", &json!({"x": x, "y": 20, "width": 30, "height": 20})).unwrap())
|
||||
}
|
||||
|
||||
fn select(s: &mut Session, ids: &[NodeId]) {
|
||||
s.execute("select.set", &json!({"ids": ids.iter().map(|i| i.0).collect::<Vec<_>>()})).unwrap();
|
||||
}
|
||||
|
||||
fn doc(s: &Session) -> Arc<Document> {
|
||||
s.doc().unwrap().doc.clone()
|
||||
}
|
||||
|
||||
/// The move [`DocState::moved`] names, when it took `from` to the document now.
|
||||
fn moved_from(s: &Session, from: &Arc<Document>) -> Option<Vec2> {
|
||||
let st = s.doc().unwrap();
|
||||
let m = st.moved.as_ref()?;
|
||||
(m.from.as_ptr() == Arc::as_ptr(from) && m.to.as_ptr() == Arc::as_ptr(&st.doc) && m.selection == st.selection).then_some(m.by)
|
||||
}
|
||||
|
||||
// A move of the selection, a nudge and each step of a drag name the move; the drag's steps all start from the
|
||||
// document the drag began with.
|
||||
#[test]
|
||||
fn a_move_of_whole_objects_names_the_documents_and_the_distance() {
|
||||
let mut s = session();
|
||||
let (a, b) = (rect(&mut s, 20.0), rect(&mut s, 80.0));
|
||||
select(&mut s, &[a, b]);
|
||||
let before = doc(&s);
|
||||
s.execute("object.move", &json!({"dx": 12, "dy": -5})).unwrap();
|
||||
assert_eq!(moved_from(&s, &before), Some(Vec2::new(12.0, -5.0)), "Object › Transform › Move");
|
||||
let before = doc(&s);
|
||||
s.execute("object.nudge", &json!({"dx": 1, "dy": 0})).unwrap();
|
||||
assert_eq!(moved_from(&s, &before), Some(Vec2::new(s.prefs.keyboard_increment, 0.0)), "a nudge");
|
||||
|
||||
let start = doc(&s);
|
||||
s.begin_interaction("Move").unwrap();
|
||||
for dx in [3.0, 7.5] {
|
||||
s.preview("object.transform", &json!({"matrix": [1, 0, 0, 1, dx, 2], "copy": false})).unwrap();
|
||||
assert_eq!(moved_from(&s, &start), Some(Vec2::new(dx, 2.0)), "a drag's step by {dx}");
|
||||
}
|
||||
}
|
||||
|
||||
// A copy, a transform that is not a move, a move of patterns alone, a move that also resizes type areas, and a move
|
||||
// of part of what the selection shows name no move.
|
||||
#[test]
|
||||
fn a_copy_a_scale_and_a_move_of_part_of_the_selection_name_no_move() {
|
||||
let mut s = session();
|
||||
let (a, b) = (rect(&mut s, 20.0), rect(&mut s, 80.0));
|
||||
select(&mut s, &[a, b]);
|
||||
let cases = [
|
||||
("object.move", json!({"dx": 12, "dy": 0, "copy": true})),
|
||||
("object.transform", json!({"matrix": [2, 0, 0, 1, 0, 0]})),
|
||||
("object.move", json!({"dx": 12, "dy": 0, "objects": false, "patterns": true})),
|
||||
("object.move", json!({"dx": 12, "dy": 0, "typeAreas": true})),
|
||||
("object.transform", json!({"matrix": [1, 0, 0, 1, 5, 0], "ids": [a.0]})),
|
||||
];
|
||||
for (cmd, p) in cases {
|
||||
select(&mut s, &[a, b]);
|
||||
let before = doc(&s);
|
||||
s.execute(cmd, &p).unwrap();
|
||||
assert_eq!(moved_from(&s, &before), None, "{cmd} {p}");
|
||||
}
|
||||
}
|
||||
|
||||
// The key object is shown too: a move that leaves it where it was names no move.
|
||||
#[test]
|
||||
fn a_key_object_left_where_it_was_names_no_move() {
|
||||
let mut s = session();
|
||||
let (a, b) = (rect(&mut s, 20.0), rect(&mut s, 80.0));
|
||||
select(&mut s, &[a]);
|
||||
s.active_mut().unwrap().selection.key = Some(b);
|
||||
let before = doc(&s);
|
||||
s.execute("object.move", &json!({"dx": 12, "dy": 0})).unwrap();
|
||||
assert_eq!(moved_from(&s, &before), None);
|
||||
}
|
||||
|
||||
// A pixel-aligned path snaps to the pixel grid after the transform, and an instance of a symbol aligned to the pixel
|
||||
// grid snaps after the edit: neither is the object before the move moved by its distance.
|
||||
#[test]
|
||||
fn objects_that_snap_to_the_pixel_grid_name_no_move() {
|
||||
let mut s = session();
|
||||
let a = rect(&mut s, 20.0);
|
||||
select(&mut s, &[a]);
|
||||
s.execute("object.setPixelAligned", &json!({"on": true})).unwrap();
|
||||
let before = doc(&s);
|
||||
s.execute("object.move", &json!({"dx": 0.3, "dy": 0})).unwrap();
|
||||
assert_eq!(moved_from(&s, &before), None, "a pixel-aligned path");
|
||||
|
||||
let mut s = session();
|
||||
let art = rect(&mut s, 20.0);
|
||||
let made = s.execute("symbol.new", &json!({"name": "Box", "ids": [art.0], "alignToPixelGrid": true})).unwrap();
|
||||
select(&mut s, &[id_of(&made)]);
|
||||
let before = doc(&s);
|
||||
s.execute("object.move", &json!({"dx": 0.3, "dy": 0})).unwrap();
|
||||
assert_eq!(moved_from(&s, &before), None, "an instance of a symbol aligned to the pixel grid");
|
||||
}
|
||||
|
||||
// A member of a blend moved on its own changes the blend's spine.
|
||||
#[test]
|
||||
fn a_member_of_a_blend_names_no_move() {
|
||||
let mut s = session();
|
||||
let (a, b) = (rect(&mut s, 20.0), rect(&mut s, 200.0));
|
||||
s.execute("object.blend.make", &json!({"ids": [a.0, b.0], "steps": 1})).unwrap();
|
||||
select(&mut s, &[a]);
|
||||
let before = doc(&s);
|
||||
s.execute("object.move", &json!({"dx": 12, "dy": 0})).unwrap();
|
||||
assert_eq!(moved_from(&s, &before), None);
|
||||
}
|
||||
@@ -801,7 +801,7 @@ fn digits_unnamed(text: &str) -> Vec<u8> {
|
||||
out
|
||||
}
|
||||
|
||||
/// #708, #811: a glyph whose ToUnicode value is U+FFFD isn't type showing "�". This subset font
|
||||
/// #708, #811: a glyph whose ToUnicode value is U+FFFD isn't type showing `\u{FFFD}`. This subset font
|
||||
/// has no character map of its own, but the font is installed: each digit is found by its outline
|
||||
/// there, so the whole text stays one type object, with no outlines left behind.
|
||||
#[test]
|
||||
|
||||
@@ -8,35 +8,5 @@
|
||||
startup | Noto Sans Arabic | Regular
|
||||
startup | Noto Sans Thai | Regular
|
||||
startup | Noto Sans Georgian | Regular
|
||||
background | Cairo | Regular
|
||||
background | Tajawal | ExtraLight
|
||||
background | Tajawal | Light
|
||||
background | Tajawal | Regular
|
||||
background | Tajawal | Medium
|
||||
background | Tajawal | Bold
|
||||
background | Tajawal | ExtraBold
|
||||
background | Tajawal | Black
|
||||
background | Almarai | Light
|
||||
background | Almarai | Regular
|
||||
background | Almarai | Bold
|
||||
background | Almarai | ExtraBold
|
||||
background | IBM Plex Sans Arabic | Thin
|
||||
background | IBM Plex Sans Arabic | ExtraLight
|
||||
background | IBM Plex Sans Arabic | Light
|
||||
background | IBM Plex Sans Arabic | Regular
|
||||
background | IBM Plex Sans Arabic | Medium
|
||||
background | IBM Plex Sans Arabic | SemiBold
|
||||
background | IBM Plex Sans Arabic | Bold
|
||||
background | Noto Kufi Arabic | Regular
|
||||
background | Amiri | Regular
|
||||
background | Amiri | Italic
|
||||
background | Amiri | Bold
|
||||
background | Amiri | Bold Italic
|
||||
background | Alexandria | Regular
|
||||
background | Fustat | Regular
|
||||
background | Reem Kufi | Regular
|
||||
background | Aref Ruqaa | Regular
|
||||
background | Aref Ruqaa | Bold
|
||||
background | Gulzar | Regular
|
||||
demand | NanumGothic | Regular
|
||||
demand | Noto Sans Devanagari | Regular
|
||||
@@ -139,6 +139,7 @@ impl VectorcraftApp {
|
||||
spelling: Default::default(),
|
||||
text_nodes: Default::default(),
|
||||
momentary: None,
|
||||
hand: None,
|
||||
selection_box: None,
|
||||
selection_bounds: None,
|
||||
selection_marks: None,
|
||||
|
||||
@@ -81,6 +81,7 @@ pub struct CanvasCache {
|
||||
/// The Hand, Zoom and Rotate View tools the Space key and its chords lend the canvas, between
|
||||
/// passes; the tool adapter takes it out for its call and puts it back.
|
||||
pub momentary: Option<craft::ui::canvas::Momentary>,
|
||||
pub hand: Option<craft::ui::canvas::HandTool>,
|
||||
/// [`VectorcraftApp::selection_box`] for (document uid, revision, Use Preview Bounds and
|
||||
/// Measure Type by Glyph Bounds).
|
||||
pub selection_box: Option<((u64, u64, vectorcraft_effects::preview::Measure), Option<vectorcraft_doc::OrientedBox>)>,
|
||||
|
||||
@@ -278,8 +278,8 @@ pub(crate) fn show_document(app: &mut VectorcraftApp, ui: &mut Ui, win: Win, kin
|
||||
pressed
|
||||
}
|
||||
|
||||
/// The body of the canvas in order: controls that take presses first, the tool host, the selection's marks, the
|
||||
/// picture last.
|
||||
/// The body of the canvas in order: controls that take presses first, the tool host, the selection's marks and the
|
||||
/// display-only widgets over it, the picture last.
|
||||
fn show_body(app: &mut VectorcraftApp, ui: &mut Ui, space: &CanvasSpace, pass: Option<&ToolPass>, win: Win, kind: BodyKind) -> Body {
|
||||
let live = kind == BodyKind::Live;
|
||||
let presenting = app.ui.screen_mode == 3;
|
||||
@@ -299,11 +299,12 @@ fn show_body(app: &mut VectorcraftApp, ui: &mut Ui, space: &CanvasSpace, pass: O
|
||||
crate::dialogs::simplify_slider::show(app, ui, &space.view);
|
||||
}
|
||||
guides::show(app, ui, space, win, kind);
|
||||
widgets::show_hollow_corners(app, ui, space, kind);
|
||||
// The selection's marks paint here, under the widgets and bars, and are drawn after the tool host has taken this
|
||||
// frame's pointer event, from the document as the event leaves it.
|
||||
// The hollow Live Corners, the selection's marks, and the bounding box, Live Corners and shape widgets paint here
|
||||
// in that order, under the 3D handles and the bars. All of them are display only and are drawn after the tool host
|
||||
// has taken this frame's pointer event, from the document as the event leaves it.
|
||||
let hollow = PaintSlot::reserve(ui.painter());
|
||||
let marks = PaintSlot::reserve(ui.painter());
|
||||
widgets::show(app, ui, space, win, kind);
|
||||
let shown_widgets = PaintSlot::reserve(ui.painter());
|
||||
if !presenting && !revolve_editing(app) {
|
||||
crate::panels::three_d::handles::show(app, ui, space);
|
||||
}
|
||||
@@ -339,14 +340,21 @@ fn show_body(app: &mut VectorcraftApp, ui: &mut Ui, space: &CanvasSpace, pass: O
|
||||
crate::type_editing::show(app, ui);
|
||||
}
|
||||
}
|
||||
let after = PaintSlot::reserve(ui.painter());
|
||||
selection::show(app, ui, space, win, kind);
|
||||
marks.extend(ui.ctx(), after.take_after(ui.ctx()));
|
||||
paint_into(ui, hollow, |ui| widgets::show_hollow_corners(app, ui, space, kind));
|
||||
paint_into(ui, marks, |ui| selection::show(app, ui, space, win, kind));
|
||||
paint_into(ui, shown_widgets, |ui| widgets::show(app, ui, space, win, kind));
|
||||
drops::show(app, ui, win, kind);
|
||||
raster::picture(app, ui, space, win, kind);
|
||||
out
|
||||
}
|
||||
|
||||
/// Runs `draw` now and moves the shapes it paints on `ui`'s layer to `slot`, their place in the paint order.
|
||||
fn paint_into(ui: &mut Ui, slot: PaintSlot, draw: impl FnOnce(&mut Ui)) {
|
||||
let after = PaintSlot::reserve(ui.painter());
|
||||
draw(ui);
|
||||
slot.extend(ui.ctx(), after.take_after(ui.ctx()));
|
||||
}
|
||||
|
||||
/// The keys held now, as the engine's tools read them, with `space` set while Space is down.
|
||||
pub(crate) fn held_mods(ctx: &egui::Context) -> vectorcraft_tools::Mods {
|
||||
let (m, space) = ctx.input(|i| (i.modifiers, i.key_down(egui::Key::Space)));
|
||||
|
||||
@@ -35,7 +35,8 @@ pub(super) fn show(app: &VectorcraftApp, ui: &mut egui::Ui, space: &CanvasSpace,
|
||||
let options = super::selection::path_options(&app.session.prefs);
|
||||
let quiet = tool_adapter::in_gesture(app, ui.ctx()) || tool_adapter::view_tool_held(app);
|
||||
let lists = [extra, overlays];
|
||||
for (i, o) in extra.iter().chain(overlays).enumerate() {
|
||||
// Only the overlays that are controls get a child `Ui`: a list of 10,000 path marks makes none.
|
||||
for (i, o) in extra.iter().chain(overlays).enumerate().filter(|(_, o)| is_control(o)) {
|
||||
ui.push_id(("tool-control", i), |ui| show_control(ui, rect, o));
|
||||
}
|
||||
for (i, list) in lists.into_iter().enumerate() {
|
||||
@@ -48,6 +49,26 @@ pub(super) fn show(app: &VectorcraftApp, ui: &mut egui::Ui, space: &CanvasSpace,
|
||||
});
|
||||
}
|
||||
|
||||
/// Whether `o` is shown as a framework control of its own ([`show_control`]) rather than painted by [`ToolMarks`].
|
||||
fn is_control(o: &Overlay) -> bool {
|
||||
match o {
|
||||
Overlay::Marquee(_) | Overlay::SelectionMarquee { .. } | Overlay::SharedPath { .. } | Overlay::Outlines { .. } | Overlay::Distance { .. } => {
|
||||
true
|
||||
}
|
||||
Overlay::Path { .. }
|
||||
| Overlay::Line { .. }
|
||||
| Overlay::Anchor { .. }
|
||||
| Overlay::CurvePoint { .. }
|
||||
| Overlay::Handle { .. }
|
||||
| Overlay::Label { .. }
|
||||
| Overlay::Measure { .. }
|
||||
| Overlay::Highlight { .. }
|
||||
| Overlay::Swatch { .. }
|
||||
| Overlay::GridLine { .. }
|
||||
| Overlay::HoverText { .. } => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// The framework control `o` stands for, if it is one: a marquee, a settled outline, a set of outlines or a distance.
|
||||
fn show_control(ui: &mut egui::Ui, rect: ScreenRect, o: &Overlay) {
|
||||
match o {
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
use std::collections::HashMap;
|
||||
use std::collections::hash_map::{DefaultHasher, Entry};
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::sync::{Arc, Weak};
|
||||
|
||||
use craft::behavior::Input;
|
||||
use craft::behavior::Metrics;
|
||||
@@ -18,9 +19,9 @@ use craft::ui::canvas_controls::{HoverOutline, HoverShape, SelectionOutline};
|
||||
use craft::ui::contract::{Access, Bind, Common, Component, Cx, MeasureCx, PaintUi, Props as _, Role, Show as _};
|
||||
use craft::ui::style::{ComponentStyle, DataColor, StyleCx};
|
||||
use egui::{Color32, Rect, Response, Shape, Stroke, StrokeKind, vec2};
|
||||
use vectorcraft_doc::{NodeId, NodeKind};
|
||||
use vectorcraft_doc::{Document, NodeId, NodeKind};
|
||||
use vectorcraft_engine::{DocState, Prefs, ViewInfo};
|
||||
use vectorcraft_geom::{AnchorKind, BezPath, PathData, PathEl, Point};
|
||||
use vectorcraft_geom::{AnchorKind, BezPath, PathData, PathEl, Point, Vec2};
|
||||
use vectorcraft_tools::Mods;
|
||||
|
||||
use super::cursor::ViewKey;
|
||||
@@ -632,9 +633,13 @@ pub(super) fn show(app: &mut VectorcraftApp, ui: &mut egui::Ui, space: &CanvasSp
|
||||
HoverOutline::new("Object highlight", Some(HoverShape::Path(h.path))).color(DataColor::new(h.color)).show_at(ui, rect);
|
||||
}
|
||||
let key = marks_key(app, st, tool, tool_points);
|
||||
let view = view_key(app, st, tool, tool_points);
|
||||
let marks = match app.canvas.selection_marks.take() {
|
||||
Some(kept) if kept.key == key => kept,
|
||||
_ => SelectionMarks::build(app, st, tool, tool_points, key),
|
||||
Some(kept) if kept.view == view && kept.selection == st.selection => {
|
||||
kept.follow(st, key).unwrap_or_else(|| SelectionMarks::build(app, st, tool, tool_points, (key, view)))
|
||||
}
|
||||
_ => SelectionMarks::build(app, st, tool, tool_points, (key, view)),
|
||||
};
|
||||
for o in &marks.outlines {
|
||||
let mut outline = SelectionOutline::solid("Selection", &o.paths).color(DataColor::new(o.color)).revision(o.revision);
|
||||
@@ -663,29 +668,99 @@ pub(super) fn show(app: &mut VectorcraftApp, ui: &mut egui::Ui, space: &CanvasSp
|
||||
}
|
||||
|
||||
/// The outlines, anchors and dots `show` draws, kept between passes while their [`marks_key`] stays: a frame with
|
||||
/// nothing changed walks no selected object.
|
||||
/// nothing changed walks no selected object. They are also kept while the document and the selection stay the same
|
||||
/// under another revision, and moved with the selection when a move ([`vectorcraft_engine::Moved`]) took the document
|
||||
/// they show to the one now.
|
||||
pub(crate) struct SelectionMarks {
|
||||
key: u64,
|
||||
/// [`view_key`] of the state they were made for.
|
||||
view: u64,
|
||||
/// The selection they show.
|
||||
selection: vectorcraft_doc::Selection,
|
||||
/// The document they show.
|
||||
doc: Weak<Document>,
|
||||
/// A document they show moved by a distance: the one they were built for and no distance, or the document the
|
||||
/// last move they followed started from and its distance. Each step of a drag starts from the document the drag
|
||||
/// began with ([`SelectionMarks::follow`]).
|
||||
from: (Weak<Document>, Vec2),
|
||||
outlines: Vec<Outlined>,
|
||||
anchors: Anchors,
|
||||
dots: Dots,
|
||||
}
|
||||
|
||||
impl SelectionMarks {
|
||||
fn build(app: &VectorcraftApp, st: &DocState, tool: &str, tool_points: bool, key: u64) -> Self {
|
||||
fn build(app: &VectorcraftApp, st: &DocState, tool: &str, tool_points: bool, (key, view): (u64, u64)) -> Self {
|
||||
#[cfg(test)]
|
||||
tests::MARKS_BUILT.with(|built| built.set(built.get() + 1));
|
||||
Self { key, outlines: outlines(app, st), anchors: anchors(app, st, tool, tool_points), dots: dots(app, st) }
|
||||
let doc = Arc::downgrade(&st.doc);
|
||||
Self {
|
||||
key,
|
||||
view,
|
||||
selection: st.selection.clone(),
|
||||
from: (doc.clone(), Vec2::ZERO),
|
||||
doc,
|
||||
outlines: outlines(app, st),
|
||||
anchors: anchors(app, st, tool, tool_points),
|
||||
dots: dots(app, st),
|
||||
}
|
||||
}
|
||||
|
||||
/// The marks of `st`, whose [`marks_key`] is `key`, from these marks of the same selection and view: these marks
|
||||
/// when `st` shows the same document, these marks moved by `st`'s move when it took the document they show, or the
|
||||
/// document of [`SelectionMarks::from`], to the one `st` shows, else `None`.
|
||||
fn follow(mut self, st: &DocState, key: u64) -> Option<Self> {
|
||||
let now = Arc::as_ptr(&st.doc);
|
||||
if self.doc.as_ptr() != now {
|
||||
let moved = st.moved.as_ref().filter(|m| m.to.as_ptr() == now && m.selection == st.selection)?;
|
||||
let by = if moved.from.ptr_eq(&self.doc) {
|
||||
moved.by
|
||||
} else if moved.from.ptr_eq(&self.from.0) {
|
||||
moved.by - self.from.1
|
||||
} else {
|
||||
return None;
|
||||
};
|
||||
self.translate(by);
|
||||
self.from = (moved.from.clone(), moved.by);
|
||||
self.doc = moved.to.clone();
|
||||
}
|
||||
self.key = key;
|
||||
Some(self)
|
||||
}
|
||||
|
||||
/// Moves every mark by `by`.
|
||||
fn translate(&mut self, by: Vec2) {
|
||||
let shift = vectorcraft_geom::Affine::translate(by);
|
||||
for o in &mut self.outlines {
|
||||
o.paths.iter_mut().chain(o.key.as_mut()).for_each(|path| path.apply_affine(shift));
|
||||
o.revision = outline_revision(&o.paths, o.key.as_ref(), o.color.to_array());
|
||||
}
|
||||
for knot in self.anchors.paths.iter_mut().flat_map(|p| &mut p.subpaths).flat_map(|sp| &mut sp.knots) {
|
||||
knot.anchor += by;
|
||||
knot.in_ctrl += by;
|
||||
knot.out_ctrl += by;
|
||||
}
|
||||
let dots = &mut self.dots;
|
||||
for (at, _) in dots.origins.iter_mut().chain(&mut dots.centers).chain(&mut dots.key_anchor) {
|
||||
*at += by;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// What the selection's marks are built from: the document and its selection (its uid and revision), the parts the
|
||||
/// view hides, Halftone Preview, the tool whose marks show, whether that tool draws its own points, and the
|
||||
/// Selection & Anchor Display preferences.
|
||||
/// What the selection's marks are built from: the document and its selection (its uid and revision), and what
|
||||
/// [`view_key`] hashes.
|
||||
fn marks_key(app: &VectorcraftApp, st: &DocState, tool: &str, tool_points: bool) -> u64 {
|
||||
let mut h = DefaultHasher::new();
|
||||
(st.revision, view_key(app, st, tool, tool_points)).hash(&mut h);
|
||||
h.finish()
|
||||
}
|
||||
|
||||
/// What the selection's marks are built from besides the document's content and the selection: the document (its
|
||||
/// uid), the parts the view hides, Halftone Preview, the tool whose marks show, whether that tool draws its own points,
|
||||
/// and the Selection & Anchor Display preferences.
|
||||
fn view_key(app: &VectorcraftApp, st: &DocState, tool: &str, tool_points: bool) -> u64 {
|
||||
let mut h = DefaultHasher::new();
|
||||
let hides = ViewHides::of(app);
|
||||
(st.uid, st.revision, hides.templates, hides.guides, hidden(app), tool, tool_points).hash(&mut h);
|
||||
(st.uid, hides.templates, hides.guides, hidden(app), tool, tool_points).hash(&mut h);
|
||||
let prefs = &app.session.prefs;
|
||||
(prefs.anchor_size, prefs.show_handles_multiple_anchors, prefs.handle_style.as_str()).hash(&mut h);
|
||||
h.finish()
|
||||
|
||||
@@ -918,3 +918,75 @@ fn the_canvas_builds_the_selection_marks_once_per_change() {
|
||||
app.select_tool("directSelection");
|
||||
assert_eq!(frames(&mut app, 5), 1, "another tool builds the marks once");
|
||||
}
|
||||
|
||||
/// Every point of the outlines, the anchors and their handles, and the dots, in order.
|
||||
fn points_of(outlines: &[Outlined], anchors: &Anchors, dots: &Dots) -> Vec<Point> {
|
||||
let mut out = vec![];
|
||||
for path in outlines.iter().flat_map(|o| o.paths.iter().chain(&o.key)) {
|
||||
for el in path.elements() {
|
||||
match *el {
|
||||
PathEl::MoveTo(a) | PathEl::LineTo(a) => out.push(a),
|
||||
PathEl::QuadTo(a, b) => out.extend([a, b]),
|
||||
PathEl::CurveTo(a, b, c) => out.extend([a, b, c]),
|
||||
PathEl::ClosePath => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
for knot in anchors.paths.iter().flat_map(|p| &p.subpaths).flat_map(|sp| &sp.knots) {
|
||||
out.extend([knot.anchor, knot.in_ctrl, knot.out_ctrl]);
|
||||
}
|
||||
out.extend(dots.origins.iter().chain(&dots.centers).chain(&dots.key_anchor).map(|(at, _)| *at));
|
||||
out
|
||||
}
|
||||
|
||||
/// Whether the marks the canvas keeps are, to rounding, the ones the builders give for the state now.
|
||||
fn kept_marks_are_current(app: &VectorcraftApp) -> bool {
|
||||
let kept = app.canvas.selection_marks.as_ref().expect("the canvas drew the selection's marks");
|
||||
let st = app.session.active().unwrap();
|
||||
let now = points_of(&outlines(app, st), &anchors(app, st, app.session.tool_id(), false), &dots(app, st));
|
||||
let was = points_of(&kept.outlines, &kept.anchors, &kept.dots);
|
||||
now.len() == was.len() && now.iter().zip(&was).all(|(a, b)| (*a - *b).hypot() < 1e-9)
|
||||
}
|
||||
|
||||
// Whole-app frames keep the selection's marks through a new revision of the same document and selection, and move
|
||||
// them with a move of the selection instead of building them: a move command, each step of a drag, and the drag's end
|
||||
// build nothing and keep the marks of the state now. A scale and an undo still build them once.
|
||||
#[test]
|
||||
fn a_move_of_the_selection_moves_its_marks_without_building_them() {
|
||||
let (mut app, _) = scene();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let frames = |app: &mut VectorcraftApp, n: usize| {
|
||||
let before = MARKS_BUILT.with(std::cell::Cell::get);
|
||||
for _ in 0..n {
|
||||
let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1600.0, 850.0));
|
||||
crate::testing::app_frame(app, &ctx, egui::RawInput { screen_rect: Some(screen), ..Default::default() });
|
||||
}
|
||||
MARKS_BUILT.with(std::cell::Cell::get) - before
|
||||
};
|
||||
frames(&mut app, 3);
|
||||
let layer = app.session.active().unwrap().doc.layers[0].id;
|
||||
let revision = app.session.active().unwrap().revision;
|
||||
app.run("layer.setCurrent", json!({"id": layer.0})).unwrap();
|
||||
assert_ne!(app.session.active().unwrap().revision, revision, "a new revision");
|
||||
assert_eq!(frames(&mut app, 3), 0, "a new revision of the same document and selection");
|
||||
app.run("object.move", json!({"dx": 12.25, "dy": -5})).unwrap();
|
||||
assert_eq!(frames(&mut app, 3), 0, "a move command");
|
||||
assert!(kept_marks_are_current(&app), "after a move command");
|
||||
|
||||
app.session.begin_interaction("Move").unwrap();
|
||||
for dx in [3.0, 7.5, -2.0] {
|
||||
app.session.preview("object.transform", &json!({"matrix": [1, 0, 0, 1, dx, 4], "copy": false})).unwrap();
|
||||
assert_eq!(frames(&mut app, 2), 0, "a drag's step by {dx}");
|
||||
assert!(kept_marks_are_current(&app), "after a drag's step by {dx}");
|
||||
}
|
||||
app.session.commit_interaction().unwrap();
|
||||
assert_eq!(frames(&mut app, 2), 0, "the drag's end");
|
||||
assert!(kept_marks_are_current(&app), "after the drag");
|
||||
|
||||
app.run("object.transform", json!({"matrix": [2, 0, 0, 1, 0, 0]})).unwrap();
|
||||
assert_eq!(frames(&mut app, 3), 1, "a scale");
|
||||
assert!(kept_marks_are_current(&app), "after a scale");
|
||||
app.run("edit.undo", json!({})).unwrap();
|
||||
assert_eq!(frames(&mut app, 3), 1, "an undo");
|
||||
assert!(kept_marks_are_current(&app), "after an undo");
|
||||
}
|
||||
@@ -303,7 +303,22 @@ fn press(at: Pos2, pressed: bool) -> egui::Event {
|
||||
/// object has after that frame's event, and none at the corner it had before it.
|
||||
#[test]
|
||||
fn a_selection_drag_draws_its_marks_in_the_frame_the_pointer_moves() {
|
||||
selection_drag_marks_follow(drag_app());
|
||||
}
|
||||
|
||||
/// With Show Bounding Box While Moving and Drawing on, a Selection tool drag draws the bounding box and its handles in
|
||||
/// the frame the pointer moves: at the corner the object has after that frame's event, and none at the corner it had
|
||||
/// before it.
|
||||
#[test]
|
||||
fn a_selection_drag_draws_its_bounding_box_in_the_frame_the_pointer_moves() {
|
||||
let mut app = drag_app();
|
||||
app.session.prefs.bounding_box_while_moving_and_drawing = true;
|
||||
selection_drag_marks_follow(app);
|
||||
}
|
||||
|
||||
/// Drags a selected rectangle with the Selection tool in six frames and checks each frame that moved it: a mark at
|
||||
/// its corner after the frame's event, none at its corner before.
|
||||
fn selection_drag_marks_follow(mut app: VectorcraftApp) {
|
||||
let id = app.session.execute("shape.rectangle", &json!({"x": 150, "y": 100, "width": 60, "height": 40})).unwrap()["id"].as_u64().unwrap();
|
||||
app.select_tool("selection");
|
||||
app.session.execute("select.set", &json!({"ids": [id]})).unwrap();
|
||||
@@ -4859,6 +4874,25 @@ fn a_flip_during_a_press_waits_for_the_release() {
|
||||
assert_eq!(app.session.tool_id(), "eraser", "the frame after the release");
|
||||
}
|
||||
|
||||
/// A selected Hand tracks its drag in the framework, outside the document tool's grab.
|
||||
#[test]
|
||||
fn turning_the_pen_during_a_hand_drag_waits_for_release() {
|
||||
let (mut app, stylus, ctx) = pen_app();
|
||||
app.select_tool("hand");
|
||||
let at = app.canvas_view().unwrap().rect.center();
|
||||
let to = at + egui::vec2(30.0, 20.0);
|
||||
let button = |pos, pressed| egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() };
|
||||
stylus.set(tip(0.5));
|
||||
frame(&mut app, &ctx, vec![egui::Event::PointerMoved(at), button(at, true)]);
|
||||
stylus.set(eraser_end(0.5));
|
||||
frame(&mut app, &ctx, vec![egui::Event::PointerMoved(to)]);
|
||||
assert_eq!(app.session.tool_id(), "hand");
|
||||
frame(&mut app, &ctx, vec![button(to, false)]);
|
||||
assert_eq!(app.session.tool_id(), "hand");
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
assert_eq!(app.session.tool_id(), "eraser");
|
||||
}
|
||||
|
||||
/// #764: a tool chosen while the eraser end stands in (the toolbar and shortcuts call
|
||||
/// `select_tool`; menus and MCP run `tool.select`) stays when the tip comes back.
|
||||
#[test]
|
||||
|
||||
@@ -127,10 +127,12 @@ fn a_hand_drag_held_near_the_edge_does_not_scroll_on() {
|
||||
let (mut app, ctx, _) = zoomed_in("hand");
|
||||
let rect = app.canvas_view().unwrap().rect;
|
||||
let start = rect.center();
|
||||
let before = center(&app);
|
||||
frame(&mut app, &ctx, vec![egui::Event::PointerMoved(start), button(start, true)]);
|
||||
let edge = pos2(rect.right() - 4.0, start.y);
|
||||
frame(&mut app, &ctx, vec![egui::Event::PointerMoved(edge)]);
|
||||
let c0 = center(&app);
|
||||
assert!(c0.x < before.x, "dragging the selected Hand right must pan the view");
|
||||
for _ in 0..3 {
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
}
|
||||
|
||||
@@ -629,6 +629,7 @@ pub(crate) fn run(app: &mut VectorcraftApp, ui: &mut Ui, pass: &ToolPass) -> Too
|
||||
// the release, and a pointer over another window for the pointer to come in.
|
||||
if ui.ctx().current_pass_index() == 0
|
||||
&& app.canvas.grab.is_none()
|
||||
&& !ToolHost::in_gesture(ui.ctx(), pass.id)
|
||||
&& ui.input(|i| i.pointer.has_pointer())
|
||||
&& crate::stylus::sync_eraser_tool(app)
|
||||
{
|
||||
@@ -650,7 +651,18 @@ pub(crate) fn run(app: &mut VectorcraftApp, ui: &mut Ui, pass: &ToolPass) -> Too
|
||||
let mut picked = ToolHostResponse::default();
|
||||
let mut response = if crate::dialogs::recolor::edit_tab::with_theme_pick(app, |app, tool| picked = host_run(app, ui, pass, tool)) {
|
||||
picked
|
||||
} else if app.session.tool_id() == "hand" && app.ui.screen_mode != 3 && app.ui.rearrange_placement.is_none() {
|
||||
let options = crate::app::view::navigation(&app.session.prefs);
|
||||
let mut hand = app.canvas.hand.take().unwrap_or_else(|| craft::ui::canvas::HandTool::new(options));
|
||||
hand.options = options;
|
||||
let response = host_run(app, ui, pass, &mut hand);
|
||||
if response.gesture.is_some() && !view_tool_held(app) && ui.input(|i| i.pointer.primary_down() || i.pointer.primary_pressed()) {
|
||||
crate::shortcuts::note_tool_use(app);
|
||||
}
|
||||
app.canvas.hand = Some(hand);
|
||||
response
|
||||
} else {
|
||||
app.canvas.hand = None;
|
||||
let mut tool = SessionTool::new(app, view_info, ui);
|
||||
let response = host_run_session(&mut tool, ui, pass);
|
||||
drop(tool);
|
||||
|
||||
@@ -114,7 +114,7 @@ pub(crate) fn family_picker<'a>(
|
||||
.filters(filters)
|
||||
.sets(sets)
|
||||
.scripts(&FontScript::ALL)
|
||||
.filter_layout(FilterLayout::Chips)
|
||||
.filter_layout(FilterLayout::Toolbar)
|
||||
}
|
||||
|
||||
/// What one pass of a picker reads of the app, for a host that has no `app` while it draws (a dialog).
|
||||
|
||||
@@ -158,7 +158,7 @@ pub(crate) fn step_place(step: usize, in_batch: Option<usize>) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
/// `text` as a status message shows it: control characters become `�`, and text past 80
|
||||
/// `text` as a status message shows it: control characters become `\u{FFFD}`, and text past 80
|
||||
/// characters ends in `…`.
|
||||
pub(crate) fn shown_text(text: &str) -> String {
|
||||
const MAX: usize = 80;
|
||||
|
||||
@@ -1231,7 +1231,7 @@ pub(crate) fn controls(app: &mut VectorcraftApp, ui: &mut Ui, rows: CharacterRow
|
||||
.filters(Bind::bound(&mut app.ui.font_filters))
|
||||
.sets(&sets)
|
||||
.scripts(&FontScript::ALL)
|
||||
.filter_layout(FilterLayout::Chips);
|
||||
.filter_layout(FilterLayout::Toolbar);
|
||||
if let Some(text) = &sample {
|
||||
source = source.preview_text(text);
|
||||
}
|
||||
|
||||
@@ -59,6 +59,12 @@ pub(crate) fn copy_value(ui: &mut Ui, label: &str, value: &str, mono: bool) -> b
|
||||
/// The same guarded full-value copy for an already shown readout. An elided path remains
|
||||
/// static text: selection indices must describe the text actually shown by the framework.
|
||||
pub(crate) fn copy_shown(ui: &mut Ui, shown: &egui::Response, value: &str) -> bool {
|
||||
// A container's measuring run shows the readout in an invisible sizing pass before the frame's real run, with the
|
||||
// same id and the same input. It neither copies nor reads or clears the remembered press: clearing it there would
|
||||
// leave the real run's release without its press.
|
||||
if ui.is_sizing_pass() {
|
||||
return false;
|
||||
}
|
||||
// The click's own position and keys: a move or a key change after the release in the same
|
||||
// frame leaves the pointer and the held keys elsewhere. A frame with more than one release
|
||||
// copies nothing, since the click flags below do not say which release they describe.
|
||||
|
||||
@@ -182,8 +182,9 @@ pub struct LayersUi {
|
||||
/// The selection square clicked last in each open document, by the document's `uid`: where a Shift-click on another
|
||||
/// square starts.
|
||||
pub art_anchors: HashMap<u64, NodeId>,
|
||||
/// The active document's rows with the [`LayerRows::key`] they were listed at.
|
||||
rows: Option<(u64, Tracked<LayerRows>)>,
|
||||
/// The active document's rows with the [`LayerRows::key`] they were listed at and the document's `uid` and
|
||||
/// `reverts`.
|
||||
rows: Option<(u64, (u64, u64), Tracked<LayerRows>)>,
|
||||
}
|
||||
|
||||
impl Default for LayersUi {
|
||||
@@ -223,7 +224,7 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
thumbnails.hold(app.session.active().is_some_and(|st| st.interaction.is_some()) || app.session.tool_busy());
|
||||
let settings = app.ui.layers_panel.settings();
|
||||
refresh_rows(app);
|
||||
let (Some(st), Some((_, kept))) = (app.session.active(), &app.ui.layers_ui.rows) else { return };
|
||||
let (Some(st), Some((_, _, kept))) = (app.session.active(), &app.ui.layers_ui.rows) else { return };
|
||||
let tree = DocLayers::of(st, kept);
|
||||
let source = thumbs::LayerThumbs { doc: &st.doc };
|
||||
let mut panel = LayersPanel::new(kept)
|
||||
@@ -294,13 +295,23 @@ fn unrevealed<T>(app: &mut VectorcraftApp, f: impl FnOnce(&mut VectorcraftApp) -
|
||||
r
|
||||
}
|
||||
|
||||
/// Lists the active document's rows again when what they are listed from changed.
|
||||
/// Lists the active document's rows again when what they are listed from changed. The new rows go into the kept
|
||||
/// [`Tracked`] while the document is the same, so the panel keeps its display order when the
|
||||
/// [order revision](LayerRows::order_of) stays; another document, or the same one after File › Revert, gets a new one.
|
||||
fn refresh_rows(app: &mut VectorcraftApp) {
|
||||
let Some(st) = app.session.active() else { return };
|
||||
let key = LayerRows::key(app, st);
|
||||
if app.ui.layers_ui.rows.as_ref().is_none_or(|(kept, _)| *kept != key) {
|
||||
let rows = Tracked::new(LayerRows::new(app, st));
|
||||
app.ui.layers_ui.rows = Some((key, rows));
|
||||
let doc = (st.uid, st.reverts);
|
||||
if app.ui.layers_ui.rows.as_ref().is_some_and(|(kept, _, _)| *kept == key) {
|
||||
return;
|
||||
}
|
||||
let new = LayerRows::new(app, st);
|
||||
match &mut app.ui.layers_ui.rows {
|
||||
Some((kept, of, rows)) if *of == doc => {
|
||||
rows.edit(|rows| *rows = new);
|
||||
*kept = key;
|
||||
}
|
||||
slot => *slot = Some((key, doc, Tracked::new(new))),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -202,6 +202,14 @@ pub(super) struct LayerRows {
|
||||
/// In isolation mode, the isolated node: the top row.
|
||||
#[plain_data(assume = "a node id is an integer")]
|
||||
root: Option<NodeId>,
|
||||
/// What the display order is built from ([`LayerRows::order_of`]).
|
||||
order: u64,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
thread_local! {
|
||||
/// How many times [`LayerRows::children`] was asked on this thread.
|
||||
pub(super) static CHILDREN_CALLS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
|
||||
}
|
||||
|
||||
/// [`LayerRows`] with the editing state of their document, for the panel's host code in one pass.
|
||||
@@ -243,7 +251,9 @@ impl LayerRows {
|
||||
let guide_rows = ruler.iter().enumerate().filter_map(|(i, g)| Some((g.id?, i))).collect();
|
||||
let blends = st.selection.objects.iter().copied().filter(|id| doc.node(*id).is_some_and(|n| matches!(n.kind, NodeKind::Blend { .. })));
|
||||
let selected: HashSet<NodeId> = st.selection.objects.iter().copied().collect();
|
||||
let root = st.isolation.and_then(|i| isolated_root(doc, i)).map(|(n, ..)| n.id);
|
||||
Self {
|
||||
order: Self::order_of(doc, &st.layers_open, app.ui.layers_panel.layers_only, root),
|
||||
doc: doc.clone(),
|
||||
opts: app.ui.layers_panel.clone(),
|
||||
xml_id: by_xml_id(app),
|
||||
@@ -258,10 +268,20 @@ impl LayerRows {
|
||||
holding: super::rows::holding(doc, &selected),
|
||||
selected,
|
||||
blends: blends.collect(),
|
||||
root: st.isolation.and_then(|i| isolated_root(doc, i)).map(|(n, ..)| n.id),
|
||||
root,
|
||||
}
|
||||
}
|
||||
|
||||
/// A hash of everything the display order reads ([`LayerTree::children`] and [`LayerTree::is_open`]): the
|
||||
/// document, which an edit replaces and a selection change keeps (its ruler guides and an opacity mask being
|
||||
/// edited are in it), the open rows, Show Layers Only and the isolated node. The selection, the highlighted rows,
|
||||
/// the current layer, the names and the other Panel Options are not in it.
|
||||
fn order_of(doc: &Arc<Document>, open: &OpenRows, layers_only: bool, root: Option<NodeId>) -> u64 {
|
||||
let mut hasher = DefaultHasher::new();
|
||||
(Arc::as_ptr(doc) as usize, open.generation(), layers_only, root).hash(&mut hasher);
|
||||
hasher.finish()
|
||||
}
|
||||
|
||||
/// What the rows of `st` are listed from: the document and its revision (which every edit and
|
||||
/// selection change moves), the open rows, isolation mode, the highlighted rows and the current
|
||||
/// layer, the Panel Options, Identify Objects By and the language.
|
||||
@@ -461,6 +481,8 @@ impl LayerTree for LayerRows {
|
||||
/// The top rows are the layers (only the opacity mask's while one is edited), or in isolation
|
||||
/// mode the isolated layer, sublayer, group or object.
|
||||
fn children(&self, parent: Option<&RowId>) -> Vec<RowId> {
|
||||
#[cfg(test)]
|
||||
CHILDREN_CALLS.with(|c| c.set(c.get() + 1));
|
||||
match parent {
|
||||
None => match self.root {
|
||||
Some(root) => vec![RowId::Node(root)],
|
||||
@@ -491,6 +513,11 @@ impl LayerTree for LayerRows {
|
||||
false
|
||||
}
|
||||
|
||||
/// The display order changes only with what [`LayerRows::order_of`] hashes: a selection change keeps it.
|
||||
fn order_revision(&self) -> Option<u64> {
|
||||
Some(self.order)
|
||||
}
|
||||
|
||||
fn info(&self, id: &RowId) -> LayerInfo {
|
||||
match *id {
|
||||
RowId::Node(id) => match self.doc.node(id) {
|
||||
|
||||
@@ -1352,3 +1352,78 @@ fn idle_frames_walk_no_node_for_the_selection_squares() {
|
||||
}
|
||||
assert!((1..=12).contains(&(visits() - before)), "a new selection walks the tree once: {}", visits() - before);
|
||||
}
|
||||
|
||||
/// A selection change keeps the panel's display order: no row is asked for the rows inside it. Closing a row, Show
|
||||
/// Layers Only and an edit build the order again, and the rows follow.
|
||||
#[test]
|
||||
fn a_selection_change_keeps_the_display_order() {
|
||||
use crate::tests::panel_harness::Panel;
|
||||
let calls = || super::model::CHILDREN_CALLS.with(std::cell::Cell::get);
|
||||
let (mut app, [_, sub, _, b, a, c]) = nested();
|
||||
for (id, name) in [(sub, "Sub"), (b, "B"), (a, "A"), (c, "C")] {
|
||||
name_row(&mut app, id, name);
|
||||
}
|
||||
app.session.execute("select.set", &json!({"ids": [b.0]})).unwrap();
|
||||
let mut panel = Panel::new(app, show);
|
||||
panel.frame();
|
||||
let before = calls();
|
||||
panel.app().session.execute("select.set", &json!({"ids": [a.0]})).unwrap();
|
||||
for _ in 0..3 {
|
||||
panel.frame();
|
||||
}
|
||||
assert_eq!(calls() - before, 0, "a selection change asks no row for its rows");
|
||||
assert!(panel.shows("A") && panel.shows("B"), "the rows stay");
|
||||
|
||||
expand(&mut panel.app(), &json!({"ids": [sub.0], "open": false})).unwrap();
|
||||
let before = calls();
|
||||
panel.frame();
|
||||
panel.frame();
|
||||
assert!(calls() > before, "closing a row builds the order again");
|
||||
assert!(!panel.shows("A") && panel.shows("Sub") && panel.shows("C"), "the closed sublayer's rows are gone");
|
||||
|
||||
panel.app().ui.layers_panel.layers_only = true;
|
||||
panel.frame();
|
||||
panel.frame();
|
||||
assert!(!panel.shows("C") && panel.shows("Sub"), "Show Layers Only leaves the objects out");
|
||||
|
||||
panel.app().ui.layers_panel.layers_only = false;
|
||||
panel.app().session.execute("object.isolate", &json!({"id": sub.0})).unwrap();
|
||||
panel.frame();
|
||||
panel.frame();
|
||||
assert!(panel.shows("Sub") && !panel.shows("C"), "isolation mode lists only the isolated sublayer");
|
||||
panel.app().session.execute("object.exitIsolation", &json!({})).unwrap();
|
||||
expand(&mut panel.app(), &json!({"ids": [sub.0], "open": true})).unwrap();
|
||||
let made = panel.app().session.execute("shape.rectangle", &json!({"x": 200, "y": 200, "width": 10, "height": 10})).unwrap();
|
||||
let d = NodeId(made["id"].as_u64().unwrap());
|
||||
name_row(&mut panel.app(), d, "D");
|
||||
panel.frame();
|
||||
panel.frame();
|
||||
assert!(panel.shows("D") && panel.shows("C"), "an edit lists the new object");
|
||||
}
|
||||
|
||||
/// The order revision stays through a selection change and moves with the document, the open rows, Show Layers Only
|
||||
/// and isolation mode.
|
||||
#[test]
|
||||
fn the_order_revision_follows_what_the_display_order_reads() {
|
||||
let order = |app: &VectorcraftApp| LayerRows::new(app, app.session.active().unwrap()).order_revision();
|
||||
let (mut app, [_, sub, g, b, a, _]) = nested();
|
||||
let first = order(&app);
|
||||
assert!(first.is_some(), "the rows report an order revision");
|
||||
app.session.execute("select.set", &json!({"ids": [b.0]})).unwrap();
|
||||
assert_eq!(order(&app), first, "a selection change keeps it");
|
||||
app.session.execute("object.isolate", &json!({"id": sub.0})).unwrap();
|
||||
let isolated = order(&app);
|
||||
assert_ne!(isolated, first, "isolation mode moves it");
|
||||
app.session.execute("object.exitIsolation", &json!({})).unwrap();
|
||||
let left = order(&app);
|
||||
assert_ne!(left, isolated, "leaving isolation mode moves it");
|
||||
app.ui.layers_panel.layers_only = true;
|
||||
assert_ne!(order(&app), left, "Show Layers Only moves it");
|
||||
app.ui.layers_panel.layers_only = false;
|
||||
assert_eq!(order(&app), left, "and turning it off gives it back");
|
||||
expand(&mut app, &json!({"ids": [g.0], "open": false})).unwrap();
|
||||
let closed = order(&app);
|
||||
assert_ne!(closed, left, "closing a row moves it");
|
||||
name_row(&mut app, a, "A");
|
||||
assert_ne!(order(&app), closed, "an edit moves it");
|
||||
}
|
||||
@@ -490,6 +490,15 @@ pub struct ContextSpelling {
|
||||
pub suggestions: Vec<String>,
|
||||
}
|
||||
|
||||
/// The main window as saved in the UI preferences through 0.24.1. Positions are desktop pixels.
|
||||
#[derive(Clone, Copy, Debug, Deserialize)]
|
||||
pub struct LegacyWindow {
|
||||
pub pos: Option<[i32; 2]>,
|
||||
pub size: [f32; 2],
|
||||
#[serde(default)]
|
||||
pub maximized: bool,
|
||||
}
|
||||
|
||||
/// Two states are equal when they save the same: the settings store writes only a changed saved form,
|
||||
/// and the panels' session state is no change to save.
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
@@ -500,6 +509,9 @@ pub struct UiState {
|
||||
/// it is never written back.
|
||||
#[serde(rename = "language", skip_serializing)]
|
||||
pub legacy_language: Option<String>,
|
||||
/// Used until the shared window store has recorded the main window.
|
||||
#[serde(rename = "window", skip_serializing)]
|
||||
pub legacy_window: Option<LegacyWindow>,
|
||||
pub brightness: Brightness,
|
||||
/// The panel arrangement: docks, floating windows, closed panels and where each goes back. One
|
||||
/// `Arc` the dock area keeps across frames; writers change it through `Arc::make_mut`.
|
||||
@@ -1448,6 +1460,7 @@ impl Default for UiState {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
legacy_language: None,
|
||||
legacy_window: None,
|
||||
brightness: Brightness::MediumDark,
|
||||
dock_workspace: std::sync::Arc::new(crate::panel_docking::default_workspace(&[])),
|
||||
tools_last_used: Default::default(),
|
||||
|
||||
@@ -355,10 +355,11 @@ fn a_control_port_cancel_of_a_dialog_preview_reads_the_menus() {
|
||||
}
|
||||
|
||||
/// OK applies the rotation a dialog previews as one undo step: the menus are read then, with Undo
|
||||
/// naming it, and not for the angles previewed before.
|
||||
/// naming it, and not for the angles previewed before. Once the dialog's angle field no longer takes
|
||||
/// the keys, the menus are sent once more without the text-editing gate.
|
||||
#[test]
|
||||
fn applying_a_dialog_preview_reads_the_menus() {
|
||||
let (m, (read, synced, closed, after)) = undisturbed(|m| {
|
||||
let (m, (read, synced, applied, closed, after)) = undisturbed(|m| {
|
||||
m.rotate_preview();
|
||||
let read = m.angles(4);
|
||||
let synced = m.fake.synced();
|
||||
@@ -367,12 +368,21 @@ fn applying_a_dialog_preview_reads_the_menus() {
|
||||
// gone two frames later.
|
||||
m.frame(vec![]);
|
||||
m.frame(vec![]);
|
||||
let applied = m.fake.synced();
|
||||
// The frame after the field gives up the keys sets the gate.
|
||||
for _ in 0..4 {
|
||||
if !m.ctx.egui_wants_keyboard_input() {
|
||||
break;
|
||||
}
|
||||
m.frame(vec![]);
|
||||
}
|
||||
m.frame(vec![]);
|
||||
(read, synced, !m.app.session.in_interaction() && !m.app.any_dialog_open(), m.fake.synced())
|
||||
(read, synced, applied, !m.app.session.in_interaction() && !m.app.any_dialog_open(), m.fake.synced())
|
||||
});
|
||||
assert_eq!(read, 0, "the menus weren't read while the dialog previewed the angles");
|
||||
assert!(closed);
|
||||
assert_eq!(after, synced + 1, "the menus were read");
|
||||
assert_eq!(applied, synced + 1, "the menus were read");
|
||||
assert_eq!(after, synced + 2, "and sent once more when the gate changed");
|
||||
assert_eq!(find(&m.fake.last(), "edit.undo").label, "Undo Rotate");
|
||||
}
|
||||
|
||||
|
||||
@@ -166,10 +166,14 @@ const SIZES: &[u8] = br#"{
|
||||
"size.page.button_side": 16,
|
||||
"size.page.link": 24
|
||||
},
|
||||
"comfortable": {
|
||||
"size.icon.lg": 26
|
||||
},
|
||||
"compact": {
|
||||
"size.control.md": 26,
|
||||
"size.button": 24,
|
||||
"size.icon.glyph_md": 16,
|
||||
"size.icon.lg": 24,
|
||||
"size.rail.width": 38,
|
||||
"size.dock.column": 310,
|
||||
"size.bar.column": 14,
|
||||
|
||||
@@ -823,7 +823,7 @@ fn bottom_controls(app: &mut VectorcraftApp, ui: &mut Ui, footer: RailFooter) {
|
||||
None => button,
|
||||
};
|
||||
// Small in two columns, where the three sit side by side in the rail's width.
|
||||
let button = if two { button.size(ControlSize::Sm) } else { button };
|
||||
let button = if two { button.size(ControlSize::Sm).glyphs(craft::ui::style::GlyphRole::Tool) } else { button };
|
||||
button.show(ui).clicked()
|
||||
};
|
||||
let mut run = None;
|
||||
|
||||
@@ -73,6 +73,29 @@ try {
|
||||
Clear-SigningFixtures
|
||||
Write-Output 'PASS: supported-configuration-presence-without-signing'
|
||||
|
||||
# The unsigned message is captured here, so it does not become an annotation of this job.
|
||||
$optInFile = Join-Path $root 'opt-in-sentinel.exe'
|
||||
[IO.File]::WriteAllText($optInFile, 'generated sentinel, not a real executable')
|
||||
$savedActions = $env:GITHUB_ACTIONS
|
||||
try {
|
||||
$env:GITHUB_ACTIONS = 'true'
|
||||
$env:CRAFT_ALLOW_UNSIGNED = $null
|
||||
$default = (& $sign $optInFile) -join "`n"
|
||||
Assert-Policy ($default.Contains('::warning::Windows signing secrets not set')) "unsigned output without the opt-in must warn; got: $default"
|
||||
$env:CRAFT_ALLOW_UNSIGNED = '1'
|
||||
$optedIn = (& $sign $optInFile) -join "`n"
|
||||
Assert-Policy ($optedIn.Contains('::notice::Windows signing secrets not set')) "opted-in unsigned output must be a notice; got: $optedIn"
|
||||
Assert-Policy (-not $optedIn.Contains('::warning::')) "opted-in unsigned output must not warn; got: $optedIn"
|
||||
foreach ($value in @('true', '0', 'yes')) {
|
||||
$env:CRAFT_ALLOW_UNSIGNED = $value
|
||||
Invoke-Refusal { & $sign $optInFile } 'CRAFT_ALLOW_UNSIGNED must be 1 or unset'
|
||||
}
|
||||
} finally {
|
||||
$env:CRAFT_ALLOW_UNSIGNED = $null
|
||||
$env:GITHUB_ACTIONS = $savedActions
|
||||
}
|
||||
Write-Output 'PASS: opted-in-unsigned-output-is-a-notice'
|
||||
|
||||
# Load the policy function without signing. These objects are not crypto evidence.
|
||||
. $sign -CheckOnly
|
||||
foreach ($value in @($null, [pscustomobject]@{Status='NotSigned';SignerCertificate='fixture'}, [pscustomobject]@{Status='HashMismatch';SignerCertificate='fixture'}, [pscustomobject]@{Status='Valid';SignerCertificate=$null})) {
|
||||
|
||||
@@ -9,7 +9,8 @@
|
||||
AZURE_SIGNING_ENDPOINT (e.g. https://eus.codesigning.azure.net),
|
||||
AZURE_SIGNING_ACCOUNT, AZURE_CERT_PROFILE
|
||||
With neither, it prints a warning and leaves the files unsigned (exit code 0), so test builds
|
||||
still produce installers. Nightly callers require signing with -Required and can check the
|
||||
still produce installers. A caller that builds unsigned on purpose sets CRAFT_ALLOW_UNSIGNED=1,
|
||||
and the message is then a notice instead of a warning. Nightly callers require signing with -Required and can check the
|
||||
signing configuration with -Required -CheckOnly. Compilation uses the separate
|
||||
-CheckBuildEnvironment mode, which refuses any signing material without importing a key.
|
||||
|
||||
@@ -38,6 +39,10 @@ function Write-Warn([string] $Message) {
|
||||
if ($env:GITHUB_ACTIONS) { Write-Output "::warning::$Message" } else { Write-Warning $Message }
|
||||
}
|
||||
|
||||
function Write-Note([string] $Message) {
|
||||
if ($env:GITHUB_ACTIONS) { Write-Output "::notice::$Message" } else { Write-Output $Message }
|
||||
}
|
||||
|
||||
function Find-SignTool {
|
||||
if ($env:SIGNTOOL) { return $env:SIGNTOOL }
|
||||
$onPath = Get-Command signtool.exe -ErrorAction SilentlyContinue
|
||||
@@ -64,6 +69,11 @@ if ($CheckBuildEnvironment) {
|
||||
}
|
||||
return
|
||||
}
|
||||
$allowUnsigned = switch -CaseSensitive ([string]$env:CRAFT_ALLOW_UNSIGNED) {
|
||||
'' { $false }
|
||||
'1' { $true }
|
||||
default { throw "CRAFT_ALLOW_UNSIGNED must be 1 or unset, got '$env:CRAFT_ALLOW_UNSIGNED'" }
|
||||
}
|
||||
$haveCert = [bool]$env:WINDOWS_CERTIFICATE
|
||||
$haveAzure = -not ($azureVars | Where-Object { -not [Environment]::GetEnvironmentVariable($_) })
|
||||
|
||||
@@ -78,7 +88,8 @@ if (-not $Files) { throw 'At least one file is required for signing' }
|
||||
$Files = $Files | ForEach-Object { (Resolve-Path $_).Path }
|
||||
|
||||
if (-not $haveCert -and -not $haveAzure) {
|
||||
Write-Warn "Windows signing secrets not set (WINDOWS_CERTIFICATE or AZURE_*): leaving unsigned: $($Files -join ', ')"
|
||||
$message = "Windows signing secrets not set (WINDOWS_CERTIFICATE or AZURE_*): leaving unsigned: $($Files -join ', ')"
|
||||
if ($allowUnsigned) { Write-Note $message } else { Write-Warn $message }
|
||||
exit 0
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,17 @@ sonar.sources=.
|
||||
sonar.tests=.
|
||||
sonar.test.inclusions=**/tests/**,**/tests.rs,**/*_tests.rs,**/tests_*.rs
|
||||
|
||||
# The coverage job writes lcov.info at the root, where sonar.sources=. would index it.
|
||||
sonar.exclusions=lcov.info
|
||||
|
||||
# Duplication skips test files, the UI command table and the MCP catalog generated from it.
|
||||
# The shared Sonar workflow reads this property from a single line and adds **/i18n/** to it.
|
||||
sonar.cpd.exclusions=**/tests/**,**/tests.rs,**/*_tests.rs,**/tests_*.rs,crates/ui-egui/src/menus/ui_commands.rs,crates/mcp/src/ui_catalog.rs
|
||||
|
||||
# CI runs the scripts in packaging/ and scripts/ with Python 3.12 (Ubuntu 24.04), 3.13
|
||||
# (setup-python in the nightly jobs) and 3.15 (macOS 15).
|
||||
sonar.python.version=3.12, 3.13, 3.14, 3.15
|
||||
|
||||
# S4790 (weak hash): MD5 is the key derivation of the PDF standard security handler revisions 2-4
|
||||
# (ISO 32000-1 §7.6.3.3), which PDF 1.3-1.6 files use. It is needed to read those files and to write
|
||||
# the compatibility the user picks, not chosen for new security: the default is 256-bit AES
|
||||
|
||||
@@ -5,7 +5,7 @@ use std::process::Command;
|
||||
|
||||
use serde_json::Value;
|
||||
|
||||
const REV: &str = "186a229c8da8db5916f8a863dfd894f1879af735";
|
||||
const REV: &str = "2680a3b3fe464c7afa3d260b33a828fa94e12f6d";
|
||||
const PACKAGES: &[(&str, &str, &str)] = &[
|
||||
("craft-pdf", "0.1.0", REV),
|
||||
("krilla", "0.8.2", REV),
|
||||
|
||||
Reference in new issue
Block a user