mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-27 21:28:40 +00:00
Merge branch 'area/app3' into area/app4
area/app3's formatting, clippy fixes, restored behaviours, the install_fonts test and the wasm-only web-time dependency. save.rs keeps area/app3's removal of save_reporting and cancel, which nothing calls, with this branch's native-only save flow on top. A recovered copy's age is read with the recovery store's clock, which stamped it (the page's on the web, where the document clock reads none). The lock gains web-time under the UI crate.
This commit is contained in:
Generated
+1
@@ -8712,6 +8712,7 @@ dependencies = [
|
||||
"vectorcraft-three-d",
|
||||
"vectorcraft-tools",
|
||||
"wat",
|
||||
"web-time",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
|
||||
@@ -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<Event>,
|
||||
/// 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<RefCell<Pointers>>;
|
||||
|
||||
|
||||
@@ -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"))]
|
||||
{
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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).
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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<u8> {
|
||||
raw_pdf_bytes(objects.iter().map(|o| o.clone().into_bytes()))
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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 {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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<Node> {
|
||||
]
|
||||
}
|
||||
|
||||
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<Param>) -> ParamDialog<'a> {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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<fn(&mut HostedParamDialog, Result<&Value, &str>)>,
|
||||
/// What OK does.
|
||||
pub confirm: Confirm,
|
||||
pub found: Option<Found>,
|
||||
}
|
||||
|
||||
/// 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<Value, String> {
|
||||
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<Resul
|
||||
Some(open(app))
|
||||
}
|
||||
|
||||
/// Once per frame: runs the preview of the open `Commit` dialog, commits or cancels it when the dialog has
|
||||
/// Once per frame: runs the preview of the open add-on dialog, commits or cancels it when the dialog has
|
||||
/// answered, then lets the dialogs that take their own answer do the same. Each takes its dialog by id, never
|
||||
/// by type: two hosted parameter dialogs would take each other's answers.
|
||||
pub(crate) fn pump(app: &mut VectorcraftApp, ctx: &Context) {
|
||||
|
||||
@@ -10,7 +10,7 @@ use craft::host::PickKind;
|
||||
|
||||
/// Whether the newest pick asked for is a folder.
|
||||
fn asked_for_folder(picker: &crate::tests::picks::Picker) -> 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`.
|
||||
|
||||
@@ -106,7 +106,7 @@ impl FoldPreviewWords {
|
||||
"bottom" => &self.bottom,
|
||||
_ => &self.three_quarter,
|
||||
};
|
||||
Label::from(word.clone())
|
||||
word.clone()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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<f64> = 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 {
|
||||
|
||||
@@ -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<f64> = 0.01..=1e6;
|
||||
const GAPS: std::ops::RangeInclusive<f64> = 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 {
|
||||
|
||||
@@ -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<f64> = 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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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<Finished>) {
|
||||
if finished.is_empty() {
|
||||
|
||||
@@ -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<vectorcraft_doc::LiveShape>), Option<f64>)>,
|
||||
pub shape_angle: Option<ShapeAngleCache>,
|
||||
/// The Image Trace presets, for the session's preset revision.
|
||||
pub(crate) trace_presets: Option<(u64, Arc<crate::panels::image_trace::PresetList>)>,
|
||||
/// 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<str>)>,
|
||||
/// The Export for Screens dialog's artboard thumbnails, for (document uid, revision).
|
||||
pub artboard_thumbs: Option<((u64, u64), Vec<Option<egui::TextureHandle>>)>,
|
||||
pub artboard_thumbs: Option<ArtboardThumbsCache>,
|
||||
/// 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<SystemTime>)>,
|
||||
pub recently_added: Option<RecentlyAddedCache>,
|
||||
/// 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<NodeId>), Vec<u32>)>,
|
||||
pub glyph_form_faces: Option<GlyphFormFacesCache>,
|
||||
/// 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<CharacterQuadsCache>,
|
||||
/// 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<TabsGuideAxisCache>,
|
||||
/// The Appearance panel's summary of the selection, which holds the document, revision and
|
||||
/// subjects it was made for.
|
||||
pub(crate) appearance_summary: Option<Arc<crate::panels::appearance::Summary>>,
|
||||
@@ -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<Vec<vectorcraft_pdf::TilingPage>>);
|
||||
|
||||
/// [`CanvasCache::shape_angle`]: the selected live shape's angle, for (document uid, revision, kind
|
||||
/// of shape).
|
||||
pub type ShapeAngleCache = ((u64, u64, std::mem::Discriminant<vectorcraft_doc::LiveShape>), Option<f64>);
|
||||
|
||||
/// [`CanvasCache::artboard_thumbs`]: the artboard thumbnails of (document uid, revision).
|
||||
pub type ArtboardThumbsCache = ((u64, u64), Vec<Option<egui::TextureHandle>>);
|
||||
|
||||
/// [`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<SystemTime>);
|
||||
|
||||
/// [`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<NodeId>), Vec<u32>);
|
||||
|
||||
/// [`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,
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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)))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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).
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -55,9 +55,12 @@ fn frame_in(app: &mut VectorcraftApp, ctx: &egui::Context, events: Vec<egui::Eve
|
||||
shapes
|
||||
}
|
||||
|
||||
/// A texture's picture: its pixels and size.
|
||||
type Picture = (Vec<Color32>, [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<std::collections::HashMap<egui::TextureId, (Vec<Color32>, [usize; 2])>> = Default::default();
|
||||
static UPLOADED: std::cell::RefCell<std::collections::HashMap<egui::TextureId, Picture>> = Default::default();
|
||||
}
|
||||
|
||||
/// Notes the last picture each texture got in `delta` in [`UPLOADED`], and handles the uploads.
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<HiddenMark> {
|
||||
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<egui::Event>| {
|
||||
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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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()),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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`.
|
||||
|
||||
@@ -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<Entry<usize>> = app
|
||||
.session
|
||||
.active()
|
||||
|
||||
@@ -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"];
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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<R
|
||||
.iter()
|
||||
.map(|b| {
|
||||
let panel = panel_id(b.id);
|
||||
let place = panel_docking::column_of(&layout, &panel);
|
||||
let place = panel_docking::column_of(layout, &panel);
|
||||
let docked = place.as_ref().and_then(|(at, _)| at.as_ref());
|
||||
let side = if matches!(docked, Some((DockEdge::End, _))) { "right" } else { "left" };
|
||||
let double = place.as_ref().is_some_and(|(_, column)| column.steps == Some(2));
|
||||
@@ -583,7 +583,7 @@ mod tests {
|
||||
fn window_frame_with(app: &mut VectorcraftApp, ctx: &egui::Context, time: f64, height: f32, events: Vec<egui::Event>) {
|
||||
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");
|
||||
|
||||
@@ -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::<StopMessage>()))
|
||||
}
|
||||
|
||||
/// 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) {
|
||||
|
||||
@@ -132,13 +132,6 @@ impl<V: Fields> Form<V> {
|
||||
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<Value> {
|
||||
serde_fields(&self.values)
|
||||
|
||||
@@ -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<Param> {
|
||||
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<Arc<Document>>, 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))))
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -249,7 +249,7 @@ fn tri_box(ui: &mut egui::Ui, current: Option<bool>, label: Option<Label>, salt:
|
||||
check = check.label(label);
|
||||
}
|
||||
let out = check.show(ui);
|
||||
let next = out.value().is_some().then(|| match current {
|
||||
let next = out.value().is_some().then_some(match current {
|
||||
None => Some(true),
|
||||
Some(true) => Some(false),
|
||||
Some(false) => None,
|
||||
@@ -1112,11 +1112,6 @@ impl CharStyleOptions {
|
||||
edited_attrs(self.inner.fields(), &self.opening)
|
||||
}
|
||||
|
||||
/// What the dialog opened with.
|
||||
pub(crate) fn opening(&self) -> &Opening {
|
||||
&self.opening
|
||||
}
|
||||
|
||||
fn command(&self, attrs: Map<String, Value>) -> Value {
|
||||
let to = self.inner.fields().text("name").unwrap_or_default();
|
||||
json!({"name": self.opening.style, "to": to, "attrs": attrs})
|
||||
|
||||
@@ -201,7 +201,7 @@ fn track(key: &str, x: f32) -> Srgba {
|
||||
fn channels(ui: &mut egui::Ui, fields: &mut DialogFields, _cx: &mut CustomContext) -> egui::Response {
|
||||
ui.vertical(|ui| {
|
||||
for (key, label) in mode(fields).channels {
|
||||
percent_row(ui, fields, key, *label, |x| track(key, x));
|
||||
percent_row(ui, fields, key, label, |x| track(key, x));
|
||||
}
|
||||
})
|
||||
.response
|
||||
|
||||
@@ -50,7 +50,8 @@ pub fn open(app: &mut VectorcraftApp) {
|
||||
})
|
||||
.collect();
|
||||
ui.scope(|ui| {
|
||||
SwatchTable::new(tl!("Variations").to_owned(), &chips).show_all(ui);
|
||||
// The chips hold no selection: a click reports one the row ignores.
|
||||
let _ = SwatchTable::new(tl!("Variations").to_owned(), &chips).show_all(ui);
|
||||
})
|
||||
.response
|
||||
});
|
||||
|
||||
@@ -359,7 +359,7 @@ fn mark_line(image: &mut vectorcraft_render::Rendered, y: f32, thickness: usize,
|
||||
for row in first..first.saturating_add(thickness).min(height) {
|
||||
let start = row.saturating_mul(width).saturating_mul(4);
|
||||
if let Some(line) = image.pixels.get_mut(start..start.saturating_add(width.saturating_mul(4))) {
|
||||
for pixel in line.chunks_exact_mut(4) {
|
||||
for pixel in line.as_chunks_mut::<4>().0 {
|
||||
pixel.copy_from_slice(&color.to_array());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,6 +87,9 @@ const MODES: [(&str, &str); 3] = [("linear", "Linear"), ("angular", "Angular"),
|
||||
/// Where the floating strip sits from the canvas corner.
|
||||
const STRIP_OFFSET: egui::Vec2 = egui::vec2(24.0, 24.0);
|
||||
|
||||
/// The option a number field edits.
|
||||
type NumSlot = fn(&mut DimensionOptions) -> &mut f64;
|
||||
|
||||
/// A number field of the options: its labels, the number it edits and the range and unit it shows.
|
||||
#[derive(Clone, Copy)]
|
||||
struct Num {
|
||||
@@ -94,7 +97,7 @@ struct Num {
|
||||
label: &'static str,
|
||||
/// The field's accessible name, which tells apart the fields that share a label.
|
||||
name: &'static str,
|
||||
slot: fn(&mut DimensionOptions) -> &mut f64,
|
||||
slot: NumSlot,
|
||||
min: f64,
|
||||
max: f64,
|
||||
unit: &'static str,
|
||||
@@ -135,7 +138,7 @@ struct Edited {
|
||||
/// A control other than a number field changed a value.
|
||||
set: bool,
|
||||
/// The number fields' edits of the pass, with the number each one edits.
|
||||
numbers: Vec<(fn(&mut DimensionOptions) -> &mut f64, EditResponse<Option<f64>>)>,
|
||||
numbers: Vec<(NumSlot, EditResponse<Option<f64>>)>,
|
||||
/// A swatch asked for a colour picker.
|
||||
pick: Option<ColorRequest>,
|
||||
}
|
||||
|
||||
@@ -486,8 +486,8 @@ fn typography() -> Vec<PropertyRow> {
|
||||
|choices: &[[char; 2]]| -> Vec<(String, String)> { choices.iter().map(|p| p.iter().collect::<String>()).map(|s| (s.clone(), s)).collect() };
|
||||
vec![
|
||||
PropertyRow::field(Param::custom("language", tl!("Language:"), language_row).companions(["quotes.double", "quotes.single"])),
|
||||
choice("quotes.double", tl!("Double Quotes:"), quotes(&Quotes::DOUBLE_CHOICES)),
|
||||
choice("quotes.single", tl!("Single Quotes:"), quotes(&Quotes::SINGLE_CHOICES)),
|
||||
choice("quotes.double", tl!("Double Quotes:"), quotes(Quotes::DOUBLE_CHOICES)),
|
||||
choice("quotes.single", tl!("Single Quotes:"), quotes(Quotes::SINGLE_CHOICES)),
|
||||
check("typographersQuotes", tl!("Use Typographer's Quotes")),
|
||||
section(tl!("Options")),
|
||||
percent("superscript.size", tl!("Superscript Size:"), 0.0),
|
||||
|
||||
@@ -38,8 +38,6 @@ pub(crate) struct EffectDialogs {
|
||||
pub effect: Option<Open>,
|
||||
/// The Halftone dialog.
|
||||
pub halftone: Option<super::halftone::Open>,
|
||||
/// The Document Raster Effects Settings and Rasterize dialogs.
|
||||
pub raster: Option<super::raster_effects::Open>,
|
||||
/// The envelope dialogs.
|
||||
pub envelope: Option<super::envelope::Open>,
|
||||
/// The Effect Gallery.
|
||||
@@ -498,7 +496,7 @@ pub(super) fn texture_fields(bytes: &[u8]) -> Result<[(&'static str, FieldValue)
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::super::effect_params::{DROP_SHADOW, GLASS, RADIAL_BLUR, ROUGH_PASTELS, TEXTURIZER, choices, own_choices, shown_choices};
|
||||
use super::super::effect_params::{DROP_SHADOW, GLASS, RADIAL_BLUR, ROUGH_PASTELS, TEXTURIZER, choices, own_choices};
|
||||
use super::*;
|
||||
|
||||
fn app() -> VectorcraftApp {
|
||||
@@ -627,10 +625,8 @@ mod tests {
|
||||
assert_eq!(d.fields().text("texture"), Some("loaded"), "{effect}");
|
||||
d.fields().text(vectorcraft_effects::pixel::TEXTURE_IMAGE).unwrap().to_string()
|
||||
});
|
||||
let mut values = Map::new();
|
||||
values.insert(vectorcraft_effects::pixel::TEXTURE_IMAGE.into(), json!(stored));
|
||||
let shown = shown_choices(effect, "texture", &values, false).unwrap();
|
||||
assert_eq!(shown.last().map(|(_, v)| v.as_str()), Some("loaded"), "{effect}");
|
||||
// The Texture menu lists Loaded Texture while the stored image reads as a texture.
|
||||
assert!(vectorcraft_effects::pixel::texture(&stored).is_some(), "{effect}");
|
||||
ok(&mut app);
|
||||
let p = params(&app, node);
|
||||
assert_eq!((&p["texture"], &p["textureImage"]), (&json!("loaded"), &json!(stored)), "{effect}");
|
||||
|
||||
@@ -195,11 +195,6 @@ pub(crate) const PAINT_DAUB_BRUSH_TYPE_LABELS: [&str; 6] = ["Simple", "Light Rou
|
||||
/// What Drop Shadow's shadow takes its color from (`shade`), as (label, value).
|
||||
pub(crate) const SHADES: form::Choices = &[("Color", "color"), ("Darkness", "darkness")];
|
||||
|
||||
/// Does effect `id` have Load Texture… in its dialog (Glass, Texturizer, Rough Pastels)?
|
||||
pub(super) fn loads_texture(id: &str) -> bool {
|
||||
matches!(id, GLASS | TEXTURIZER | ROUGH_PASTELS)
|
||||
}
|
||||
|
||||
/// Glass's Texture menu, ending with Loaded Texture once a texture is `loaded`.
|
||||
pub(super) fn glass_textures(loaded: bool) -> form::Choices {
|
||||
use vectorcraft_effects::pixel::{GLASS_TEXTURES, GLASS_TEXTURES_LOADED};
|
||||
@@ -287,32 +282,6 @@ pub(super) fn own_choices(effect: &str, key: &str, cmyk: bool) -> Option<Vec<(&'
|
||||
})
|
||||
}
|
||||
|
||||
/// The values that parameter `key` of applied effect `effect` picks from, as its dialog lists
|
||||
/// them, as (label, value): our own effects' labels in the UI language, a plug-in's choices as the
|
||||
/// plug-in names them. The Texture menu of Glass, Texturizer and Rough Pastels ends with Loaded
|
||||
/// Texture when the effect's values `params` hold a loaded texture, and the lists of
|
||||
/// [`own_choices`] are translated as their dialogs translate them (`cmyk`: the document is in
|
||||
/// CMYK). `None` for a parameter that is not one of these lists.
|
||||
pub(crate) fn shown_choices(effect: &str, key: &str, params: &Map<String, Value>, cmyk: bool) -> Option<Vec<(String, String)>> {
|
||||
if let Some(plugin) = vectorcraft_plugins::effect::installed(effect) {
|
||||
return plugin.manifest().param(key).and_then(|p| match &p.spec {
|
||||
vectorcraft_plugins::ParamSpec::Choice { options, .. } => Some(options.iter().map(|o| (o.clone(), o.clone())).collect()),
|
||||
_ => None,
|
||||
});
|
||||
}
|
||||
if let Some(own) = own_choices(effect, key, cmyk) {
|
||||
return Some(own.into_iter().map(|(label, value)| (tl!(label).to_string(), value.to_string())).collect());
|
||||
}
|
||||
let options = if loads_texture(effect) && key == "texture" {
|
||||
use vectorcraft_effects::pixel::{TEXTURE_IMAGE, texture};
|
||||
let loaded = params.get(TEXTURE_IMAGE).and_then(Value::as_str).and_then(texture).is_some();
|
||||
if effect == GLASS { glass_textures(loaded) } else { texturizer_textures(loaded) }
|
||||
} else {
|
||||
choices(effect, key)?
|
||||
};
|
||||
Some(options.iter().map(|(label, value)| (form::choice_label(label).to_string(), value.to_string())).collect())
|
||||
}
|
||||
|
||||
/// Where parameter `key` comes in the effect's parameter documentation `doc` (`{radius: …,
|
||||
/// threshold: …}`), which lists them in its dialog's order; the end when it isn't there.
|
||||
pub(super) fn doc_rank(doc: &str, key: &str) -> usize {
|
||||
|
||||
@@ -189,7 +189,7 @@ pub(super) fn textured(cx: &EffectCx, fields: &DialogFields) -> Vec<Param> {
|
||||
let exts: Vec<String> = vectorcraft_engine::cmd::fileio::FORMATS
|
||||
.iter()
|
||||
.filter(|f| f.read && f.raster)
|
||||
.flat_map(|f| vectorcraft_engine::cmd::fileio::read_extensions(f).into_iter().map(|e| e.to_string()))
|
||||
.flat_map(|f| vectorcraft_engine::cmd::fileio::read_extensions(f).iter().map(|e| e.to_string()))
|
||||
.collect();
|
||||
let exts: Vec<&str> = exts.iter().map(String::as_str).collect();
|
||||
let picker = Param::custom("texture", lbl!("Texture:"), move |ui, fields, cx| {
|
||||
|
||||
@@ -426,7 +426,7 @@ impl StackDialog for FileInfoDialog {
|
||||
true
|
||||
});
|
||||
match answered {
|
||||
Some(true) => ask_import(templates, import, *import_mode),
|
||||
Some(true) => ask_import(templates, import, import_mode),
|
||||
Some(false) => *import = None,
|
||||
None => {}
|
||||
}
|
||||
|
||||
@@ -118,9 +118,12 @@ fn name_rows(names: &&[(String, String)], _: &Env) -> Vec<PresetRow<String>> {
|
||||
names.iter().map(|(name, shown)| PresetRow::item(name.clone(), shown.clone(), 0)).collect()
|
||||
}
|
||||
|
||||
/// What a presets row takes: the rows, the values each applies, and the built-in names.
|
||||
pub(crate) type PresetRows = (Vec<PresetRow<String>>, Vec<(String, DialogFields)>, Vec<String>);
|
||||
|
||||
/// The presets the session lists, as what a presets row takes: the rows (the built-in ones
|
||||
/// translated), the values each applies, and the built-in names.
|
||||
pub(crate) fn preset_rows(app: &VectorcraftApp) -> (Vec<PresetRow<String>>, Vec<(String, DialogFields)>, Vec<String>) {
|
||||
pub(crate) fn preset_rows(app: &VectorcraftApp) -> PresetRows {
|
||||
let presets = app.session.flattener_presets();
|
||||
let rows = preset_names(app).into_iter().map(|(name, shown)| PresetRow::item(name, shown, 0)).collect();
|
||||
let values = presets.iter().map(|p| (p.name.clone(), option_fields(&p.options))).collect();
|
||||
|
||||
@@ -390,12 +390,6 @@ fn graph_grid(app: &mut VectorcraftApp, graph: Option<u64>) -> Result<Grid, Stri
|
||||
Ok(grid_from_data(&v))
|
||||
}
|
||||
|
||||
/// Revert: the graph's data again.
|
||||
fn revert(app: &mut VectorcraftApp, sheet: &mut Sheet, graph: Option<u64>) -> Result<(), String> {
|
||||
replace_grid(sheet, graph_grid(app, graph)?);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Whether Import Data can ask for a file here: the host has a picker and the app can read files.
|
||||
fn can_import(app: &VectorcraftApp) -> bool {
|
||||
file_asks::can(app, craft::host::PickKind::Open) && app.services.read.is_some()
|
||||
|
||||
@@ -34,15 +34,18 @@ pub(crate) struct HeldOptions {
|
||||
/// The dialog this one opens over; it closes with its parent.
|
||||
pub parent: Option<DialogId>,
|
||||
/// Runs when the dialog is cancelled (a live preview's rollback).
|
||||
pub cancel: Option<Box<dyn FnOnce(&mut VectorcraftApp)>>,
|
||||
pub cancel: Option<Cancel>,
|
||||
}
|
||||
|
||||
/// Rolls back what a held dialog did, when it is cancelled.
|
||||
pub(crate) type Cancel = Box<dyn FnOnce(&mut VectorcraftApp)>;
|
||||
|
||||
/// Runs one held dialog's pass; `Some(cancelled)` once the dialog is gone.
|
||||
type Drain = Box<dyn FnMut(&mut VectorcraftApp) -> Option<bool>>;
|
||||
|
||||
struct Record {
|
||||
drain: Drain,
|
||||
cancel: Option<Box<dyn FnOnce(&mut VectorcraftApp)>>,
|
||||
cancel: Option<Cancel>,
|
||||
}
|
||||
|
||||
/// The held dialogs of the app: one record each, served by [`pump`].
|
||||
|
||||
@@ -258,7 +258,7 @@ mod tests {
|
||||
|
||||
fn set_field(panel: &Panel, field: &str, value: &str) {
|
||||
let dialogs = panel.app().dialogs().unwrap();
|
||||
dialogs.with(|host| host.set_json_field(&panel.ctx(), dialog_id(KEY), field, json!(value))).unwrap();
|
||||
dialogs.with(|host| host.set_json_field(panel.ctx(), dialog_id(KEY), field, json!(value))).unwrap();
|
||||
}
|
||||
|
||||
fn json_selected(panel: &Panel) -> Value {
|
||||
|
||||
@@ -131,7 +131,7 @@ impl LayerOptionsValue {
|
||||
|
||||
/// Whether `field` was set in the dialog.
|
||||
fn is_set(&self, field: &str) -> bool {
|
||||
self.set.iter().any(|set| *set == field)
|
||||
self.set.contains(&field)
|
||||
}
|
||||
|
||||
/// The check box `key` names.
|
||||
|
||||
@@ -56,7 +56,7 @@ fn check(key: &str, label: &'static str, default: bool) -> Param {
|
||||
|
||||
/// The rows of the dialog of tool `k`, in the order the tool's options are laid out.
|
||||
fn params(k: LiquifyKind, lengths: LengthUnits) -> Vec<Param> {
|
||||
let length = |key: &str, label: &'static str| Param::number(key, label, 50.0, 1.0, 0).length(lengths.clone());
|
||||
let length = |key: &str, label: &'static str| Param::number(key, label, 50.0, 1.0, 0).length(lengths);
|
||||
let mut rows = vec![
|
||||
Param::section(tl!("Global Brush Dimensions")),
|
||||
length("width", tl!("Width:")),
|
||||
|
||||
@@ -344,6 +344,35 @@ mod tests {
|
||||
assert_eq!(state(&app).0, before.0 + 1);
|
||||
}
|
||||
|
||||
/// The canvas draws the gaps Gap Options previews, in its preview color, and stops when Preview goes off.
|
||||
#[test]
|
||||
fn the_canvas_draws_the_previewed_gaps() {
|
||||
let mut app = app();
|
||||
gapped_group(&mut app);
|
||||
let green = egui::Color32::from_rgb(0x4f, 0xff, 0x4f);
|
||||
let drawn = |app: &mut VectorcraftApp| {
|
||||
let ctx = app.ui_ctx.clone().unwrap();
|
||||
let raw =
|
||||
egui::RawInput { screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(800.0, 600.0))), ..Default::default() };
|
||||
let mut out = ctx.run_ui(raw, |ui| crate::canvas::show(app, ui));
|
||||
out.textures_delta.clear();
|
||||
ctx.tessellate(out.shapes, out.pixels_per_point).into_iter().any(|p| match p.primitive {
|
||||
egui::epaint::Primitive::Mesh(mesh) => mesh.vertices.iter().any(|v| v.color == green),
|
||||
egui::epaint::Primitive::Callback(_) => false,
|
||||
})
|
||||
};
|
||||
app.run("ui.livePaintGapOptions", json!({})).unwrap();
|
||||
set(&app, "detect", json!(true)).unwrap();
|
||||
set(&app, "color", json!("Green")).unwrap();
|
||||
set(&app, "preview", json!(true)).unwrap();
|
||||
pump_all(&mut app);
|
||||
assert!(!overlays(&app).is_empty());
|
||||
assert!(drawn(&mut app), "the previewed gap draws on the canvas");
|
||||
set(&app, "preview", json!(false)).unwrap();
|
||||
pump_all(&mut app);
|
||||
assert!(!drawn(&mut app), "no preview, no gap");
|
||||
}
|
||||
|
||||
/// With Preview on, a Gap Preview Color with an alpha part is not previewed: the group keeps
|
||||
/// its own color, the gaps draw in black, OK refuses the color and Cancel rolls the preview back.
|
||||
#[test]
|
||||
|
||||
@@ -284,10 +284,11 @@ impl StackDialog for MissingFontsDialog {
|
||||
*search_folder = next.clone();
|
||||
act = Some(Act::Search);
|
||||
}
|
||||
if *can_pick && clicked(&Button::new(tl!("Find in Folder…")).id_salt("pick").enabled(!searching).show(ui)) {
|
||||
if let Some(host) = form.env.host().cloned() {
|
||||
*ticket = Some(host.files().pick(PickRequest::folder("fonts")));
|
||||
}
|
||||
if *can_pick
|
||||
&& clicked(&Button::new(tl!("Find in Folder…")).id_salt("pick").enabled(!searching).show(ui))
|
||||
&& let Some(host) = form.env.host().cloned()
|
||||
{
|
||||
*ticket = Some(host.files().pick(PickRequest::folder("fonts")));
|
||||
}
|
||||
if searching && clicked(&Button::new(tl!("Stop")).id_salt("stop").show(ui)) {
|
||||
act = Some(Act::Stop);
|
||||
@@ -381,7 +382,7 @@ pub(crate) fn open_next(app: &mut VectorcraftApp) {
|
||||
let Some(dialog) = dialog_for(app, uid) else { continue };
|
||||
let Some(dialogs) = app.dialogs() else { return };
|
||||
// One dialog at a time: a document that asks while another's is open waits its turn.
|
||||
if dialogs.with(|h| h.open_unless_open(dialog)).is_err() {
|
||||
if dialogs.with(|h| h.open_unless_open(dialog).is_err()) {
|
||||
queue_first(app, uid);
|
||||
}
|
||||
break;
|
||||
@@ -487,7 +488,7 @@ fn open_searching(app: &mut VectorcraftApp, uid: u64, folder: &str) -> Result<Va
|
||||
fn show_for(app: &mut VectorcraftApp, uid: u64, dialog: MissingFontsDialog) {
|
||||
app.ui.pending_fonts.retain(|u| *u != uid);
|
||||
let Some(dialogs) = app.dialogs() else { return };
|
||||
if dialogs.with(|h| h.open_unless_open(dialog)).is_err() {
|
||||
if dialogs.with(|h| h.open_unless_open(dialog).is_err()) {
|
||||
queue_first(app, uid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -215,7 +215,8 @@ fn find_fonts_opens_find_font_on_the_missing_font() {
|
||||
assert!(answer_ok(&mut app));
|
||||
assert!(is_open::<crate::find_font::FindFontDialog>(&app), "Find Font");
|
||||
let fonts = app.session.execute("text.fonts", &json!({})).unwrap();
|
||||
let selected = host(&app, |h| h.get::<crate::find_font::FindFontDialog>().map(|d| d.selected())).unwrap();
|
||||
let selected =
|
||||
host(&app, |h| h.get::<crate::find_font::FindFontDialog>().and_then(|d| d.json_fields())).unwrap()["selected"].as_u64().unwrap() as usize;
|
||||
assert!(selected > 0 && fonts[selected]["family"] == "Zz Missing Family", "{selected} in {fonts}");
|
||||
// Find Font closed: no Missing Fonts dialog follows.
|
||||
let ctx = app.ui_ctx.clone().unwrap();
|
||||
@@ -244,7 +245,8 @@ fn find_fonts_works_on_the_dialog_s_own_document() {
|
||||
answer_ok(&mut app);
|
||||
assert_eq!(app.session.active().unwrap().path.as_deref(), Some(&*a.to_string_lossy()));
|
||||
let fonts = app.session.execute("text.fonts", &json!({})).unwrap();
|
||||
let selected = host(&app, |h| h.get::<crate::find_font::FindFontDialog>().map(|d| d.selected())).unwrap();
|
||||
let selected =
|
||||
host(&app, |h| h.get::<crate::find_font::FindFontDialog>().and_then(|d| d.json_fields())).unwrap()["selected"].as_u64().unwrap() as usize;
|
||||
assert_eq!(fonts[selected]["family"], "Alpha Missing Family", "{fonts}");
|
||||
}
|
||||
|
||||
|
||||
@@ -309,7 +309,7 @@ impl DocumentSettings for VcNewDocument {
|
||||
}
|
||||
});
|
||||
});
|
||||
if let Some(o) = picked.clone()
|
||||
if let Some(o) = picked
|
||||
&& o != current
|
||||
{
|
||||
std::mem::swap(&mut s.width, &mut s.height);
|
||||
|
||||
@@ -30,6 +30,9 @@ use crate::canvas::rulers::unit_kind;
|
||||
/// Pixels per inch that sizes a length shown in pixels: a pixel is a point.
|
||||
const PIXELS_PER_INCH: f64 = 72.0;
|
||||
|
||||
/// What OK does with a dialog's checked values and its extra value.
|
||||
type Run = fn(&mut VectorcraftApp, &Map<String, Value>, &Value) -> Result<Value, String>;
|
||||
|
||||
/// What one of the dialogs the form serves is.
|
||||
pub(super) struct OptionSpec {
|
||||
/// The dialog kind: the key automation and the host know the dialog by.
|
||||
@@ -47,7 +50,7 @@ pub(super) struct OptionSpec {
|
||||
/// Whether the row of `key` takes no input with these values.
|
||||
pub inactive: fn(&Map<String, Value>, &str) -> bool,
|
||||
/// What OK does with the checked values and [`OptionForm::extra`].
|
||||
pub run: fn(&mut VectorcraftApp, &Map<String, Value>, &Value) -> Result<Value, String>,
|
||||
pub run: Run,
|
||||
/// What closing the dialog without OK releases (a running preview).
|
||||
pub cancelled: Option<fn(&mut VectorcraftApp)>,
|
||||
}
|
||||
|
||||
@@ -772,11 +772,6 @@ impl ParaStyleOptions {
|
||||
edited_attrs(self.inner.fields(), &self.opening)
|
||||
}
|
||||
|
||||
/// What the dialog opened with.
|
||||
pub(crate) fn opening(&self) -> &Opening {
|
||||
&self.opening
|
||||
}
|
||||
|
||||
fn command(&self, attrs: Map<String, Value>) -> Value {
|
||||
let to = self.inner.fields().text("name").unwrap_or_default();
|
||||
json!({"name": self.opening.style, "to": to, "attrs": attrs})
|
||||
|
||||
@@ -155,11 +155,6 @@ pub(crate) enum Opened {
|
||||
}
|
||||
|
||||
impl PluginDialog {
|
||||
/// The plug-in the dialog is for.
|
||||
pub(crate) fn plugin(&self) -> &str {
|
||||
self.kind.plugin()
|
||||
}
|
||||
|
||||
/// Whether the dialog is an importer's whose Open opens a file the picker chose, which is read off the UI thread
|
||||
/// where the app can.
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -56,6 +56,9 @@ impl ManagerRow {
|
||||
}
|
||||
}
|
||||
|
||||
/// Makes detail elements with the words of the drawing `Ui`'s `Env`.
|
||||
pub(crate) type LazyDetails = Arc<dyn Fn(&Env) -> Vec<Detail> + Send + Sync>;
|
||||
|
||||
/// One element of the detail column.
|
||||
pub(crate) enum Detail {
|
||||
/// The preset's name, strong.
|
||||
@@ -71,7 +74,7 @@ pub(crate) enum Detail {
|
||||
/// The parameter rows of the preset's options over their values; the flag makes them read only.
|
||||
Rows(Vec<Param>, DialogFields, bool),
|
||||
/// Elements whose text needs the framework's words, which only the `Env` of the drawing `Ui` gives.
|
||||
Lazy(Arc<dyn Fn(&Env) -> Vec<Detail> + Send + Sync>),
|
||||
Lazy(LazyDetails),
|
||||
}
|
||||
|
||||
/// A button under the list.
|
||||
@@ -257,11 +260,6 @@ impl PresetManager {
|
||||
self.stored = stored;
|
||||
self.detail = detail;
|
||||
}
|
||||
|
||||
/// Whether the selected preset is a built-in one.
|
||||
fn built_in(&self) -> bool {
|
||||
find(&self.rows, &self.selected).is_none_or(|row| row.built_in)
|
||||
}
|
||||
}
|
||||
|
||||
impl StackDialog for PresetManager {
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
//! dialog stays open. [`params`] lays out the options of Effect › Rasterize… with the same rows.
|
||||
|
||||
use craft::ui::contract::Bind;
|
||||
use craft::ui::dialog::DialogId;
|
||||
use craft::ui::patterns::form_dialogs::{HostedParamDialog, Param, ParamDialog, ParamKind, ParamResult};
|
||||
use craft::ui::runtime::env::UnitKind;
|
||||
use serde_json::{Map, Value, json};
|
||||
@@ -16,19 +15,13 @@ use vectorcraft_render::AntiAlias;
|
||||
use super::effect_params::{EffectCx, own_choices};
|
||||
use super::form::{fields_of, json_of};
|
||||
use super::halftone::options;
|
||||
use super::host::{HeldOptions, open_held_with};
|
||||
use super::host::open_held;
|
||||
use crate::VectorcraftApp;
|
||||
|
||||
const CMD: &str = "document.rasterEffectsSettings";
|
||||
/// The resolution presets: (ppi, label).
|
||||
const RESOLUTIONS: [(f64, &str); 3] = [(72.0, "Screen (72 ppi)"), (150.0, "Medium (150 ppi)"), (300.0, "High (300 ppi)")];
|
||||
|
||||
/// The open Document Raster Effects Settings dialog.
|
||||
pub(crate) struct Open {
|
||||
/// The dialog's id on the host.
|
||||
pub id: DialogId,
|
||||
}
|
||||
|
||||
/// Sets `resolutionPreset` from `resolution` and `useDocumentResolution`: Use Document Raster
|
||||
/// Effects Resolution, the preset whose ppi the resolution is, or Other.
|
||||
// PLAN: effects-w4's `effect::open` calls this when the Rasterize effect opens.
|
||||
@@ -112,19 +105,15 @@ pub fn open(app: &mut VectorcraftApp) -> Result<Value, String> {
|
||||
let ok = move |app: &mut VectorcraftApp, result: &ParamResult| {
|
||||
let mut params = json_of(&answered, &result.fields);
|
||||
resolution_of(&mut params);
|
||||
app.run(CMD, Value::Object(params))?;
|
||||
app.effect_dialogs.raster = None;
|
||||
Ok(())
|
||||
app.run(CMD, Value::Object(params)).map(|_| ())
|
||||
};
|
||||
let cancel: Box<dyn FnOnce(&mut VectorcraftApp)> = Box::new(|app| app.effect_dialogs.raster = None);
|
||||
let id = open_held_with(app, dialog, ok, HeldOptions { cancel: Some(cancel), ..Default::default() }).ok_or("no window")?;
|
||||
app.effect_dialogs.raster = Some(Open { id });
|
||||
open_held(app, dialog, ok).ok_or("no window")?;
|
||||
Ok(Value::Null)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use craft::ui::dialog::DialogId;
|
||||
use craft::ui::dialog::{DialogId, StackDialog};
|
||||
use craft::ui::patterns::form_dialogs::HostedParamDialog;
|
||||
use serde_json::json;
|
||||
use vectorcraft_engine::Session;
|
||||
@@ -173,7 +162,7 @@ mod tests {
|
||||
fn raster_effects_settings_draw_and_ok_is_one_undo_step() {
|
||||
let mut app = app();
|
||||
crate::menus::invoke(&mut app, "document.rasterEffectsSettings", json!({}));
|
||||
let id = app.effect_dialogs.raster.as_ref().unwrap().id;
|
||||
let id = app.dialogs().unwrap().with(|h| h.get::<HostedParamDialog>().map(StackDialog::id)).unwrap();
|
||||
assert_eq!(text(&app, id, "colorModel").as_deref(), Some("rgb"));
|
||||
// `ui.dialog.set` names the dialog by the id `ui.inspect` lists.
|
||||
let listed = id.value().to_string();
|
||||
@@ -186,7 +175,7 @@ mod tests {
|
||||
set(&mut app, Some(&listed), "resolutionPreset", json!("other"));
|
||||
set(&mut app, Some(&listed), "resolution", json!(200));
|
||||
ok(&mut app, id);
|
||||
assert!(app.effect_dialogs.raster.is_none());
|
||||
assert!(app.dialogs().unwrap().with(|h| h.get_by_id::<HostedParamDialog>(id).is_none()), "OK closes the dialog");
|
||||
let st = app.session.active().unwrap();
|
||||
let r = &st.doc.raster_effects;
|
||||
assert_eq!((st.doc.raster_effects_ppi, r.add_around, r.background), (200.0, 36.0, vectorcraft_doc::Background::White));
|
||||
|
||||
@@ -300,7 +300,9 @@ mod tests {
|
||||
/// setting the layout makes meaningless is refused.
|
||||
#[test]
|
||||
fn rearrange_fields_reach_the_command() {
|
||||
let cases: [(u32, &[(&str, Value)], &[(f64, f64)]); 2] = [
|
||||
type Settings<'a> = &'a [(&'a str, Value)];
|
||||
type Positions<'a> = &'a [(f64, f64)];
|
||||
let cases: [(u32, Settings<'_>, Positions<'_>); 2] = [
|
||||
(3, &[("layout", json!("row")), ("order", json!("rightToLeft")), ("spacing", json!(10))], &[(220.0, 0.0), (110.0, 0.0), (0.0, 0.0)]),
|
||||
(
|
||||
4,
|
||||
|
||||
@@ -3678,7 +3678,7 @@ mod tests {
|
||||
let row_of = |rc: &Recolor, key: &str| rc.rows().iter().position(|r| r["from"][0] == key).unwrap();
|
||||
let (r, b) = (row_of(&rc, "rgb 255 0 0"), row_of(&rc, "rgb 0 0 255"));
|
||||
let undo = undo_len(&rc.app());
|
||||
let fills = |rc: &Recolor| (fill_hex(&rc, red), fill_hex(&rc, blue));
|
||||
let fills = |rc: &Recolor| (fill_hex(rc, red), fill_hex(rc, blue));
|
||||
rc.set(THEME_PICKS, json!([{"at": [107, 17]}])).unwrap();
|
||||
rc.frame();
|
||||
assert_eq!(new_colors(&rc), [json!("rgb 0 255 0"), json!("rgb 0 255 0")], "one color for both rows");
|
||||
@@ -3724,7 +3724,7 @@ mod tests {
|
||||
fn colors_merged_into_a_new_row_take_its_new_color() {
|
||||
let (mut rc, [red, blue]) = theme_setup();
|
||||
let undo = undo_len(&rc.app());
|
||||
let fills = |rc: &Recolor| (fill_hex(&rc, red), fill_hex(&rc, blue));
|
||||
let fills = |rc: &Recolor| (fill_hex(rc, red), fill_hex(rc, blue));
|
||||
let mut rs = rc.rows();
|
||||
let at = new_row(&mut rs, &[]);
|
||||
rs[at]["to"] = json!("rgb 0 255 0");
|
||||
@@ -4042,7 +4042,7 @@ mod tests {
|
||||
fn find_shows_the_selected_rows_art_and_dims_the_rest() {
|
||||
let (mut rc, [red, blue]) = theme_setup();
|
||||
let undo = undo_len(&rc.app());
|
||||
let fills = |rc: &Recolor| (fill_hex(&rc, red), fill_hex(&rc, blue));
|
||||
let fills = |rc: &Recolor| (fill_hex(rc, red), fill_hex(rc, blue));
|
||||
let rs = json!([{"from": ["rgb 255 0 0"], "to": "rgb 0 255 0"}, {"from": ["rgb 0 0 255"], "to": "rgb 255 255 0"}]);
|
||||
rc.set("rows", rs.clone()).unwrap();
|
||||
rc.set("__sel", json!([0])).unwrap();
|
||||
|
||||
@@ -255,7 +255,7 @@ fn tool_row(ui: &mut Ui, d: &mut Fields, display: &'static str, axes: DiscRadius
|
||||
}
|
||||
let tip = if bright { tl!("Show saturation and hue on wheel") } else { tl!("Show brightness and hue on wheel") };
|
||||
// The button is named for what a click shows next, as its tooltip says.
|
||||
flipped = ToggleButton::new(tip.clone(), Bind::given(on_wheel && bright))
|
||||
flipped = ToggleButton::new(tip, Bind::given(on_wheel && bright))
|
||||
.icon(IconId::new("sun"))
|
||||
.icon_only()
|
||||
.tooltip(tip)
|
||||
|
||||
@@ -5,12 +5,11 @@
|
||||
use std::cell::{RefCell, RefMut};
|
||||
use std::rc::Rc;
|
||||
|
||||
use craft::behavior::PartRef;
|
||||
use craft::ui::dialog::{DialogHost, DialogId, HeldOk, dialog_id};
|
||||
use craft::ui::runtime::access::Role;
|
||||
use craft::ui::testing::pointer::part_rect_of_node;
|
||||
use craft::ui::testing::{Fixture, Room, Target};
|
||||
use egui::{Event, Modifiers, PointerButton, Pos2, Rect, Vec2};
|
||||
use egui::{Event, Modifiers, PointerButton, Pos2, Rect};
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use super::{Fields, GROUP_ACTION, KIND, RecolorDialog};
|
||||
@@ -183,25 +182,6 @@ impl Recolor {
|
||||
self
|
||||
}
|
||||
|
||||
/// The rect of part `part` of component `owner`, for a part with no access node.
|
||||
pub(crate) fn part_rect(&self, owner: egui::Id, part: impl Into<PartRef>) -> Option<Rect> {
|
||||
self.fixture.part_rect(owner, part)
|
||||
}
|
||||
|
||||
/// A drag of the control named `label` by `by`, released.
|
||||
pub(crate) fn drag(&mut self, label: &str, by: Vec2) -> &mut Self {
|
||||
let target = self.target(label);
|
||||
self.fixture.drag(&target, by);
|
||||
self
|
||||
}
|
||||
|
||||
/// A press on the control named `label`, held.
|
||||
pub(crate) fn press(&mut self, label: &str) -> &mut Self {
|
||||
let target = self.target(label);
|
||||
self.fixture.press(&target);
|
||||
self
|
||||
}
|
||||
|
||||
/// The rects of the graphics objects inside `area` (a bar's parts), left to right.
|
||||
pub(crate) fn graphics_in(&self, area: Rect) -> Vec<Rect> {
|
||||
let mut rects: Vec<Rect> =
|
||||
|
||||
@@ -81,7 +81,7 @@ pub fn open(app: &mut VectorcraftApp, p: &Value) -> Result<Value, String> {
|
||||
}
|
||||
}
|
||||
let dialog = RelinkDialog::new(ids, links);
|
||||
crate::dialogs::host::open_held(app, dialog, |app, params| relink(app, params)).ok_or("no window")?;
|
||||
crate::dialogs::host::open_held(app, dialog, relink).ok_or("no window")?;
|
||||
Ok(Value::Null)
|
||||
}
|
||||
|
||||
|
||||
@@ -247,7 +247,7 @@ fn object_rows(data: &Data, rows: &Rows, effect: &str, place: Place) -> Vec<Para
|
||||
CLASSIC_REVOLVE => return super::three_d_classic::revolve_params(data, &DialogFields::new(), effect),
|
||||
_ => {}
|
||||
}
|
||||
let solid = vec![Value::Bool(true), Value::Bool(false)];
|
||||
let solid = [Value::Bool(true), Value::Bool(false)];
|
||||
let cap = select_row("cap", c3("Cap"), vec![(solid[0].clone(), c3("Solid").into()), (solid[1].clone(), c3("Hollow").into())], json!(true));
|
||||
let mut out = vec![
|
||||
Param::section(tl!("Object")),
|
||||
@@ -311,9 +311,9 @@ fn bevel_heading() -> Param {
|
||||
pub(crate) type BevelChoice = (String, Value, Option<(String, Value)>);
|
||||
|
||||
/// The entries of the Bevel Shape menu for form `fields`, and how many are built in. The built-in labels are
|
||||
/// translated; custom bevels show their names as they are. The effect's own custom bevel, the panel's [`OWN_BEVEL`]
|
||||
/// else the form's, is listed unless the file lists it by name with the same points; while another entry has its
|
||||
/// label, " (document)" is added to it.
|
||||
/// translated; custom bevels show their names as they are. The effect's own custom bevel in `fields` (the 3D and
|
||||
/// Materials panel gives the first selected effect's settings, unmarked by a mixed selection) is listed unless the
|
||||
/// file lists it by name with the same points; while another entry has its label, " (document)" is added to it.
|
||||
pub(crate) fn bevel_options(app: &VectorcraftApp, fields: &serde_json::Map<String, Value>, effect: &str) -> (Vec<BevelChoice>, usize) {
|
||||
let mut options: Vec<BevelChoice> = super::effect_params::own_choices(effect, "bevel", false)
|
||||
.unwrap_or_default()
|
||||
@@ -325,13 +325,10 @@ pub(crate) fn bevel_options(app: &VectorcraftApp, fields: &serde_json::Map<Strin
|
||||
options.push((b.name.clone(), json!("custom"), Some((b.name.clone(), b.profile_json()))));
|
||||
}
|
||||
let custom = fields.get("bevel").and_then(Value::as_str) == Some("custom");
|
||||
let own = match fields.get(OWN_BEVEL).and_then(Value::as_array).map(Vec::as_slice) {
|
||||
Some([n, p]) => Some((n.as_str().unwrap_or_default().to_string(), p.clone())),
|
||||
_ => fields
|
||||
.get(BEVEL_PROFILE)
|
||||
.filter(|p| custom && !p.is_null())
|
||||
.map(|p| (fields.get(BEVEL_NAME).and_then(Value::as_str).unwrap_or_default().to_string(), p.clone())),
|
||||
};
|
||||
let own = fields
|
||||
.get(BEVEL_PROFILE)
|
||||
.filter(|p| custom && !p.is_null())
|
||||
.map(|p| (fields.get(BEVEL_NAME).and_then(Value::as_str).unwrap_or_default().to_string(), p.clone()));
|
||||
if let Some((n, p)) = own
|
||||
&& !options[builtin..].iter().any(|(_, _, c)| c.as_ref().is_some_and(|(cn, cp)| *cn == n && *cp == p))
|
||||
{
|
||||
@@ -345,10 +342,6 @@ pub(crate) fn bevel_options(app: &VectorcraftApp, fields: &serde_json::Map<Strin
|
||||
(options, builtin)
|
||||
}
|
||||
|
||||
/// The form field where the 3D and Materials panel puts the first selected effect's custom bevel, `[name, points]`,
|
||||
/// so Bevel Shape lists it while a mixed selection unsets the shown bevel.
|
||||
pub(crate) const OWN_BEVEL: &str = "__ownBevel";
|
||||
|
||||
/// The Bevel Shape menu of Extrude & Bevel and Extrude & Bevel (Classic) (`effect`): None and the built-in shapes,
|
||||
/// then the custom bevels of the bevels file, and the effect's own custom bevel when the file does not list it. Picking
|
||||
/// a custom bevel stores its name and a copy of its points. In the panel, Edit Bevels… opens the bevels file
|
||||
|
||||
@@ -95,15 +95,6 @@ fn round(n: f64) -> f64 {
|
||||
(n * 10.0).round() / 10.0
|
||||
}
|
||||
|
||||
/// The effect's lights: each light of its list, or its single light, with the effect's defaults for
|
||||
/// the settings a light leaves out or the selected effects hold with different values (null). A 3D
|
||||
/// (Classic) effect's lights are white whatever color a list light carries, since it shades
|
||||
/// without light color.
|
||||
pub(crate) fn lights(fields: &DialogFields) -> Lights {
|
||||
let classic = vectorcraft_effects::is_classic_three_d(fields.text("__effect").unwrap_or_default());
|
||||
lights_for(fields, classic)
|
||||
}
|
||||
|
||||
/// [`lights`] for a light editor that already knows whether it edits a 3D (Classic) effect.
|
||||
fn lights_for(fields: &DialogFields, classic: bool) -> Lights {
|
||||
let defaults = vectorcraft_effects::default_params(fields.text("__effect").unwrap_or_default()).unwrap_or(json!({}));
|
||||
@@ -297,7 +288,7 @@ impl Component for LightSphere<'_> {
|
||||
let level = u8::from(index == self.selected);
|
||||
cx.part(LIGHT.at(index as u64), HitShape::circle(center + light.offset() * radius, SUN + 4.0))
|
||||
.sense(Sense::DRAG | Sense::CLICK)
|
||||
.priority(HitPriority::new(HitLevel::Handle, level.into()))
|
||||
.priority(HitPriority::new(HitLevel::Handle, level))
|
||||
.cursor(CursorIcon::Grab)
|
||||
.drag_cursor(CursorIcon::Grabbing)
|
||||
.tooltip(tl!("Drag a light to move it. The arrow keys move the focused light; Shift steps 15°."))
|
||||
|
||||
@@ -187,7 +187,7 @@ pub fn open(app: &mut VectorcraftApp) -> Result<Value, String> {
|
||||
let (size, original) = match render_for(app, &natural) {
|
||||
Ok((key, r)) => {
|
||||
let texture = original_texture(&ctx, &key, &r);
|
||||
app.web_export.original = Some(texture.clone());
|
||||
app.web_export.original = Some(texture);
|
||||
(PixelSize::new(r.width, r.height), texture)
|
||||
}
|
||||
// The panes show why the rendering failed; the Original pane has nothing to show.
|
||||
@@ -503,7 +503,7 @@ fn answer_variants(app: &mut VectorcraftApp, ctx: &egui::Context, host: &craft::
|
||||
_ => None,
|
||||
};
|
||||
if let Some(texture) = fresh {
|
||||
app.web_export.original = Some(texture.clone());
|
||||
app.web_export.original = Some(texture);
|
||||
on_dialog(host, |d| d.set_original(texture));
|
||||
}
|
||||
on_dialog(host, |d| answers.into_iter().for_each(|v| d.set_variant(v)));
|
||||
|
||||
@@ -366,7 +366,7 @@ pub(crate) fn dialog_set(app: &mut VectorcraftApp, params: &Value) -> Option<Res
|
||||
let id = open.id;
|
||||
let (top, name) =
|
||||
dialogs.with(|host| (host.open_dialogs().last().map(|d| d.id), host.get_by_id::<HostedPdfExport>(id).map(super::flatten::preset_name)));
|
||||
let named = (params["dialog"] == "top" && top == Some(id)) || params["dialog"] == id.value().to_string();
|
||||
let named = (params["dialog"] == "top" && top == Some(id)) || params["dialog"] == id.value();
|
||||
let (true, Some(name), Some(job)) = (named, name, open.job.as_mut()) else { return None };
|
||||
let custom = job.flattener.as_ref().and_then(|f| serde_json::to_value(f).ok());
|
||||
let set = FlattenOptions::for_export(Some(&name), custom.as_ref(), &saved).and_then(|now| {
|
||||
@@ -377,7 +377,7 @@ pub(crate) fn dialog_set(app: &mut VectorcraftApp, params: &Value) -> Option<Res
|
||||
Some(set.map(|options| {
|
||||
job.flattener = Some(options);
|
||||
let shown = dialogs.with(|host| craft::automation::dialogs::inspect(host));
|
||||
shown.as_array().and_then(|list| list.iter().find(|d| d["id"] == id.value().to_string())).cloned().unwrap_or(Value::Null)
|
||||
shown.as_array().and_then(|list| list.iter().find(|d| d["id"] == id.value())).cloned().unwrap_or(Value::Null)
|
||||
}))
|
||||
}
|
||||
|
||||
|
||||
@@ -355,12 +355,15 @@ pub(crate) fn apply_preset(fields: &mut Map<String, Value>, preset: &Value) {
|
||||
fields.insert("exportPreset".into(), json!(preset["name"]));
|
||||
}
|
||||
|
||||
/// The dialog's format presets menu, drawn in the Formats row over the dialog's fields.
|
||||
pub(crate) type FormatMenu<'a> = &'a mut dyn FnMut(&mut Ui, &mut Map<String, Value>);
|
||||
|
||||
/// Formats: the iOS and Android buttons (each sets the rows that platform uses), `menu` (the
|
||||
/// dialog's format presets), the Format Settings gear (which sets `__settings`), the format rows
|
||||
/// (scale, suffix, format) and Add Scale, as wide as `ui` allows: the dialog's and the Asset Export
|
||||
/// panel's rows. A row edit makes `preset` "". Nothing is kept between passes: the rows are built
|
||||
/// over `fields` each pass.
|
||||
pub(crate) fn rows(ui: &mut Ui, fields: &mut Map<String, Value>, mut menu: Option<&mut dyn FnMut(&mut Ui, &mut Map<String, Value>)>) -> Response {
|
||||
pub(crate) fn rows(ui: &mut Ui, fields: &mut Map<String, Value>, mut menu: Option<FormatMenu<'_>>) -> Response {
|
||||
let mut rows: Vec<Value> = fields.get("formats").and_then(Value::as_array).cloned().unwrap_or_default();
|
||||
let preset = text(fields, "preset").to_string();
|
||||
let sizes: Vec<Entry<String>> = SIZES.iter().map(|s| Entry::new((*s).to_string(), *s)).collect();
|
||||
|
||||
@@ -18,7 +18,8 @@
|
||||
//!
|
||||
//! A script's file dialog (kind `scriptFiles`: `File.openDialog`, `File.saveDialog`,
|
||||
//! `Folder.selectDialog` and the objects' `openDlg`, `saveDlg` and `selectDlg`) has the fields
|
||||
//! `kind` (open, save or folder), `prompt`, `canAlways` and `answer`. Only the person at the
|
||||
//! `kind` (open, save or folder), `prompt`, `canAlways`, `paths` (what Choose… picked), `leftOut` (Choose… picked
|
||||
//! more files than a script is given) and `answer`. Only the person at the
|
||||
//! keyboard answers Allow Once or Always Allow: `ui.dialog.set` refuses `once` and `always`, and a
|
||||
//! click made by automation, or on paths that a pick automation opened, is refused and the dialog
|
||||
//! opens again with the same paths; `deny` and `stop` are taken from automation too. The paths it
|
||||
@@ -290,16 +291,6 @@ impl ScriptFiles {
|
||||
}
|
||||
}
|
||||
|
||||
/// The paths Choose… picked.
|
||||
pub(crate) fn paths(&self) -> &[String] {
|
||||
&self.paths
|
||||
}
|
||||
|
||||
/// Whether Choose… left out files past the most a script is given.
|
||||
pub(crate) fn left_out(&self) -> bool {
|
||||
self.left_out
|
||||
}
|
||||
|
||||
/// Keeps what a pick chose: in place of the paths before, or after them when the script asked
|
||||
/// for several files. At most [`MAX_ENTRIES`] are kept, the number of files a script is given.
|
||||
/// A pick that chose nothing changes nothing.
|
||||
@@ -377,7 +368,14 @@ impl StackDialog for ScriptFiles {
|
||||
}
|
||||
|
||||
fn json_fields(&self) -> Option<Value> {
|
||||
Some(json!({"kind": self.kind.id(), "prompt": self.prompt, "canAlways": self.can_always, "answer": self.answer}))
|
||||
Some(json!({
|
||||
"kind": self.kind.id(),
|
||||
"prompt": self.prompt,
|
||||
"canAlways": self.can_always,
|
||||
"paths": self.paths,
|
||||
"leftOut": self.left_out,
|
||||
"answer": self.answer,
|
||||
}))
|
||||
}
|
||||
|
||||
fn set_json_field(&mut self, _: &egui::Context, field: &str, value: Value) -> Result<(), String> {
|
||||
|
||||
@@ -307,8 +307,7 @@ fn grid_options(kind: &str, fields: &DialogFields) -> Map<String, Value> {
|
||||
options
|
||||
}
|
||||
|
||||
/// The size of the arc picture in Arc Segment Tool Options, and its margin around the arc.
|
||||
const ARC_PREVIEW: egui::Vec2 = egui::vec2(160.0, 120.0);
|
||||
/// The margin around the arc in Arc Segment Tool Options' picture.
|
||||
const ARC_PREVIEW_MARGIN: f32 = 12.0;
|
||||
|
||||
/// The arc the Arc tool draws with the options OK sets from `fields` ([`arc_options`]; a slope past -100
|
||||
@@ -762,7 +761,7 @@ mod tests {
|
||||
/// the frame, and stays finite for a length of 0 or a huge one.
|
||||
#[test]
|
||||
fn the_arc_preview_follows_the_fields_and_fits_its_frame() {
|
||||
let rect = egui::Rect::from_min_size(egui::pos2(10.0, 20.0), ARC_PREVIEW);
|
||||
let rect = egui::Rect::from_min_size(egui::pos2(10.0, 20.0), egui::vec2(160.0, 120.0));
|
||||
let shape = |fields: Value| arc_preview_shape(&arc_dialog(fields), 0.0, rect).expect("an arc");
|
||||
let inside = |s: &ArcPreview| {
|
||||
let room = rect.shrink(ARC_PREVIEW_MARGIN - 0.01);
|
||||
|
||||
@@ -243,7 +243,7 @@ pub(crate) fn show(app: &mut VectorcraftApp, ui: &mut egui::Ui, view: &CanvasVie
|
||||
}
|
||||
None if auto_clicked => {
|
||||
app.object_dialogs.strip = Some(strip);
|
||||
auto_of(app, kind).map(|v| v)
|
||||
auto_of(app, kind)
|
||||
}
|
||||
None => {
|
||||
let params = strip.params();
|
||||
|
||||
@@ -347,7 +347,10 @@ pub(crate) fn pump(app: &mut VectorcraftApp, _ctx: &egui::Context) {
|
||||
});
|
||||
let Some((action, selected, editing, code)) = taken.filter(|(action, ..)| !action.is_empty()) else { return };
|
||||
let result: Result<(), String> = match action.as_str() {
|
||||
"new" => Ok(set(app, &[(EDITING, json!("new")), (CODE, json!(""))])),
|
||||
"new" => {
|
||||
set(app, &[(EDITING, json!("new")), (CODE, json!(""))]);
|
||||
Ok(())
|
||||
}
|
||||
"edit" => {
|
||||
if let Some(f) = filters(app).0.iter().map(|f| &f.filter).find(|f| f.name == selected) {
|
||||
let (name, xml) = (f.name.clone(), f.xml.clone());
|
||||
@@ -363,7 +366,10 @@ pub(crate) fn pump(app: &mut VectorcraftApp, _ctx: &egui::Context) {
|
||||
}
|
||||
app.run("svgFilter.define", p).map(|r| set(app, &[(SELECTED, r["name"].clone()), (EDITING, json!("")), (CODE, json!(""))]))
|
||||
}
|
||||
"discard" => Ok(set(app, &[(EDITING, json!("")), (CODE, json!(""))])),
|
||||
"discard" => {
|
||||
set(app, &[(EDITING, json!("")), (CODE, json!(""))]);
|
||||
Ok(())
|
||||
}
|
||||
"import" => {
|
||||
ask_import(app);
|
||||
Ok(())
|
||||
|
||||
@@ -24,8 +24,8 @@ pub(super) fn app() -> VectorcraftApp {
|
||||
pub(super) fn frame(app: &mut VectorcraftApp, events: Vec<egui::Event>) -> egui::FullOutput {
|
||||
let ctx = app.ui_ctx.clone().expect("a window app");
|
||||
let raw = egui::RawInput { events, focused: true, screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, SCREEN)), ..Default::default() };
|
||||
let out = crate::testing::app_frame(app, &ctx, raw);
|
||||
out
|
||||
|
||||
crate::testing::app_frame(app, &ctx, raw)
|
||||
}
|
||||
|
||||
/// Frames until what a command just opened has measured, placed itself and run its first preview.
|
||||
|
||||
@@ -309,7 +309,7 @@ fn dragging_the_preview_moves_the_placement_on_the_paper() {
|
||||
),
|
||||
] {
|
||||
let before = app.session.execute("print.preview", &json!({ "settings": settings })).unwrap();
|
||||
let (dx, dy) = (f64::from(dx), f64::from(dy));
|
||||
let (dx, dy) = (dx, dy);
|
||||
let mut dialog_fields = super::print::fields_of(&serde_json::from_value(settings.clone()).unwrap()).unwrap();
|
||||
let placement = super::print::settings(&dialog_fields)["placement"].clone();
|
||||
super::print::move_placement(&mut dialog_fields, &before["sheets"][0], (dx, dy));
|
||||
|
||||
@@ -17,7 +17,7 @@ pub(super) fn fields(app: &VectorcraftApp) -> DialogFields {
|
||||
host.get_by_id::<HostedParamDialog>(id).map(|d| d.fields().clone())
|
||||
})
|
||||
})
|
||||
.unwrap_or_else(DialogFields::new)
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
/// A JPEG's SOF marker and component count.
|
||||
@@ -34,7 +34,8 @@ fn jpeg_frame(file: &[u8]) -> (u8, u8) {
|
||||
#[test]
|
||||
fn raster_option_rows_reach_the_export_params() {
|
||||
type Check = fn(&[u8]);
|
||||
let rows: [(&str, &[(&str, serde_json::Value)], Check); 8] = [
|
||||
type Set<'a> = &'a [(&'a str, serde_json::Value)];
|
||||
let rows: [(&str, Set<'_>, Check); 8] = [
|
||||
("jpg", &[("method", json!("progressive")), ("scans", json!(4)), ("colorModel", json!("cmyk")), ("quality", json!(30))], |file| {
|
||||
assert_eq!(jpeg_frame(file), (0xC2, 4), "progressive CMYK");
|
||||
assert!(file.windows(12).any(|w| w == b"ICC_PROFILE\0"));
|
||||
|
||||
@@ -271,7 +271,7 @@ fn rectangular_grid_cancel_discards_edits_and_reopens_from_saved_values() {
|
||||
click(&mut app, Point::new(111.0, 147.0));
|
||||
values(&mut app, json!(18), json!(30), json!(9), json!(1));
|
||||
cancel_of(&mut app, KIND);
|
||||
assert!(!is_open(&mut app, KIND));
|
||||
assert!(!is_open(&app, KIND));
|
||||
before.assert_unchanged(&app);
|
||||
click(&mut app, Point::new(209.0, 173.0));
|
||||
assert_eq!((field(&mut app, "x"), field(&mut app, "y")), (json!(209.0), json!(173.0)));
|
||||
@@ -331,7 +331,7 @@ fn rectangular_grid_failed_creation_does_not_save_counts() {
|
||||
click(&mut app, Point::new(30.0, 40.0));
|
||||
values(&mut app, json!(120), json!(60), json!(7), json!(8));
|
||||
assert!(try_confirm(&mut app, KIND).is_err());
|
||||
assert!(is_open(&mut app, KIND), "a refusal keeps the dialog open");
|
||||
assert!(is_open(&app, KIND), "a refusal keeps the dialog open");
|
||||
assert_eq!(app.session.tool_options_of(KIND), before.options);
|
||||
assert_eq!(app.session.doc().unwrap().history.undo.len(), before.undo);
|
||||
}
|
||||
@@ -346,7 +346,7 @@ fn rectangular_grid_tool_options_with_a_refused_width_stay_open() {
|
||||
set(&mut app, "width", json!(0));
|
||||
let e = try_confirm(&mut app, KIND).unwrap_err();
|
||||
assert!(e.contains("`width`"), "{e}");
|
||||
assert!(is_open(&mut app, KIND));
|
||||
assert!(is_open(&app, KIND));
|
||||
assert_eq!(app.session.tool_options_of(KIND), before);
|
||||
}
|
||||
|
||||
@@ -390,10 +390,10 @@ fn a_grid_dialog_sends_its_skews_switch_and_fill() {
|
||||
click(&mut app, at);
|
||||
} else {
|
||||
super::shapes::open(&mut app, kind, Some(super::shapes::Click { at, alt: false }));
|
||||
assert!(is_open(&mut app, kind));
|
||||
assert!(is_open(&app, kind));
|
||||
}
|
||||
for (key, value) in initial {
|
||||
assert_eq!(field_of(&mut app, kind, key), value, "{kind} {key}");
|
||||
assert_eq!(field_of(&app, kind, key), value, "{kind} {key}");
|
||||
}
|
||||
for (key, value) in edits {
|
||||
set_of(&mut app, kind, key, value).unwrap();
|
||||
|
||||
@@ -384,7 +384,7 @@ fn flat_view(ui: &mut Ui, fields: &mut DialogFields, flat: &Flat) -> Response {
|
||||
let (width, height) = (flat.width.max(1e-6), flat.height.max(1e-6));
|
||||
let margin = f64::from(ui.spacing().item_spacing.x) * 2.0;
|
||||
let zoom = ((f64::from(room.width()) - margin) / width).min((f64::from(room.height()) - margin) / height).max(1e-6);
|
||||
let view = CanvasView::new(room.into(), Point::ZERO, zoom);
|
||||
let view = CanvasView::new(room, Point::ZERO, zoom);
|
||||
let rect = flat.art.map(art_rect);
|
||||
let mut edited = map.clone();
|
||||
Canvas::new(tl!("Surface")).view(view).show_at(ui, room, |ui, body| {
|
||||
@@ -535,7 +535,7 @@ pub(crate) fn show_outline(app: &mut VectorcraftApp, ui: &mut Ui, space: &Canvas
|
||||
path.line_to((b.x, b.y));
|
||||
}
|
||||
let paths = [path];
|
||||
SelectionOutline::solid(tl!("Map Art surface"), &paths).color(DataColor::new(Color32::RED)).show_at(ui, space.view.rect.into());
|
||||
SelectionOutline::solid(tl!("Map Art surface"), &paths).color(DataColor::new(Color32::RED)).show_at(ui, space.view.rect);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -397,7 +397,7 @@ pub(crate) fn row() -> Param {
|
||||
}
|
||||
});
|
||||
let mixed = now.iter().any(|m| matches!(m, Mixed::Mixed));
|
||||
let out = TrackCube::new(tl!("Track cube"), Bind::given(now.clone())).enabled(!mixed).show(ui);
|
||||
let out = TrackCube::new(tl!("Track cube"), Bind::given(now)).enabled(!mixed).show(ui);
|
||||
cx.gesture(&out.events);
|
||||
let was = degrees(&now);
|
||||
// What each event leaves in the cube, a cancel's restored start included.
|
||||
|
||||
@@ -502,7 +502,8 @@ mod tests {
|
||||
/// Transform Objects off.
|
||||
#[test]
|
||||
fn a_transform_dialog_sends_its_commands_params() {
|
||||
let rows: [(&str, Vec<(&str, Value)>, &str, Value); 5] = [
|
||||
type Fields<'a> = Vec<(&'a str, Value)>;
|
||||
let rows: [(&str, Fields<'_>, &str, Value); 5] = [
|
||||
("object.reflect", vec![("axis", json!("horizontal"))], "axis", json!("horizontal")),
|
||||
("object.reflect", vec![("axis", json!("angle")), ("angle", json!(45))], "axis", json!(45.0)),
|
||||
("object.shear", vec![("axis", json!("vertical")), ("angle", json!(45))], "axis", json!("vertical")),
|
||||
|
||||
@@ -116,7 +116,7 @@ fn window_tab_at(shapes: &[Shape], title: &str, window: egui::Rect) -> Pos2 {
|
||||
Shape::Text(t) if t.pos.y >= 35.0 && window.contains(t.pos) && t.galley.text().contains(title) => Some(t.pos + vec2(4.0, 4.0)),
|
||||
_ => None,
|
||||
})
|
||||
.last()
|
||||
.next_back()
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ fn ctx() -> egui::Context {
|
||||
/// One whole app frame at `time`; returns the named nodes it drew.
|
||||
fn frame(app: &mut VectorcraftApp, ctx: &egui::Context, time: f64, events: Vec<Event>) -> Nodes {
|
||||
let input = RawInput { time: Some(time), events, screen_rect: Some(Rect::from_min_size(Pos2::ZERO, SCREEN)), ..Default::default() };
|
||||
let out = crate::testing::app_frame(app, &ctx, input);
|
||||
let out = crate::testing::app_frame(app, ctx, input);
|
||||
let nodes = out.platform_output.accesskit_update.map(|u| u.nodes).unwrap_or_default();
|
||||
nodes
|
||||
.into_iter()
|
||||
@@ -400,7 +400,7 @@ fn basic_or_advanced_takes_the_drawer_to_the_tools_panel() {
|
||||
app.run("window.toolbar", json!({})).unwrap();
|
||||
for advanced in [false, true] {
|
||||
app.run("window.editToolbar", json!({"toolbar": "Mine", "open": true})).unwrap();
|
||||
pick_layout(&mut app, advanced).unwrap();
|
||||
crate::menus::invoke(&mut app, "window.toolbarAdvanced", json!({ "advanced": advanced }));
|
||||
assert!(app.ui.tools_drawer && crate::custom_toolbars::drawer_target(&app.ui).is_none(), "{advanced}");
|
||||
assert_eq!(app.ui.toolbar_advanced, advanced);
|
||||
assert!(crate::toolbar::shown(&app.ui), "the Tools panel shows beside the drawer");
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user