diff --git a/Cargo.lock b/Cargo.lock index 5f9a7814c0..b70fa4247b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8712,6 +8712,7 @@ dependencies = [ "vectorcraft-three-d", "vectorcraft-tools", "wat", + "web-time", ] [[package]] diff --git a/apps/vectorcraft-web/src/keys.rs b/apps/vectorcraft-web/src/keys.rs index 5eab667472..3d388d1720 100644 --- a/apps/vectorcraft-web/src/keys.rs +++ b/apps/vectorcraft-web/src/keys.rs @@ -9,6 +9,7 @@ use craft::keymap::Chord; // PLAN: assumed path `craft::ui::runtime::commands` for the ui contract's `commands` module. +#[cfg(target_arch = "wasm32")] use craft::ui::runtime::commands; use egui::{Key, Modifiers}; @@ -33,6 +34,7 @@ pub(crate) fn browser_chord(key: &str, code: &str, modifiers: Modifiers, alt_gra /// Whether the browser's own action for a key press is cancelled: the keymap in effect, the /// user's shortcuts included, binds its chord. Before the first frame nothing is bound. +#[cfg(target_arch = "wasm32")] pub(crate) fn kept_from_browser(ctx: &egui::Context, key: &str, code: &str, modifiers: Modifiers, alt_graph: bool) -> bool { browser_chord(key, code, modifiers, alt_graph).is_some_and(|chord| commands::holder(ctx, &chord).is_some()) } diff --git a/apps/vectorcraft-web/src/pencil.rs b/apps/vectorcraft-web/src/pencil.rs index 5970bb0181..5b5cec5a69 100644 --- a/apps/vectorcraft-web/src/pencil.rs +++ b/apps/vectorcraft-web/src/pencil.rs @@ -22,9 +22,9 @@ use std::cell::RefCell; #[cfg(target_arch = "wasm32")] use std::rc::Rc; -use egui::{Event, PointerButton, Pos2, TouchDeviceId, TouchId, TouchPhase}; use craft::behavior::PointerSample; use craft::ui::runtime::pen::PenSource; +use egui::{Event, PointerButton, Pos2, TouchDeviceId, TouchId, TouchPhase}; use vectorcraft_ui_egui::touch::{self, Source}; #[cfg(target_arch = "wasm32")] use wasm_bindgen::JsCast as _; @@ -38,6 +38,7 @@ const FINGER_DEVICE: TouchDeviceId = TouchDeviceId(2); const ERASER_BUTTON: i16 = 5; /// The pen and finger contacts followed, and the egui events they made since the last frame. +#[derive(Default)] pub struct Pointers { events: Vec, /// The pen pressing, by pointer id. @@ -54,12 +55,6 @@ pub struct Pointers { source: PenSource, } -impl Default for Pointers { - fn default() -> Self { - Self { events: vec![], pen: None, fingers: vec![], primary: None, button: None, eraser: false, source: PenSource::default() } - } -} - #[cfg(target_arch = "wasm32")] pub type SharedPointers = Rc>; diff --git a/apps/vectorcraft/src/main.rs b/apps/vectorcraft/src/main.rs index 5d5e82f841..08c6aceb61 100644 --- a/apps/vectorcraft/src/main.rs +++ b/apps/vectorcraft/src/main.rs @@ -765,8 +765,10 @@ fn main() -> std::process::ExitCode { #[cfg(target_os = "macos")] { open_documents::set_ui(&cc.egui_ctx); - // PLAN: menus-w7 installs the macOS menu bar into `app.services.native_menu` here unless `in_window_menus`. - let _ = in_window_menus; + // The macOS menu bar, installed now so winit's default menu doesn't stay up. + if !in_window_menus { + app.services.native_menu = vectorcraft_ui_egui::menus::native::install(&cc.egui_ctx, &mut app); + } } #[cfg(not(target_os = "macos"))] { diff --git a/crates/engine/src/cmd/fileio/pdf.rs b/crates/engine/src/cmd/fileio/pdf.rs index 7899110e72..819895414c 100644 --- a/crates/engine/src/cmd/fileio/pdf.rs +++ b/crates/engine/src/cmd/fileio/pdf.rs @@ -9,8 +9,8 @@ use serde::Deserialize; use serde_json::{Value, json}; use vectorcraft_doc::{Document, Node, NodeKind}; use vectorcraft_pdf::{ - APP, ActiveProfiles, Overprint, PdfError, PdfOptions, PdfPreset, PdfSettings, Standard, THUMBNAIL_SIZE, Thumbnail, default_preset_name, leaves_out_bleed, - page_bleed, + APP, ActiveProfiles, Overprint, PdfError, PdfOptions, PdfPreset, PdfSettings, Standard, THUMBNAIL_SIZE, Thumbnail, default_preset_name, + leaves_out_bleed, page_bleed, }; use super::super::flatten::{FlattenOptions, flatten_document, see_through_images}; @@ -20,7 +20,6 @@ use crate::EngineError; const C: &str = "document.exportPdf"; - /// The PDF options `document.formats` lists; `document.exportPdf` documents every field. pub(crate) const OPTIONS: &[FormatOption] = &[ super::ARTBOARD, diff --git a/crates/engine/src/tests/emptytype.rs b/crates/engine/src/tests/emptytype.rs index 45d90042a6..9684312015 100644 --- a/crates/engine/src/tests/emptytype.rs +++ b/crates/engine/src/tests/emptytype.rs @@ -302,4 +302,3 @@ fn ime_target_survives_edits_and_changes_with_the_document() { let second = s.tool_ime_target(v).expect("the new document's type has a target"); assert_ne!(first.0, second.0, "a document replacement is a new IME owner"); } - diff --git a/crates/mcp/src/tests.rs b/crates/mcp/src/tests.rs index d35bf9affd..7c3d717d5a 100644 --- a/crates/mcp/src/tests.rs +++ b/crates/mcp/src/tests.rs @@ -1260,7 +1260,8 @@ fn remote_rejects_uncorrelated_replies_without_replaying() { // The line the app sends instead of the edit's answer, made from the edit's request, and // whether it answers the edit: a reply with no id or a null one answers the call in flight, // one with another id (or the id as a string) is skipped while the call waits for its own. - let replies: [(fn(&Value) -> String, bool); 6] = [ + type Reply = fn(&Value) -> String; + let replies: [(Reply, bool); 6] = [ (|_| json!({"ok": true, "result": {}}).to_string(), true), (|_| json!({"id": null, "ok": true, "result": {}}).to_string(), true), (|msg| json!({"id": msg["id"].to_string(), "ok": true, "result": {}}).to_string(), false), diff --git a/crates/mcp/src/ui_catalog.rs b/crates/mcp/src/ui_catalog.rs index e0c1425c0d..01f14628f2 100644 --- a/crates/mcp/src/ui_catalog.rs +++ b/crates/mcp/src/ui_catalog.rs @@ -570,7 +570,12 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "", "{double?: bool, toolbar?: name} show the toolbar's tools (with `toolbar`, that toolbar made with New Toolbar's) in two columns (true), one (false) or toggle (omitted), as the double arrow at the top of the toolbar does; returns the new state", ), - ("window.toolbarAdvanced", "Toolbar: Advanced / Basic", "", "{}"), + ( + "window.toolbarAdvanced", + "Toolbar: Advanced / Basic", + "", + "{advanced?: bool} give the Tools panel the Advanced toolbar (true) or the Basic one (false), as the All Tools drawer's menu does, which then edits the Tools panel's toolbar also when it was editing one made with New Toolbar; omitted, toggle between them; returns the new state", + ), ( "window.toolbarCompact", "Compact Tools", diff --git a/crates/pdf/src/encrypt.rs b/crates/pdf/src/encrypt.rs index 8ae0d01a80..6ee43ef05d 100644 --- a/crates/pdf/src/encrypt.rs +++ b/crates/pdf/src/encrypt.rs @@ -24,7 +24,6 @@ mod lexer; pub(crate) use lexer::{Lexer, Obj, Spanned, Tok, int, is_white}; - /// The standard security handler revision written for PDF version `c`: 3 (RC4, metadata always /// encrypted), 4 (crypt filters: RC4 or AES-128) or 6 (AES-256). fn revision(c: Compatibility) -> u8 { @@ -36,7 +35,6 @@ fn revision(c: Compatibility) -> u8 { } } - // ---------- cryptography ---------- /// Padding of passwords (revisions 2–4). diff --git a/crates/pdf/src/tests/cmykimages.rs b/crates/pdf/src/tests/cmykimages.rs index e0ba33b6b0..8c41809ebd 100644 --- a/crates/pdf/src/tests/cmykimages.rs +++ b/crates/pdf/src/tests/cmykimages.rs @@ -1564,7 +1564,8 @@ fn press_quality_writes_an_rgb_image_in_a_cmyk_document_as_cmyk() { /// out CMYK. #[test] fn press_quality_writes_cmyk_in_an_rgb_document_too() { - let press = || PdfOptions { settings: builtin_preset("Press Quality", APP).unwrap().settings, created: Some(1_700_000_000), ..Default::default() }; + let press = + || PdfOptions { settings: builtin_preset("Press Quality", APP).unwrap().settings, created: Some(1_700_000_000), ..Default::default() }; assert_eq!(press().settings.output.destination, DOCUMENT_CMYK); let ink = [0u8, 102, 255, 0]; let tiff = ImageBlob::cmyk_tiff(&Inks::new(4, 4, flat(ink, 16)).unwrap()).unwrap(); diff --git a/crates/pdf/src/tests/editing.rs b/crates/pdf/src/tests/editing.rs index 9251870dba..cba8a24279 100644 --- a/crates/pdf/src/tests/editing.rs +++ b/crates/pdf/src/tests/editing.rs @@ -123,7 +123,6 @@ fn the_legacy_name_is_read_and_plain_pdfs_have_no_editing_data() { assert_eq!(editing(&r.bytes), None); } - /// A tiny PDF made of the given objects (numbered from 1), with the cross-reference table written. fn raw_pdf(objects: &[String]) -> Vec { raw_pdf_bytes(objects.iter().map(|o| o.clone().into_bytes())) diff --git a/crates/pdf/src/tests/encrypt.rs b/crates/pdf/src/tests/encrypt.rs index 304682acb2..c6b8772ff3 100644 --- a/crates/pdf/src/tests/encrypt.rs +++ b/crates/pdf/src/tests/encrypt.rs @@ -119,7 +119,6 @@ fn a_permissions_password_alone_opens_without_a_password_and_restricts() { } } - #[test] fn unicode_passwords_open_aes256_files() { let bytes = protected(Compatibility::Pdf20, security("pässwörd", "ünïcode"), false); diff --git a/crates/pdf/src/tests/pdf13.rs b/crates/pdf/src/tests/pdf13.rs index 0415cb240b..61795a4b82 100644 --- a/crates/pdf/src/tests/pdf13.rs +++ b/crates/pdf/src/tests/pdf13.rs @@ -26,7 +26,6 @@ fn options(v: serde_json::Value) -> PdfOptions { PdfOptions { settings: serde_json::from_value(v).unwrap(), created: Some(0), ..PdfOptions::uncompressed() } } - #[test] fn pdf_1_3_files_say_so_and_have_no_transparency() { let mut d = doc(1.0); diff --git a/crates/tools/src/text/tests.rs b/crates/tools/src/text/tests.rs index fd433b9291..d7682e690f 100644 --- a/crates/tools/src/text/tests.rs +++ b/crates/tools/src/text/tests.rs @@ -1108,7 +1108,6 @@ fn ime_ranges_convert_characters_to_bytes() { assert_eq!(char_range_to_bytes("ががく", backwards), None, "backwards"); } - #[test] fn marked_text_is_underlined_with_the_converting_clause_thick() { let (mut d, id, mut tool) = editing("曲"); @@ -1925,7 +1924,6 @@ fn type_on_a_path_has_its_ports_beyond_its_brackets() { assert!(near(port_centre(t, Port::In, 0.5), Point::new(160.0 - PORT_RISE_PX / 2.0, 300.0)), "screen pixels at 200%"); } - /// Deleting around a selection removes only the surrounding text, keeps the reversed selection /// direction, and leaves it for the following commit to replace. #[test] @@ -1978,7 +1976,6 @@ fn ime_target_is_stable_within_an_edit_session() { assert_ne!(second.2, first.2, "a new edit session is a replacement epoch"); } - /// Deletion counts start at the caret, including when it is in a later styled run. Character /// units count Unicode scalars; byte units round inward instead of cutting a multibyte scalar. #[test] @@ -2033,7 +2030,6 @@ fn a_recreated_type_tool_gets_a_new_replacement_epoch() { assert_ne!(a.2, b.2, "edit sessions are numbered process-wide, not per tool"); } - #[test] fn shift_enter_inserts_soft_return() { let (mut d, id, mut tool) = editing("Hello World"); diff --git a/crates/tools/src/text/tool.rs b/crates/tools/src/text/tool.rs index 23356673fd..8405eb39aa 100644 --- a/crates/tools/src/text/tool.rs +++ b/crates/tools/src/text/tool.rs @@ -1,8 +1,8 @@ use super::plain::{char_range_to_bytes, plain_ceil_boundary, plain_chars_after, plain_chars_before, plain_floor_boundary, plain_len}; use super::ports::{ported, ports, ports_shown}; use super::{ - Action, BezPath, Cursor, Mode, Mods, NodeId, Overlay, Point, PointerEvent, PointerKind, Preedit, Range, Rect, Shape, - SurroundingUnit, TextKind, TextRun, Tool, ToolContext, ToolKey, TypeTool, Value, edit, json, + Action, BezPath, Cursor, Mode, Mods, NodeId, Overlay, Point, PointerEvent, PointerKind, Preedit, Range, Rect, Shape, SurroundingUnit, TextKind, + TextRun, Tool, ToolContext, ToolKey, TypeTool, Value, edit, json, }; impl Tool for TypeTool { @@ -681,4 +681,3 @@ impl Tool for TypeTool { } } } - diff --git a/crates/ui-egui/Cargo.toml b/crates/ui-egui/Cargo.toml index 7484998eca..fb7c31eed0 100644 --- a/crates/ui-egui/Cargo.toml +++ b/crates/ui-egui/Cargo.toml @@ -84,6 +84,11 @@ craft = { workspace = true, features = ["dialogs", "update"] } # Cargo.lock with the time-zone crates `clock` uses. chrono = { workspace = true, features = ["clock"] } +[target.'cfg(target_arch = "wasm32")'.dependencies] +# The status bar's Date and Time readout reads the page's clock with this crate in the web build. It +# is MIT OR Apache-2.0 and already in the build through eframe. +web-time = "1" + # The current user's id (`geteuid`): Preview in Browser uses its temporary folder only when that # user owns it (src/dialogs/save_for_web.rs). Already in Cargo.lock (tempfile), so this adds no # new crate. diff --git a/crates/ui-egui/src/addons/arrange.rs b/crates/ui-egui/src/addons/arrange.rs index 093d91695a..52b8130b1b 100644 --- a/crates/ui-egui/src/addons/arrange.rs +++ b/crates/ui-egui/src/addons/arrange.rs @@ -11,7 +11,7 @@ use craft::ui::patterns::form_dialogs::{DialogFields, Param, ParamDialog, ParamK use craft::ui::runtime::env::{LengthUnits, UnitKind}; use serde_json::{Value, json}; -use super::dialogs::{Confirm, Spec}; +use super::dialogs::Spec; use crate::VectorcraftApp; use crate::canvas::rulers::general_lengths; use crate::dialogs::form; @@ -67,11 +67,11 @@ pub fn menu() -> Vec { ] } -static GRID_SPEC: Spec = Spec { command: GRID, params: grid_params, found: None, confirm: Confirm::Commit }; -static REPLACE_SPEC: Spec = Spec { command: REPLACE, params: replace_params, found: None, confirm: Confirm::Commit }; -static SIZE_SPEC: Spec = Spec { command: SIZE, params: size_params, found: None, confirm: Confirm::Commit }; -static OPACITY_SPEC: Spec = Spec { command: OPACITY, params: opacity_params, found: None, confirm: Confirm::Commit }; -static SORT_SPEC: Spec = Spec { command: SORT, params: sort_params, found: None, confirm: Confirm::Commit }; +static GRID_SPEC: Spec = Spec { command: GRID, params: grid_params, found: None }; +static REPLACE_SPEC: Spec = Spec { command: REPLACE, params: replace_params, found: None }; +static SIZE_SPEC: Spec = Spec { command: SIZE, params: size_params, found: None }; +static OPACITY_SPEC: Spec = Spec { command: OPACITY, params: opacity_params, found: None }; +static SORT_SPEC: Spec = Spec { command: SORT, params: sort_params, found: None }; /// The dialog over `rows`, titled by the heading of `command`. fn dialog<'a>(command: &str, rows: Vec) -> ParamDialog<'a> { diff --git a/crates/ui-egui/src/addons/color/legend.rs b/crates/ui-egui/src/addons/color/legend.rs index 4a6fcd1312..9f4d6a8729 100644 --- a/crates/ui-egui/src/addons/color/legend.rs +++ b/crates/ui-egui/src/addons/color/legend.rs @@ -7,7 +7,7 @@ use craft::ui::patterns::form_dialogs::{DialogFields, FieldValue, Param, ParamDi use serde_json::{Value, json}; use crate::VectorcraftApp; -use crate::addons::dialogs::{self, Confirm, Spec}; +use crate::addons::dialogs::{self, Spec}; use crate::canvas::rulers::general_lengths; /// The command. @@ -16,7 +16,7 @@ pub const COMMAND: &str = "addon.color.swatchLegend"; pub const VALUES: [(&str, &str); 5] = [("hex", "HEX"), ("rgb", "RGB"), ("cmyk", "CMYK"), ("lab", "Lab"), ("gray", "Grayscale")]; /// How the dialog's values reach the command. -pub(crate) static SPEC: Spec = Spec { command: COMMAND, params, found: None, confirm: Confirm::Commit }; +pub(crate) static SPEC: Spec = Spec { command: COMMAND, params, found: None }; /// The command's params from the dialog's fields. pub(crate) fn params(fields: &DialogFields) -> Value { diff --git a/crates/ui-egui/src/addons/dialogs.rs b/crates/ui-egui/src/addons/dialogs.rs index cd23bab7de..55ad5dd64d 100644 --- a/crates/ui-egui/src/addons/dialogs.rs +++ b/crates/ui-egui/src/addons/dialogs.rs @@ -1,11 +1,11 @@ //! The add-on dialogs' host side: each is a hosted parameter dialog keyed by its command, whose -//! values reach that command as params. `Commit` dialogs preview on the canvas and run their -//! command at OK as one undo step; `Options` dialogs hold their OK and answer through `tool.setOption`. +//! values reach that command as params. Each previews on the canvas and runs its command at OK as +//! one undo step. use std::mem; use craft::ui::dialog::{DialogResult, StackDialog}; -use craft::ui::patterns::form_dialogs::{DialogFields, HostedParamDialog, ParamDialog, ParamResult}; +use craft::ui::patterns::form_dialogs::{DialogFields, HostedParamDialog, ParamDialog}; use egui::Context; use serde_json::{Value, json}; @@ -16,13 +16,8 @@ use crate::dialogs::preview::LivePreview; #[cfg(test)] pub(crate) mod tests; -/// What OK does for a dialog. -pub(crate) enum Confirm { - /// Run the command as one undo step, keeping the live preview ([`pump`] answers it). - Commit, - /// Run `tool.setOption` with the params; a refusal keeps the dialog open. - Options, -} +/// Shows a preview run's answer (or its error) in the dialog. +pub(crate) type Found = fn(&mut HostedParamDialog, Result<&Value, &str>); /// What one add-on dialog is: the command it answers for and how its values become that command's params. pub(crate) struct Spec { @@ -31,19 +26,17 @@ pub(crate) struct Spec { /// The command's params from the dialog's values. pub params: fn(&DialogFields) -> Value, /// Receives the answer of each preview run (or its error), to show it in the dialog. - pub found: Option)>, - /// What OK does. - pub confirm: Confirm, + pub found: Option, } -/// The `Commit` dialog open now and the live preview it drives; one at a time, since a preview owns the document. +/// The add-on dialog open now and the live preview it drives; one at a time, since a preview owns the document. #[derive(Default)] pub(crate) struct AddonDialogs { open: Option<(craft::ui::dialog::DialogId, &'static Spec)>, preview: LivePreview, } -/// Closes the open `Commit` dialog without an answer and rolls its preview back. +/// Closes the open add-on dialog without an answer and rolls its preview back. fn close_open(app: &mut VectorcraftApp) { let Some((id, _)) = app.addon_dialogs.open.take() else { return }; if let (Some(host), Some(ctx)) = (app.dialogs(), app.ui_ctx.clone()) { @@ -65,22 +58,11 @@ pub(crate) fn open( ) -> Result { let ctx = app.ui_ctx.clone().ok_or("no window")?; let dialog = HostedParamDialog::new(&ctx, spec.command, fields, build); - match spec.confirm { - Confirm::Commit => { - let host = app.dialogs().ok_or("no window")?; - close_open(app); - let id = dialog.id(); - host.with(|h| h.open(dialog)); - app.addon_dialogs.open = Some((id, spec)); - } - Confirm::Options => { - let params = spec.params; - crate::dialogs::host::open_held(app, dialog, move |app, result: &ParamResult| { - app.run("tool.setOption", params(&result.fields)).map(|_| ()) - }) - .ok_or("no window")?; - } - } + let host = app.dialogs().ok_or("no window")?; + close_open(app); + let id = dialog.id(); + host.with(|h| h.open(dialog)); + app.addon_dialogs.open = Some((id, spec)); Ok(json!({ "dialog": spec.command })) } @@ -101,7 +83,7 @@ pub(crate) fn open_from_menu(app: &mut VectorcraftApp, id: &str) -> Option bool { - picker.requests().last().map(|r| r.kind.clone()) == Some(PickKind::Folder) + picker.requests().last().map(|r| r.kind) == Some(PickKind::Folder) } /// A new, empty folder of its own for test `name`. diff --git a/crates/ui-egui/src/addons/packaging/preview.rs b/crates/ui-egui/src/addons/packaging/preview.rs index 5d1ecb8484..e6ab1ac650 100644 --- a/crates/ui-egui/src/addons/packaging/preview.rs +++ b/crates/ui-egui/src/addons/packaging/preview.rs @@ -106,7 +106,7 @@ impl FoldPreviewWords { "bottom" => &self.bottom, _ => &self.three_quarter, }; - Label::from(word.clone()) + word.clone() } } diff --git a/crates/ui-egui/src/addons/packaging/preview/tests.rs b/crates/ui-egui/src/addons/packaging/preview/tests.rs index 42d8bf13a1..fcaf37a7b5 100644 --- a/crates/ui-egui/src/addons/packaging/preview/tests.rs +++ b/crates/ui-egui/src/addons/packaging/preview/tests.rs @@ -377,7 +377,8 @@ enum Gesture { #[test] fn the_view_gestures_change_the_settings() { - let rows: [(Gesture, fn(&Settings) -> bool, &str); 7] = [ + type Check = fn(&Settings) -> bool; + let rows: [(Gesture, Check, &str); 7] = [ ( Gesture::Drag(vec2(40.0, 20.0)), |s| s.rotate_y > 5.0 && s.rotate_y <= 20.0 + 1e-9 && s.rotate_x > 2.0 && s.rotate_x <= 10.0 + 1e-9, diff --git a/crates/ui-egui/src/addons/pathtools/bridge.rs b/crates/ui-egui/src/addons/pathtools/bridge.rs index 0107570f64..ffe710633c 100644 --- a/crates/ui-egui/src/addons/pathtools/bridge.rs +++ b/crates/ui-egui/src/addons/pathtools/bridge.rs @@ -8,7 +8,7 @@ use craft::ui::runtime::env::UnitKind; use serde_json::{Value, json}; use crate::VectorcraftApp; -use crate::addons::dialogs::{self, Confirm, Spec}; +use crate::addons::dialogs::{self, Spec}; use crate::canvas::rulers::general_lengths; /// The command. @@ -24,7 +24,7 @@ const REACHES: std::ops::RangeInclusive = 0.0..=10000.0; const REACH: f64 = 10.0; /// How the dialog's values reach the command. -pub(crate) static SPEC: Spec = Spec { command: COMMAND, params, found: None, confirm: Confirm::Commit }; +pub(crate) static SPEC: Spec = Spec { command: COMMAND, params, found: None }; /// The command's parameters from the dialog's fields: the radius, or with Constant Gap the gap. fn params(fields: &DialogFields) -> Value { diff --git a/crates/ui-egui/src/addons/pathtools/dashes.rs b/crates/ui-egui/src/addons/pathtools/dashes.rs index 9edf2c31b5..7c90a560a8 100644 --- a/crates/ui-egui/src/addons/pathtools/dashes.rs +++ b/crates/ui-egui/src/addons/pathtools/dashes.rs @@ -5,7 +5,7 @@ use craft::ui::patterns::form_dialogs::{DialogFields, FieldValue, Param, ParamDi use serde_json::{Value, json}; use crate::VectorcraftApp; -use crate::addons::dialogs::{self, Confirm, Spec}; +use crate::addons::dialogs::{self, Spec}; use crate::canvas::rulers::general_lengths; /// The command. @@ -15,7 +15,7 @@ const DASHES: std::ops::RangeInclusive = 0.01..=1e6; const GAPS: std::ops::RangeInclusive = 0.0..=1e6; /// How the dialog's values reach the command. -pub(crate) static SPEC: Spec = Spec { command: COMMAND, params, found: None, confirm: Confirm::Commit }; +pub(crate) static SPEC: Spec = Spec { command: COMMAND, params, found: None }; /// The command's parameters from the dialog's fields. pub(crate) fn params(fields: &DialogFields) -> Value { diff --git a/crates/ui-egui/src/addons/pathtools/set_corners.rs b/crates/ui-egui/src/addons/pathtools/set_corners.rs index 1a0fff6d89..6a4bb79a2d 100644 --- a/crates/ui-egui/src/addons/pathtools/set_corners.rs +++ b/crates/ui-egui/src/addons/pathtools/set_corners.rs @@ -9,7 +9,7 @@ use serde_json::{Value, json}; use vectorcraft_tools::addons::corner_tool::{ID, MAX_RADIUS, RADIUS}; use crate::VectorcraftApp; -use crate::addons::dialogs::{self, Confirm, Spec}; +use crate::addons::dialogs::{self, Spec}; use crate::canvas::rulers::general_lengths; /// The command. @@ -22,7 +22,7 @@ const EVERY: [(&str, &str); 3] = [("all", "All Anchors"), ("odd", "Odd-Numbered const ANGLES: std::ops::RangeInclusive = 0.0..=180.0; /// How the dialog's values reach the command. -pub(crate) static SPEC: Spec = Spec { command: COMMAND, params, found: None, confirm: Confirm::Commit }; +pub(crate) static SPEC: Spec = Spec { command: COMMAND, params, found: None }; /// The command's parameters from the dialog's fields. pub(crate) fn params(fields: &DialogFields) -> Value { diff --git a/crates/ui-egui/src/addons/pathtools/tangent_circle.rs b/crates/ui-egui/src/addons/pathtools/tangent_circle.rs index 9a48a6eab7..94e5daa51c 100644 --- a/crates/ui-egui/src/addons/pathtools/tangent_circle.rs +++ b/crates/ui-egui/src/addons/pathtools/tangent_circle.rs @@ -6,7 +6,7 @@ use craft::ui::patterns::form_dialogs::{DialogFields, FieldValue, HostedParamDia use serde_json::{Value, json}; use crate::VectorcraftApp; -use crate::addons::dialogs::{self, Confirm, Spec}; +use crate::addons::dialogs::{self, Spec}; use crate::canvas::rulers::general_lengths; /// The command. @@ -19,7 +19,7 @@ const MAX_CIRCLES: u64 = 64; const RADIUS: f64 = 36.0; /// How the dialog's values reach the command; the preview's answer says how many circles were found. -pub(crate) static SPEC: Spec = Spec { command: COMMAND, params, found: Some(found), confirm: Confirm::Commit }; +pub(crate) static SPEC: Spec = Spec { command: COMMAND, params, found: Some(found) }; /// The circle number the choice holds (an option id): 0 is every circle, `k` the k-th, counted from 1. fn circle(fields: &DialogFields) -> u64 { diff --git a/crates/ui-egui/src/addons/typetools.rs b/crates/ui-egui/src/addons/typetools.rs index 7b6b30423a..58e1b005ca 100644 --- a/crates/ui-egui/src/addons/typetools.rs +++ b/crates/ui-egui/src/addons/typetools.rs @@ -8,7 +8,7 @@ use craft::ui::runtime::env::UnitKind; use serde_json::{Value, json}; use crate::VectorcraftApp; -use crate::addons::dialogs::{self, Confirm, Spec}; +use crate::addons::dialogs::{self, Spec}; use crate::menus::{c, cp}; /// The command the dialog runs. @@ -48,7 +48,7 @@ fn attribute(key: &str) -> &'static Attribute { } /// How the dialog's values reach the command. -pub(crate) static SPEC: Spec = Spec { command: COMMAND, params, found: None, confirm: Confirm::Commit }; +pub(crate) static SPEC: Spec = Spec { command: COMMAND, params, found: None }; /// The command's parameters from the dialog's fields; an end of the ramp not set yet is the attribute's own. pub(crate) fn params(fields: &DialogFields) -> Value { diff --git a/crates/ui-egui/src/app/control.rs b/crates/ui-egui/src/app/control.rs index 35858ccf85..7d7d35ba46 100644 --- a/crates/ui-egui/src/app/control.rs +++ b/crates/ui-egui/src/app/control.rs @@ -99,16 +99,6 @@ impl VectorcraftApp { } } - /// The UI phase of a pass: counts the pass toward the captures' settling and issues the due - /// ones; a capture that expired or lost its window is answered here. - pub(crate) fn issue_captures(&mut self, ctx: &egui::Context) { - let document = self.document_identity(); - let Some(channel) = self.channel.as_mut() else { return }; - channel.captures.note_pass(); - let finished = channel.captures.issue(&WindowHost::of(ctx), motion::now(), document); - self.finish_captures(finished); - } - /// Replies to finished captures; a capture with a path is written by [`write_automation_file`]. fn finish_captures(&mut self, finished: Vec) { if finished.is_empty() { diff --git a/crates/ui-egui/src/caches.rs b/crates/ui-egui/src/caches.rs index 03d2559ab9..dbf79f25a4 100644 --- a/crates/ui-egui/src/caches.rs +++ b/crates/ui-egui/src/caches.rs @@ -117,7 +117,7 @@ pub struct CanvasCache { /// How many objects Start Global Edit would edit, for the key the Properties panel builds. pub(crate) global_edit_count: Option<(crate::panels::properties::GlobalEditKey, usize)>, /// The selected live shape's angle, for (document uid, revision, kind of shape). - pub shape_angle: Option<((u64, u64, std::mem::Discriminant), Option)>, + pub shape_angle: Option, /// The Image Trace presets, for the session's preset revision. pub(crate) trace_presets: Option<(u64, Arc)>, /// What the Image Trace panel traces, for (document uid, revision). @@ -131,25 +131,25 @@ pub struct CanvasCache { /// The SVG Options dialog's SVG code, for every input it reads (compared with `==`). pub(crate) svg_code: Option<(crate::dialogs::svg_options::SvgCodeKey, Arc)>, /// The Export for Screens dialog's artboard thumbnails, for (document uid, revision). - pub artboard_thumbs: Option<((u64, u64), Vec>)>, + pub artboard_thumbs: Option, /// The families the document uses, for the document's fonts key. pub document_families: Option<(FontsKey, Arc<[String]>)>, /// The families installed lately: the font generation, when it was asked, the families and /// the newest install time among them. - pub recently_added: Option<(u64, SystemTime, Arc<[String]>, Option)>, + pub recently_added: Option, /// The kerning at the Type tool's caret, for (document uid, revision, text object, byte). pub caret_kerning: Option<((u64, u64, NodeId, usize), f64)>, /// The alternates the Glyphs panel found at the selection. pub(crate) glyphs_found: crate::panels::glyphs::Found, /// The faces the Glyphs panel's positional forms come from: (document uid, revision, font /// generation, the selection's object and range, the selected objects). - pub glyph_form_faces: Option<((u64, u64, u64, Option<(NodeId, usize, usize)>, Vec), Vec)>, + pub glyph_form_faces: Option, /// The selected characters' outlines on the page for the alternates row: (document uid, /// revision, text object, range) to the quads and whether they are cut. - pub character_quads: Option<((u64, u64, NodeId, usize, usize), (Vec<[Point; 4]>, bool))>, + pub character_quads: Option, /// The Tabs panel's guide line, for (document uid, text object, paragraph, revision): layout is /// too slow to run on every frame of a stop's drag. - pub tabs_guide_axis: Option<((u64, NodeId, usize, u64), Option<(Point, Point, Vec2)>)>, + pub tabs_guide_axis: Option, /// The Appearance panel's summary of the selection, which holds the document, revision and /// subjects it was made for. pub(crate) appearance_summary: Option>, @@ -257,6 +257,29 @@ pub struct SymbolInstances { /// [`CanvasCache::print_tiling`]: the print tiling of (document uid, revision). pub type PrintTilingCache = ((u64, u64), std::sync::Arc>); +/// [`CanvasCache::shape_angle`]: the selected live shape's angle, for (document uid, revision, kind +/// of shape). +pub type ShapeAngleCache = ((u64, u64, std::mem::Discriminant), Option); + +/// [`CanvasCache::artboard_thumbs`]: the artboard thumbnails of (document uid, revision). +pub type ArtboardThumbsCache = ((u64, u64), Vec>); + +/// [`CanvasCache::recently_added`]: the font generation, when it was asked, the families and the +/// newest install time among them. +pub type RecentlyAddedCache = (u64, SystemTime, Arc<[String]>, Option); + +/// [`CanvasCache::glyph_form_faces`]: the faces, for (document uid, revision, font generation, the +/// selection's object and range, the selected objects). +pub type GlyphFormFacesCache = ((u64, u64, u64, Option<(NodeId, usize, usize)>, Vec), Vec); + +/// [`CanvasCache::character_quads`]: the quads and whether they are cut, for (document uid, +/// revision, text object, range). +pub type CharacterQuadsCache = ((u64, u64, NodeId, usize, usize), (Vec<[Point; 4]>, bool)); + +/// [`CanvasCache::tabs_guide_axis`]: the guide line, for (document uid, text object, paragraph, +/// revision). +pub type TabsGuideAxisCache = ((u64, NodeId, usize, u64), Option<(Point, Point, Vec2)>); + #[derive(Clone, Debug, PartialEq)] pub struct CacheKey { pub doc: usize, diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs index 0bd6441006..11b1b1f05b 100644 --- a/crates/ui-egui/src/canvas.rs +++ b/crates/ui-egui/src/canvas.rs @@ -137,7 +137,7 @@ pub(crate) fn show_document(app: &mut VectorcraftApp, ui: &mut Ui, win: Win, kin // Presentation Mode shows the active artboard on the whole screen: it fits again when the screen changes. let refit = !view.fitted || (presenting && view.rect != area); let (request, moved) = if measuring { - (view.request.clone(), view.moved) + (view.request, view.moved) } else { view.rect = area; (view.request.take(), view.moved.take()) diff --git a/crates/ui-egui/src/canvas/artboards.rs b/crates/ui-egui/src/canvas/artboards.rs index 05579876ef..4313aa7b88 100644 --- a/crates/ui-egui/src/canvas/artboards.rs +++ b/crates/ui-egui/src/canvas/artboards.rs @@ -14,9 +14,6 @@ use crate::doc_windows::Win; /// The length on screen, in points, of each arm of an artboard's center mark (a cross), at any zoom. const CENTER_MARK_ARM: f32 = 6.0; -/// The fade's color: black at 40% opacity, which shows each channel under it at 60% of its value. -pub(super) const FADE_OUTSIDE: Color32 = Color32::from_black_alpha(102); - fn closed(r: vectorcraft_geom::Rect) -> BezPath { let mut path = BezPath::new(); path.move_to(Point::new(r.x0, r.y0)); @@ -69,14 +66,16 @@ pub(super) fn border(outline: bool) -> PageBorder { if outline { PageBorder::Line } else { PageBorder::DropShadow } } -/// The pasteboard's color: white in Outline, the paper under Hide Artboards, else the interface's. +/// The pasteboard's color: white in Outline, the paper under Hide Artboards, else User Interface › Canvas Color, or the +/// interface's when that matches the interface brightness. pub(super) fn pasteboard_color(app: &VectorcraftApp, st: &vectorcraft_engine::DocState, outline: bool) -> PasteboardColor { if outline { PasteboardColor::Custom(DataColor::new(Color32::WHITE)) } else if !shows_artboards(app) { PasteboardColor::Custom(DataColor::new(paper_color(&st.doc.setup))) } else { - PasteboardColor::Default + crate::prefs_dialog::canvas_color(&app.session.prefs.canvas_color) + .map_or(PasteboardColor::Default, |c| PasteboardColor::Custom(DataColor::new(c))) } } diff --git a/crates/ui-egui/src/canvas/artboards/tests.rs b/crates/ui-egui/src/canvas/artboards/tests.rs index 7fd90abe5e..54cc9aedec 100644 --- a/crates/ui-egui/src/canvas/artboards/tests.rs +++ b/crates/ui-egui/src/canvas/artboards/tests.rs @@ -58,6 +58,16 @@ fn outline_has_a_white_canvas_line_edges_and_no_paper() { assert!(frames_of(&app, false).iter().all(|f| f.fill.is_some())); } +/// User Interface › Canvas Color paints the pasteboard in Preview; Outline keeps its white one. +#[test] +fn the_canvas_color_preference_paints_the_pasteboard() { + let mut app = app_with(1); + app.run("prefs.set", json!({"key": "canvasColor", "value": "darkGray"})).unwrap(); + let st = app.session.active().unwrap(); + assert_eq!(pasteboard_color(&app, st, false), PasteboardColor::Custom(DataColor::new(Color32::from_gray(0x5a)))); + assert_eq!(pasteboard_color(&app, st, true), PasteboardColor::Custom(DataColor::new(Color32::WHITE))); +} + #[test] fn hidden_artboards_leave_a_paper_canvas_and_the_artboard_tool_brings_them_back() { let mut app = app_with(2); diff --git a/crates/ui-egui/src/canvas/grid.rs b/crates/ui-egui/src/canvas/grid.rs index a7dbd1fe2d..75c4a59286 100644 --- a/crates/ui-egui/src/canvas/grid.rs +++ b/crates/ui-egui/src/canvas/grid.rs @@ -1,48 +1,9 @@ -use craft::color_ui::display::DisplayTransform; use craft::ui::canvas_controls::{CanvasGrid, GridLine}; use craft::ui::style::DataColor; use egui::{Color32, Pos2, Shape, pos2}; use super::VectorcraftApp; -/// The transparency grid's 2 × 2-cell tile in the document's colours (Document Setup), converted -/// into the display profile `display` when there is one, cached per look, and its cell size in -/// screen points. -pub(crate) fn checker_texture( - ctx: &egui::Context, - setup: &vectorcraft_doc::DocSetup, - display: Option<&DisplayTransform>, -) -> (egui::TextureHandle, f32) { - // A tile of its own with a display profile, so a preview drawn in sRGB beside the canvas - // doesn't make the canvas's tile again each frame. - let id = egui::Id::unique("transparency-grid-tile").with(display.is_some()); - (checker_tile(ctx, setup.grid_colors, display, id), setup.grid_size.cell()) -} - -/// The transparency grid's 2 × 2-cell tile in the colors `grid_colors` (the first in the top-left -/// and bottom-right cells), converted into the display profile `display` when there is one, and -/// cached under `id` until the colors change. -pub(crate) fn checker_tile( - ctx: &egui::Context, - grid_colors: [vectorcraft_color::Color; 2], - display: Option<&DisplayTransform>, - id: egui::Id, -) -> egui::TextureHandle { - let colors = grid_colors.map(|c| crate::display_profile::color32(display, crate::panels::c32(&c))); - let cached = ctx.data(|d| d.get_temp::<([Color32; 2], egui::TextureHandle)>(id)).filter(|(c, _)| *c == colors); - cached.map(|(_, t)| t).unwrap_or_else(|| { - let [a, b] = colors; - let img = egui::ColorImage::new([2, 2], vec![a, b, b, a]); - let opts = egui::TextureOptions { wrap_mode: egui::TextureWrapMode::Repeat, ..egui::TextureOptions::NEAREST }; - let t = ctx.load_texture(TRANSPARENCY_GRID, img, opts); - ctx.data_mut(|d| d.insert_temp(id, (colors, t.clone()))); - t - }) -} - -/// Name of the transparency grid's texture. -pub(crate) const TRANSPARENCY_GRID: &str = "transparency grid"; - /// One quad drawn with `tex`: its corners `quad` (from the top left, clockwise) show the texture /// from (0, 0) to (`u`, `v`). pub(super) fn textured_quad(p: &egui::Painter, tex: egui::TextureId, quad: &[Pos2], (u, v): (f32, f32)) { @@ -97,25 +58,6 @@ pub(super) fn pref_color(hex: &str, fallback: Color32) -> Color32 { vectorcraft_color::Color::from_hex(hex).map_or(fallback, |c| crate::panels::c32(&c)) } -/// The part of the segment from `a` to `b` inside `r`, none when the segment misses it. -pub(super) fn clip_segment(a: Pos2, b: Pos2, r: egui::Rect) -> Option<(Pos2, Pos2)> { - let d = b - a; - let (mut t0, mut t1) = (0.0_f32, 1.0_f32); - // Each edge as (the run toward it, the room before it). - for (run, room) in [(-d.x, a.x - r.left()), (d.x, r.right() - a.x), (-d.y, a.y - r.top()), (d.y, r.bottom() - a.y)] { - if run == 0.0 { - if room < 0.0 { - return None; - } - } else if run < 0.0 { - t0 = t0.max(room / run); - } else { - t1 = t1.min(room / run); - } - } - (t0 <= t1).then(|| (a + d * t0, a + d * t1)) -} - /// A ruler label for `v` (in the ruler's unit) on a ruler whose labels are `step` apart: whole /// numbers, or the fewest decimals that write `step` exactly, so a binary step keeps its value /// (an inch ruler's 1/16 reads `0.0625`, not the `0.06` that rounding the step's magnitude gave). diff --git a/crates/ui-egui/src/canvas/overlays.rs b/crates/ui-egui/src/canvas/overlays.rs index 5244438c49..ff55781655 100644 --- a/crates/ui-egui/src/canvas/overlays.rs +++ b/crates/ui-egui/src/canvas/overlays.rs @@ -169,7 +169,7 @@ impl Component for ToolMarks<'_> { fn paint(&mut self, ui: &mut PaintUi<'_>, cx: &Cx<'_, Self>) { let Some(space) = canvas_space(&cx.env) else { return }; let _painter = ui.content_painter(cx); - paint(&ui.draw(), &space.view, self.overlays, &self.options, &cx.style); + paint(&ui.draw(), &space.view, self.overlays, &self.options, cx.style); for o in self.overlays { if let Overlay::SelectionMarquee { enclosed, pointer, .. } = o { let (current, other) = badge_rule(*enclosed); diff --git a/crates/ui-egui/src/canvas/panes/tests.rs b/crates/ui-egui/src/canvas/panes/tests.rs index b7a8e88d0e..d90b13f9c8 100644 --- a/crates/ui-egui/src/canvas/panes/tests.rs +++ b/crates/ui-egui/src/canvas/panes/tests.rs @@ -55,9 +55,12 @@ fn frame_in(app: &mut VectorcraftApp, ctx: &egui::Context, events: Vec, [usize; 2]); + thread_local! { /// The last picture each texture got in the frames [`frame_in`] and [`wait_ready`] ran, as pixels and size. - static UPLOADED: std::cell::RefCell, [usize; 2])>> = Default::default(); + static UPLOADED: std::cell::RefCell> = Default::default(); } /// Notes the last picture each texture got in `delta` in [`UPLOADED`], and handles the uploads. diff --git a/crates/ui-egui/src/canvas/rulers.rs b/crates/ui-egui/src/canvas/rulers.rs index de1242ac04..9aa709e127 100644 --- a/crates/ui-egui/src/canvas/rulers.rs +++ b/crates/ui-egui/src/canvas/rulers.rs @@ -199,7 +199,7 @@ pub(super) fn apply(app: &mut VectorcraftApp, ui: &Ui, out: &RulersOutput) { EditEvent::Begin { .. } => zero_begin(app, ui), EditEvent::Update { value, .. } => zero_update(app, ui, *value), // A release where it began (a click, or dropped back on the corner) moves nothing. - EditEvent::Commit { before, after, .. } if matches!(before, Mixed::Same(start) if start == after) => zero_cancel(app, ui), + EditEvent::Commit { before: Mixed::Same(start), after, .. } if start == after => zero_cancel(app, ui), EditEvent::Commit { after, .. } => zero_commit(app, ui, *after), EditEvent::Cancel { .. } => zero_cancel(app, ui), EditEvent::Set { after, .. } => zero_set(app, *after), diff --git a/crates/ui-egui/src/canvas/rulers/tests.rs b/crates/ui-egui/src/canvas/rulers/tests.rs index 619c5bfd98..363c150ad7 100644 --- a/crates/ui-egui/src/canvas/rulers/tests.rs +++ b/crates/ui-egui/src/canvas/rulers/tests.rs @@ -142,7 +142,7 @@ fn ruler_guide_shift_origin_preview_release_and_history() { let (mut app, ctx) = (app(), crate::testing::ui_context()); let (before, undo) = (app.session.active().unwrap().doc.clone(), undo_len(&app)); let to = Point::new(125.25, 90.5); - zero(&mut app, &ctx, |app, ui| zero_begin(app, ui)); + zero(&mut app, &ctx, zero_begin); zero(&mut app, &ctx, |app, ui| { zero_update(app, ui, to); }); @@ -158,11 +158,11 @@ fn ruler_guide_shift_origin_cancel_preserves_redo() { app.session.execute("shape.rectangle", &json!({"x": 40, "y": 50, "width": 20, "height": 30})).unwrap(); app.session.execute("edit.undo", &json!({})).unwrap(); let before = app.session.active().unwrap().doc.clone(); - zero(&mut app, &ctx, |app, ui| zero_begin(app, ui)); + zero(&mut app, &ctx, zero_begin); zero(&mut app, &ctx, |app, ui| { zero_update(app, ui, Point::new(50.0, 60.0)); }); - zero(&mut app, &ctx, |app, ui| zero_cancel(app, ui)); + zero(&mut app, &ctx, zero_cancel); assert_eq!(&*app.session.active().unwrap().doc, &*before); assert_eq!(app.session.active().unwrap().history.redo.len(), 1); } @@ -210,7 +210,7 @@ fn a_ruler_drag_trim_view_cancelled_stays_cancelled_until_released() { fn trim_view_toggled_during_a_ruler_origin_drag_cancels_it() { let (mut app, ctx) = (app(), crate::testing::ui_context()); let (before, undo) = (app.session.active().unwrap().doc.clone(), undo_len(&app)); - zero(&mut app, &ctx, |app, ui| zero_begin(app, ui)); + zero(&mut app, &ctx, zero_begin); app.ui.view.trim_view = true; zero(&mut app, &ctx, |app, ui| { zero_update(app, ui, Point::new(50.0, 60.0)); diff --git a/crates/ui-egui/src/canvas/selection.rs b/crates/ui-egui/src/canvas/selection.rs index 89e17b64bc..bc6189861d 100644 --- a/crates/ui-egui/src/canvas/selection.rs +++ b/crates/ui-egui/src/canvas/selection.rs @@ -485,7 +485,8 @@ pub(super) fn show(app: &mut VectorcraftApp, ui: &mut egui::Ui, space: &CanvasSp let marks = anchors(app, st, tool_points); if !marks.paths.is_empty() { let mut paths = marks.paths; - BezierOverlay::new("Anchors", Bind::bound(&mut paths), &marks.selection) + // The marks only show the selection: the tools make the edits. + let _ = BezierOverlay::new("Anchors", Bind::bound(&mut paths), &marks.selection) .tool(BezierTool::Anchors) .handles(marks.handles) .anchors(marks.shown) diff --git a/crates/ui-egui/src/canvas/task_bar.rs b/crates/ui-egui/src/canvas/task_bar.rs index 2f392454fe..c0af7c5eef 100644 --- a/crates/ui-egui/src/canvas/task_bar.rs +++ b/crates/ui-egui/src/canvas/task_bar.rs @@ -470,7 +470,7 @@ pub(super) fn task_bar(app: &mut VectorcraftApp, ui: &mut Ui, space: &CanvasSpac run = Some(("tool.setOption", json!({"tool": "smooth", "values": {"fidelity": x}}))); } } - } else if Button::new(*label).icon(IconSpec::svg(IconId::new(*icon))).variant(Variant::GHOST).show(ui).clicked() { + } else if Button::new(*label).icon(IconSpec::svg(IconId::new(icon))).variant(Variant::GHOST).show(ui).clicked() { run = Some((*cmd, params.clone())); } } diff --git a/crates/ui-egui/src/canvas/tests.rs b/crates/ui-egui/src/canvas/tests.rs index 4d6dcb294f..6448183840 100644 --- a/crates/ui-egui/src/canvas/tests.rs +++ b/crates/ui-egui/src/canvas/tests.rs @@ -471,7 +471,7 @@ fn cmd_with_another_tool_drags_with_the_selection_tool_used_last() { assert_eq!(cmd_drag(&mut app, inside, inside), "selection"); } -//// #6369: only the selection box remains over the temporary halftone, and the original +/// #6369: only the selection box remains over the temporary halftone, and the original /// selection's outlines come back when Preview is turned off or the dialog is cancelled. #[test] fn halftone_preview_hides_dot_outlines_and_keeps_selection_bounds() { @@ -2505,7 +2505,7 @@ fn old_outline_preference_loads_but_does_not_restore_outline() { assert!(!app.outline_view(), "a new document is in Preview"); } -//// The kinds of `marks` other than spaces and line ends, in order. +/// The kinds of `marks` other than spaces and line ends, in order. fn char_marks(marks: &[PlacedMark]) -> Vec { use HiddenMark::{LineBreak, ParagraphEnd, Space, StoryEnd}; marks.iter().map(|m| m.mark).filter(|k| !matches!(k, Space | LineBreak | ParagraphEnd | StoryEnd)).collect() @@ -2639,7 +2639,7 @@ fn view_actual_size_follows_display_print_size() { // Frames as the hosts run them: the zoom stops come from the preferences through the app's frame input. let frame = |app: &mut VectorcraftApp, ctx: &egui::Context, _: Vec| { let raw = egui::RawInput { screen_rect: Some(egui::Rect::from_min_size(Pos2::ZERO, vec2(800.0, 600.0))), ..Default::default() }; - crate::testing::part_frame(app, ctx, raw, |app, ui| show(app, ui)); + crate::testing::part_frame(app, ctx, raw, show); }; frame(&mut app, &ctx, vec![]); // The view's zoom after Actual Size from 250%, and the percent the app's zoom scheme reads it as. diff --git a/crates/ui-egui/src/canvas/tests_ui_scaling.rs b/crates/ui-egui/src/canvas/tests_ui_scaling.rs index b81f4f0b9d..230bf917ff 100644 --- a/crates/ui-egui/src/canvas/tests_ui_scaling.rs +++ b/crates/ui-egui/src/canvas/tests_ui_scaling.rs @@ -23,7 +23,7 @@ fn frame(app: &mut VectorcraftApp, ctx: &egui::Context, (native, ui_zoom): (f32, }; input.viewports.entry(egui::ViewportId::ROOT).or_default().native_pixels_per_point = Some(native); // As the hosts run it: the zoom stops come from the preferences through the app's frame input. - crate::testing::part_frame(app, ctx, input, |app, ui| show(app, ui)); + crate::testing::part_frame(app, ctx, input, show); } /// A 512 × 512 pt document shown at `native` device pixels a point and UI Scaling `ui_zoom`, with a diff --git a/crates/ui-egui/src/canvas/tool_adapter.rs b/crates/ui-egui/src/canvas/tool_adapter.rs index 78211c4279..e5079fe50e 100644 --- a/crates/ui-egui/src/canvas/tool_adapter.rs +++ b/crates/ui-egui/src/canvas/tool_adapter.rs @@ -573,13 +573,13 @@ pub(crate) fn run(app: &mut VectorcraftApp, ui: &mut Ui, pass: &ToolPass) -> Too } let mut view = response.view.or(pass.view).or_else(|| pass.space.map(|s| s.view)); let mut scrolled = false; - if let (Some(v), Some(step)) = (view.as_mut(), response.scroll) { - if Autoscroll::scroll(v, step, super::document_size(app.content_bounds())).is_some() { - ui.ctx().request_repaint(); - // The body takes the reply's view as the one the canvas showed. - response.view = Some(*v); - scrolled = true; - } + if let (Some(v), Some(step)) = (view.as_mut(), response.scroll) + && Autoscroll::scroll(v, step, super::document_size(app.content_bounds())).is_some() + { + ui.ctx().request_repaint(); + // The body takes the reply's view as the one the canvas showed. + response.view = Some(*v); + scrolled = true; } let scaling = app.ui_scaling(); if let (Some(v), Some(view)) = (app.view_mut(), view.as_ref()) { @@ -624,7 +624,8 @@ fn show_overlays(app: &mut VectorcraftApp, ui: &mut Ui, pass: &ToolPass, view_in if app.session.tool_overlays_pending() { ui.ctx().request_repaint(); } - let mut extra = vec![]; + // Gap Options' Preview shows the gaps it finds. + let mut extra = crate::dialogs::live_paint_gaps::overlays(app); if app.ui.view.edges && !revolve { if app.ui.view.text_threads { extra.extend(super::marks::thread_overlays(app, space.view.zoom)); diff --git a/crates/ui-egui/src/chrome.rs b/crates/ui-egui/src/chrome.rs index 60bc0fa9f1..3a97fc1daf 100644 --- a/crates/ui-egui/src/chrome.rs +++ b/crates/ui-egui/src/chrome.rs @@ -205,8 +205,8 @@ pub fn app_bar(ui: &mut Ui, _cx: &mut BodyCx<'_>, app: &mut VectorcraftApp) { let _ = TitleBar::new().show_titled( ui, Title::new(tl!("VectorCraft")), - |ui, _| leading(ui, &mut **app.borrow_mut()), - |ui, _| trailing(ui, &mut **app.borrow_mut()), + |ui, _| leading(ui, &mut app.borrow_mut()), + |ui, _| trailing(ui, &mut app.borrow_mut()), ); } diff --git a/crates/ui-egui/src/chrome/control_bar.rs b/crates/ui-egui/src/chrome/control_bar.rs index affc548233..f2eec9c4de 100644 --- a/crates/ui-egui/src/chrome/control_bar.rs +++ b/crates/ui-egui/src/chrome/control_bar.rs @@ -31,8 +31,6 @@ pub(crate) mod rank { pub const OPACITY: u8 = 4; /// Every other member of the bar. pub const GROUP: u8 = 5; - /// A section's link that stays after its fields leave. - pub const LINK: u8 = 7; } /// An anchor button: icon, tooltip, command and the convert command's `to`. diff --git a/crates/ui-egui/src/chrome/status_bar.rs b/crates/ui-egui/src/chrome/status_bar.rs index e9feeaaac1..e6a18208e0 100644 --- a/crates/ui-egui/src/chrome/status_bar.rs +++ b/crates/ui-egui/src/chrome/status_bar.rs @@ -23,11 +23,8 @@ pub fn status_bar(app: &mut VectorcraftApp, ui: &mut Ui) { let nab = app.session.active().map(|d| d.doc.artboards.len()).unwrap_or(0); let cur = crate::panels::artboards::selected(app, nab); // PLAN: assumed Artboard::rect has `width()` and `height()`. - let document = app - .session - .active() - .and_then(|d| d.doc.artboards.get(cur)) - .map_or(Size::new(1.0, 1.0), |a| Size::new(f64::from(a.rect.width()), f64::from(a.rect.height()))); + let document = + app.session.active().and_then(|d| d.doc.artboards.get(cur)).map_or(Size::new(1.0, 1.0), |a| Size::new(a.rect.width(), a.rect.height())); let boards: Vec> = app .session .active() diff --git a/crates/ui-egui/src/control.rs b/crates/ui-egui/src/control.rs index d7840e9ad1..9c339adc66 100644 --- a/crates/ui-egui/src/control.rs +++ b/crates/ui-egui/src/control.rs @@ -1163,7 +1163,7 @@ const DOCKING_ACTION: &str = "action"; /// succeeded or failed ([`sent_paths`]), except where a `path` or `files` entry of its result names the /// file the request wrote inside the write roots, as the request gave it. A reply with no `/`, `\` or `%` in it is not searched, since every hidden path /// holds a separator, written or escaped. A screenshot's reply is hidden when it is sent -/// ([`hide_in_deferred_reply`]); a `ui.pointer` reply sent after the tool's edit holds no library id +/// ([`Hiding::hide_error`]); a `ui.pointer` reply sent after the tool's edit holds no library id /// or path. pub fn handle(app: &mut VectorcraftApp, ctx: &egui::Context, req: &ControlRequest) -> Reply { let method = req.method.as_str(); @@ -1309,15 +1309,6 @@ fn restore_written_paths(reply: &mut Value, kept: Vec<(String, String)>) { } } -/// Hides in a reply sent after its request was handled (a screenshot's) what [`handle`] hides in a -/// reply, with `sent` as the request's params. Without a read root in force it leaves the reply as -/// it is. -pub(crate) fn hide_in_deferred_reply(app: &VectorcraftApp, reply: &mut Value, sent: &Value) { - if vectorcraft_engine::file_access::current().is_some() { - deferred_hiding(app).hide(reply, sent); - } -} - /// The control methods that send synthetic input. const INPUT_METHODS: [&str; 11] = ["ui.pointer", "ui.click", "ui.drag", "ui.move", "ui.wheel", "ui.key", "ui.text", "ui.type", "ui.release", "ui.ime", "ui.capsLock"]; diff --git a/crates/ui-egui/src/credits.rs b/crates/ui-egui/src/credits.rs index 34a6e5b59c..bc3e4e2fea 100644 --- a/crates/ui-egui/src/credits.rs +++ b/crates/ui-egui/src/credits.rs @@ -92,7 +92,7 @@ pub fn open(app: &mut VectorcraftApp) { let (Some(host), Some(ctx)) = (app.dialogs(), app.ui_ctx.clone()) else { return }; let dialog = HostedAbout::new(about_info(app), credits()); // An open About stays as it is: a second request has nothing to add. - let _ = host.with(|h| h.open_unless_open_in(&ctx, dialog)); + let _ = host.with(|h| h.open_unless_open_in(&ctx, dialog).ok()); } /// Opens the link the user activated in the About dialog, once. Only browsable URLs open. diff --git a/crates/ui-egui/src/custom_toolbars.rs b/crates/ui-egui/src/custom_toolbars.rs index 9f60f0a052..5f9fb10feb 100644 --- a/crates/ui-egui/src/custom_toolbars.rs +++ b/crates/ui-egui/src/custom_toolbars.rs @@ -145,7 +145,7 @@ fn float_new(app: &mut VectorcraftApp, id: u32, from: [f32; 2], first: u32, widt let at = |n: u32| pos2(from[0] + 16.0 * n as f32, from[1] + 24.0 * n as f32); let sits = |p: egui::Pos2| { let others = app.ui.custom_toolbars.iter().filter(|b| b.id != id); - others.filter_map(|b| panel_docking::floating_window(&layout, &panel_id(b.id))).any(|w| w.rect.min.distance(p) < 0.5) + others.filter_map(|b| panel_docking::floating_window(layout, &panel_id(b.id))).any(|w| w.rect.min.distance(p) < 0.5) }; let n = (first..=first + MAX as u32).find(|&n| !sits(at(n))).unwrap_or(first); panel_docking::place_floating(app, &panel_id(id), at(n), width)?; @@ -244,7 +244,7 @@ pub(crate) fn duplicate(app: &mut VectorcraftApp, name: Option<&str>) -> Result< let base = format!("{} Copy", stem.trim_end()); let ui = &app.ui; copy.name = std::iter::once(base.clone()).chain((2..).map(|i| format!("{base} {i}"))).find(|n| find(ui, n).is_none()).unwrap_or_default(); - let source = panel_docking::floating_window(&panel_docking::layout_of(&app.ui), &panel_id(copy.id)).map(|w| w.rect); + let source = panel_docking::floating_window(panel_docking::layout_of(&app.ui), &panel_id(copy.id)).map(|w| w.rect); copy.id = next_id(&app.ui.custom_toolbars); let (id, name) = (copy.id, copy.name.clone()); app.ui.custom_toolbars.push(copy); @@ -471,7 +471,7 @@ pub(crate) fn command(app: &mut VectorcraftApp, id: &str, p: &Value) -> Option) { let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1200.0, height)); let raw = egui::RawInput { time: Some(time), screen_rect: Some(screen), events, ..Default::default() }; - crate::testing::app_frame(app, &ctx, raw); + crate::testing::app_frame(app, ctx, raw); } /// One frame of the whole window, `height` points tall. @@ -874,7 +874,7 @@ mod tests { let copy = find(&app.ui, "Pens Copy").unwrap(); assert!(shown(&app, "Pens Copy") && copy.slots == [["pen"]]); let layout = panel_docking::layout_of(&app.ui); - let window = |name: &str| panel_docking::floating_window(&layout, &panel_id(find(&app.ui, name).unwrap().id)).map(|w| w.rect.min); + let window = |name: &str| panel_docking::floating_window(layout, &panel_id(find(&app.ui, name).unwrap().id)).map(|w| w.rect.min); assert!(window("Pens Copy").is_some(), "a copy floats"); assert_ne!(window("Pens Copy"), window("Pens"), "not on top of the toolbar it copies"); assert_ne!(window("Pens Copy"), window("Pens Copy 2"), "nor on top of an earlier copy"); diff --git a/crates/ui-egui/src/dialogs/action_stop.rs b/crates/ui-egui/src/dialogs/action_stop.rs index fe4f30c639..e9949234ef 100644 --- a/crates/ui-egui/src/dialogs/action_stop.rs +++ b/crates/ui-egui/src/dialogs/action_stop.rs @@ -136,11 +136,6 @@ pub(crate) fn open_message(app: &mut VectorcraftApp, action: &str, message: &str open_or_say(app, StopMessage(prompt.button(PromptChoice::Cancel, label("Stop")))); } -/// Whether a stop's message box is open. -pub(crate) fn message_open(app: &VectorcraftApp) -> bool { - app.dialogs().is_some_and(|dialogs| dialogs.with(|host| host.is_open::())) -} - /// Closes a stop's message box as Stop does; the playback keeps waiting. The closer consumes the /// Cancel it caused, so the pump does not read it as an answer. pub(crate) fn close_message(app: &VectorcraftApp) { diff --git a/crates/ui-egui/src/dialogs/actions.rs b/crates/ui-egui/src/dialogs/actions.rs index 85ea23796f..7d52338be2 100644 --- a/crates/ui-egui/src/dialogs/actions.rs +++ b/crates/ui-egui/src/dialogs/actions.rs @@ -132,13 +132,6 @@ impl Form { self.held.state() } - /// Applies `edit` to the values and to the values Reset returns to, for a change in the app that - /// the values follow (a set they name moved), so Reset does not go back to the old place. - pub(crate) fn follow(&mut self, edit: impl Fn(&mut V)) { - edit(&mut self.values); - edit(&mut self.opening); - } - /// The values as JSON, by their serde names. pub(crate) fn json_fields(&self) -> Option { serde_fields(&self.values) diff --git a/crates/ui-egui/src/dialogs/brush_art_options.rs b/crates/ui-egui/src/dialogs/brush_art_options.rs index 276f68d7a9..13261028e5 100644 --- a/crates/ui-egui/src/dialogs/brush_art_options.rs +++ b/crates/ui-egui/src/dialogs/brush_art_options.rs @@ -31,9 +31,9 @@ use craft::ui::buttons::{Button, IconButton}; use craft::ui::choice::{CellMarks, Segmented, Swatch}; use craft::ui::contract::{Bind, Entry, Outcome as _, Props as _, Show as _, ShowContainer as _, clicked}; use craft::ui::dialog::{FieldRefusal, StackDialog}; -use craft::ui::display::{Picture, PictureSize, Text}; +use craft::ui::display::{Picture, Text}; use craft::ui::layout_components::{Row, Stack}; -use craft::ui::list::{ThumbAspect, ThumbSize}; +use craft::ui::list::ThumbAspect; use craft::ui::patterns::form_dialogs::{DialogFields, FieldValue, HostedParamDialog, Param, ParamKind}; use craft::ui::pickers::Select; use craft::ui::popover::Popover; @@ -48,7 +48,7 @@ use vectorcraft_brush::{ArtBrush, ArtScale, Brush, BrushKind, Colorization, Corn use vectorcraft_color::{Color, Paint}; use vectorcraft_doc::{Appearance, Document, Node, NodeId, NodeKind, PatternDef}; -use super::brush_options::{clamped, mode_key, stroke_preview}; +use super::brush_options::{clamped, mode_key}; use crate::VectorcraftApp; /// Scatter values: (field, suffix), in [`Scatter::RANGES`] order. @@ -155,11 +155,6 @@ pub(super) fn tile_choice(f: &DialogFields, key: &str) -> String { } } -/// Sets tile `key` to `choice`: the pick that marks the tile as set. -pub(super) fn choose_corner(f: &mut DialogFields, key: &str, choice: &str) { - f.set(key, choice); -} - /// The most key colours offered. const MAX_COLORS: usize = 16; @@ -428,18 +423,6 @@ pub(super) fn rows(ty: &str, object: bool) -> Vec { rows } -/// The row of the stroke the brush would paint, on the document `doc` the dialog opened over. -pub(super) fn preview_row(doc: Option>, ty: &str) -> Param { - let ty = ty.to_string(); - Param::custom("__stroke", tl!("Preview"), move |ui, f, _| { - let def = edited_def(f); - Picture::painter(tl!("Stroke preview"), ThumbAspect::new(7, 1), |cx, rect| stroke_preview(cx, rect, doc.as_deref(), &ty, def.clone())) - .extent(PictureSize::Thumb(ThumbSize::Medium)) - .show(ui) - }) - .full_width() -} - /// A whole-number field bound to `f[key]`, kept within `range`, named `label`. fn number_cell(ui: &mut Ui, f: &mut DialogFields, key: &str, label: &'static str, range: (f64, f64), unit: UnitKind, enabled: bool) -> Response { let typed = NumberField::new(label, Bind::given(Some(clamped(f, key, range)))) diff --git a/crates/ui-egui/src/dialogs/brush_options/tests.rs b/crates/ui-egui/src/dialogs/brush_options/tests.rs index 6a362cce6f..0f2db21d46 100644 --- a/crates/ui-egui/src/dialogs/brush_options/tests.rs +++ b/crates/ui-egui/src/dialogs/brush_options/tests.rs @@ -428,9 +428,9 @@ fn pattern_options_tiles_open_empty_and_show_the_brushs_own_tile() { assert_eq!(brush_art_options::tile_choice(&d, "outerCornerTile"), "original"); // Original stays in a corner's menu after another choice, and goes back to the corner art. let mut d = d; - brush_art_options::choose_corner(&mut d, "outerCornerTile", "autoBetween"); + d.set("outerCornerTile", "autoBetween"); assert!(brush_art_options::original_available(&d, "outer_corner")); - brush_art_options::choose_corner(&mut d, "outerCornerTile", "original"); + d.set("outerCornerTile", "original"); assert_eq!(brush_art_options::tile_choice(&d, "outerCornerTile"), "original"); } @@ -470,9 +470,9 @@ fn pattern_tile_menus_use_document_patterns_and_side_none_keeps_dialog_open() { } // Original stays available after a swatch is chosen, and restores the tile the dialog opened with. let mut d = d; - brush_art_options::choose_corner(&mut d, "sideTile", "Wide"); + d.set("sideTile", "Wide"); assert!(brush_art_options::original_available(&d, "side")); - brush_art_options::choose_corner(&mut d, "sideTile", "original"); + d.set("sideTile", "original"); let restored = brush_art_options::edited_def(&d); assert_eq!((&restored["side"], &restored["side_frame"]), (&before["side"], &before["side_frame"])); set(&mut app, json!({"sideTile": "original"})); @@ -491,7 +491,7 @@ fn pattern_tile_menus_use_document_patterns_and_side_none_keeps_dialog_open() { let mut d = fields_of(&app); assert_eq!(brush_art_options::tile_choice(&d, "sideTile"), "pattern:Wide"); assert!(brush_art_options::original_available(&d, "side")); - brush_art_options::choose_corner(&mut d, "sideTile", "original"); + d.set("sideTile", "original"); assert_eq!(brush_art_options::edited_def(&d)["side"], opened["side"]); cancel(&mut app); app.session diff --git a/crates/ui-egui/src/dialogs/char_style_options.rs b/crates/ui-egui/src/dialogs/char_style_options.rs index 5d8823945d..3ad521ad04 100644 --- a/crates/ui-egui/src/dialogs/char_style_options.rs +++ b/crates/ui-egui/src/dialogs/char_style_options.rs @@ -249,7 +249,7 @@ fn tri_box(ui: &mut egui::Ui, current: Option, label: Option