Merge main into fix/speed-global-edit-preview-member-list

This commit is contained in:
dotCooCoo committed 2026-11-29 14:48:54 -08:00
commit 1a7e524d90
20 files changed
+456 -177

No files matched your search

+1
View File
@@ -42,6 +42,7 @@ jobs:
dry-run: ${{ github.event_name == 'schedule' }}
app-name: vectorcraft
app-title: VectorCraft
macos-runner: macos-15
craft-fonts-ref: b076417b5880bd4154bd22f00695b1d28c6bea83
web-craft-fonts: true
version: ${{ inputs.version }}
+1 -1
View File
@@ -11,7 +11,7 @@ permissions:
contents: read
concurrency:
group: sonarcloud-${{ github.ref }}
group: ${{ github.ref == 'refs/heads/main' && format('sonarcloud-main-{0}', github.sha) || format('sonarcloud-{0}', github.ref) }}
# A push to main is the run that publishes coverage; superseded runs there would never finish.
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
Generated
+60 -75
View File
@@ -8515,7 +8515,7 @@ dependencies = [
[[package]]
name = "vectorcraft"
version = "0.24.1"
version = "0.25.0"
dependencies = [
"arboard",
"block2 0.6.2",
@@ -8558,7 +8558,7 @@ dependencies = [
[[package]]
name = "vectorcraft-affinity"
version = "0.24.1"
version = "0.25.0"
dependencies = [
"craft-affinity",
"craft-image-codecs",
@@ -8569,26 +8569,26 @@ dependencies = [
[[package]]
name = "vectorcraft-apischema"
version = "0.24.1"
version = "0.25.0"
dependencies = [
"serde_json",
]
[[package]]
name = "vectorcraft-brush"
version = "0.24.1"
version = "0.25.0"
dependencies = [
"kurbo 0.13.1",
"serde",
"serde_json",
"vectorcraft-color",
"vectorcraft-doc",
"vectorcraft-geom 0.24.1",
"vectorcraft-geom 0.25.0",
]
[[package]]
name = "vectorcraft-cad"
version = "0.24.1"
version = "0.25.0"
dependencies = [
"craft-dxf",
"craft-image-codecs",
@@ -8600,14 +8600,14 @@ dependencies = [
"vectorcraft-color",
"vectorcraft-doc",
"vectorcraft-effects",
"vectorcraft-geom 0.24.1",
"vectorcraft-pathops 0.24.1",
"vectorcraft-geom 0.25.0",
"vectorcraft-pathops 0.25.0",
"vectorcraft-text",
]
[[package]]
name = "vectorcraft-cli"
version = "0.24.1"
version = "0.25.0"
dependencies = [
"log",
"objc2-core-foundation",
@@ -8618,7 +8618,7 @@ dependencies = [
"vectorcraft-doc",
"vectorcraft-engine",
"vectorcraft-format",
"vectorcraft-geom 0.24.1",
"vectorcraft-geom 0.25.0",
"vectorcraft-mcp",
"vectorcraft-render",
"vectorcraft-svg",
@@ -8630,7 +8630,7 @@ dependencies = [
[[package]]
name = "vectorcraft-color"
version = "0.24.1"
version = "0.25.0"
dependencies = [
"craft-cms",
"craft-color-ui",
@@ -8646,7 +8646,7 @@ dependencies = [
[[package]]
name = "vectorcraft-doc"
version = "0.24.1"
version = "0.25.0"
dependencies = [
"chrono",
"craft-image-codecs",
@@ -8662,13 +8662,13 @@ dependencies = [
"thiserror 2.0.21",
"tiff",
"vectorcraft-color",
"vectorcraft-geom 0.24.1",
"vectorcraft-geom 0.25.0",
"zune-jpeg",
]
[[package]]
name = "vectorcraft-effects"
version = "0.24.1"
version = "0.25.0"
dependencies = [
"craft-image-codecs",
"craft-svg",
@@ -8678,8 +8678,8 @@ dependencies = [
"svgtypes 0.16.1",
"vectorcraft-color",
"vectorcraft-doc",
"vectorcraft-geom 0.24.1",
"vectorcraft-pathops 0.24.1",
"vectorcraft-geom 0.25.0",
"vectorcraft-pathops 0.25.0",
"vectorcraft-plugins",
"vectorcraft-text",
"vectorcraft-three-d",
@@ -8689,7 +8689,7 @@ dependencies = [
[[package]]
name = "vectorcraft-engine"
version = "0.24.1"
version = "0.25.0"
dependencies = [
"apple-native-keyring-store",
"cfb",
@@ -8738,10 +8738,10 @@ dependencies = [
"vectorcraft-doc",
"vectorcraft-eps",
"vectorcraft-format",
"vectorcraft-geom 0.24.1",
"vectorcraft-geom 0.25.0",
"vectorcraft-js",
"vectorcraft-metafile",
"vectorcraft-pathops 0.24.1",
"vectorcraft-pathops 0.25.0",
"vectorcraft-pdf",
"vectorcraft-plugins",
"vectorcraft-render",
@@ -8761,7 +8761,7 @@ dependencies = [
[[package]]
name = "vectorcraft-eps"
version = "0.24.1"
version = "0.25.0"
dependencies = [
"craft-eps",
"craft-image-codecs",
@@ -8782,9 +8782,9 @@ dependencies = [
"vectorcraft-doc",
"vectorcraft-effects",
"vectorcraft-eps",
"vectorcraft-geom 0.24.1",
"vectorcraft-geom 0.25.0",
"vectorcraft-metafile",
"vectorcraft-pathops 0.24.1",
"vectorcraft-pathops 0.25.0",
"vectorcraft-pdf",
"vectorcraft-render",
"vectorcraft-testkit",
@@ -8793,7 +8793,7 @@ dependencies = [
[[package]]
name = "vectorcraft-format"
version = "0.24.1"
version = "0.25.0"
dependencies = [
"craft-gzip",
"craft-vectorcraft-format",
@@ -8805,7 +8805,7 @@ dependencies = [
"thiserror 2.0.21",
"vectorcraft-brush",
"vectorcraft-doc",
"vectorcraft-geom 0.24.1",
"vectorcraft-geom 0.25.0",
"vectorcraft-testkit",
]
@@ -8821,7 +8821,7 @@ dependencies = [
[[package]]
name = "vectorcraft-geom"
version = "0.24.1"
version = "0.25.0"
dependencies = [
"kurbo 0.13.1",
"proptest",
@@ -8832,7 +8832,7 @@ dependencies = [
[[package]]
name = "vectorcraft-js"
version = "0.24.1"
version = "0.25.0"
dependencies = [
"chrono",
"craft-xml",
@@ -8843,7 +8843,7 @@ dependencies = [
[[package]]
name = "vectorcraft-mcp"
version = "0.24.1"
version = "0.25.0"
dependencies = [
"craft",
"craft-image-codecs",
@@ -8855,7 +8855,7 @@ dependencies = [
"vectorcraft-doc",
"vectorcraft-engine",
"vectorcraft-format",
"vectorcraft-geom 0.24.1",
"vectorcraft-geom 0.25.0",
"vectorcraft-render",
"vectorcraft-svg",
"vectorcraft-testkit",
@@ -8864,7 +8864,7 @@ dependencies = [
[[package]]
name = "vectorcraft-metafile"
version = "0.24.1"
version = "0.25.0"
dependencies = [
"craft-image-codecs",
"craft-metafile",
@@ -8874,7 +8874,7 @@ dependencies = [
"vectorcraft-color",
"vectorcraft-doc",
"vectorcraft-effects",
"vectorcraft-geom 0.24.1",
"vectorcraft-geom 0.25.0",
"vectorcraft-text",
]
@@ -8891,19 +8891,19 @@ dependencies = [
[[package]]
name = "vectorcraft-pathops"
version = "0.24.1"
version = "0.25.0"
dependencies = [
"kurbo 0.13.1",
"linesweeper",
"proptest",
"thiserror 2.0.21",
"vectorcraft-geom 0.24.1",
"vectorcraft-geom 0.25.0",
"vectorcraft-testkit",
]
[[package]]
name = "vectorcraft-pdf"
version = "0.24.1"
version = "0.25.0"
dependencies = [
"aes 0.8.4",
"chrono",
@@ -8932,7 +8932,7 @@ dependencies = [
"vectorcraft-color",
"vectorcraft-doc",
"vectorcraft-effects",
"vectorcraft-geom 0.24.1",
"vectorcraft-geom 0.25.0",
"vectorcraft-pdf",
"vectorcraft-testkit",
"vectorcraft-text",
@@ -8940,7 +8940,7 @@ dependencies = [
[[package]]
name = "vectorcraft-plugin-worker"
version = "0.24.1"
version = "0.25.0"
dependencies = [
"js-sys",
"vectorcraft-plugins",
@@ -8950,7 +8950,7 @@ dependencies = [
[[package]]
name = "vectorcraft-plugins"
version = "0.24.1"
version = "0.25.0"
dependencies = [
"craft-image-codecs",
"craft-vectorcraft-format",
@@ -8962,7 +8962,7 @@ dependencies = [
"thiserror 2.0.21",
"vectorcraft-color",
"vectorcraft-doc",
"vectorcraft-geom 0.24.1",
"vectorcraft-geom 0.25.0",
"vectorcraft-js",
"vectorcraft-plugins",
"wasmi",
@@ -8973,7 +8973,7 @@ dependencies = [
[[package]]
name = "vectorcraft-render"
version = "0.24.1"
version = "0.25.0"
dependencies = [
"craft-gif",
"craft-image-codecs",
@@ -8991,7 +8991,7 @@ dependencies = [
"vectorcraft-color",
"vectorcraft-doc",
"vectorcraft-effects",
"vectorcraft-geom 0.24.1",
"vectorcraft-geom 0.25.0",
"vectorcraft-plugins",
"vectorcraft-testkit",
"vectorcraft-text",
@@ -9004,7 +9004,7 @@ dependencies = [
[[package]]
name = "vectorcraft-scriptcheck"
version = "0.24.1"
version = "0.25.0"
dependencies = [
"proptest",
"unicode-properties",
@@ -9012,7 +9012,7 @@ dependencies = [
[[package]]
name = "vectorcraft-svg"
version = "0.24.1"
version = "0.25.0"
dependencies = [
"craft-docpath",
"craft-image-codecs",
@@ -9036,15 +9036,15 @@ dependencies = [
"vectorcraft-color",
"vectorcraft-doc",
"vectorcraft-effects",
"vectorcraft-geom 0.24.1",
"vectorcraft-pathops 0.24.1",
"vectorcraft-geom 0.25.0",
"vectorcraft-pathops 0.25.0",
"vectorcraft-testkit",
"vectorcraft-text",
]
[[package]]
name = "vectorcraft-testkit"
version = "0.24.1"
version = "0.25.0"
dependencies = [
"craft-image-codecs",
"fax",
@@ -9055,14 +9055,14 @@ dependencies = [
"vectorcraft-doc",
"vectorcraft-engine",
"vectorcraft-format",
"vectorcraft-geom 0.24.1",
"vectorcraft-geom 0.25.0",
"vectorcraft-render",
"vectorcraft-svg",
]
[[package]]
name = "vectorcraft-text"
version = "0.24.1"
version = "0.25.0"
dependencies = [
"craft",
"craft-fonts-build",
@@ -9080,23 +9080,23 @@ dependencies = [
"unicode-script",
"unicode-segmentation",
"vectorcraft-doc",
"vectorcraft-geom 0.24.1",
"vectorcraft-geom 0.25.0",
"vello_cpu",
"write-fonts",
]
[[package]]
name = "vectorcraft-three-d"
version = "0.24.1"
version = "0.25.0"
dependencies = [
"proptest",
"vectorcraft-geom 0.24.1",
"vectorcraft-pathops 0.24.1",
"vectorcraft-geom 0.25.0",
"vectorcraft-pathops 0.25.0",
]
[[package]]
name = "vectorcraft-thumbnail-handler"
version = "0.24.1"
version = "0.25.0"
dependencies = [
"png 0.18.1",
"windows",
@@ -9105,7 +9105,7 @@ dependencies = [
[[package]]
name = "vectorcraft-tools"
version = "0.24.1"
version = "0.25.0"
dependencies = [
"craft-image-codecs",
"kurbo 0.13.1",
@@ -9115,15 +9115,15 @@ dependencies = [
"vectorcraft-color",
"vectorcraft-doc",
"vectorcraft-effects",
"vectorcraft-geom 0.24.1",
"vectorcraft-pathops 0.24.1",
"vectorcraft-geom 0.25.0",
"vectorcraft-pathops 0.25.0",
"vectorcraft-text",
"vectorcraft-tools",
]
[[package]]
name = "vectorcraft-trace"
version = "0.24.1"
version = "0.25.0"
dependencies = [
"craft-image-codecs",
"image",
@@ -9131,12 +9131,12 @@ dependencies = [
"serde",
"serde_json",
"thiserror 2.0.21",
"vectorcraft-geom 0.24.1",
"vectorcraft-geom 0.25.0",
]
[[package]]
name = "vectorcraft-ui-egui"
version = "0.24.1"
version = "0.25.0"
dependencies = [
"bytemuck",
"chrono",
@@ -9160,7 +9160,7 @@ dependencies = [
"vectorcraft-engine",
"vectorcraft-eps",
"vectorcraft-format",
"vectorcraft-geom 0.24.1",
"vectorcraft-geom 0.25.0",
"vectorcraft-pdf",
"vectorcraft-plugins",
"vectorcraft-render",
@@ -9175,7 +9175,7 @@ dependencies = [
[[package]]
name = "vectorcraft-web"
version = "0.24.1"
version = "0.25.0"
dependencies = [
"craft",
"craft-web-api",
@@ -10404,7 +10404,7 @@ checksum = "9440ea3e5aeabb0ac63af70daf835274065238cdd0cec83418f417eae38bacee"
[[package]]
name = "xtask"
version = "0.24.1"
version = "0.25.0"
dependencies = [
"serde_json",
]
@@ -10759,18 +10759,3 @@ dependencies = [
"syn 3.0.9",
"winnow",
]
[[patch.unused]]
name = "egui_demo_lib"
version = "0.37.0"
source = "git+https://github.com/storytold/egui.git?rev=14c39fed181756be6f357c284354e0ab55b64443#14c39fed181756be6f357c284354e0ab55b64443"
[[patch.unused]]
name = "egui_inspection"
version = "0.37.0"
source = "git+https://github.com/storytold/egui.git?rev=14c39fed181756be6f357c284354e0ab55b64443#14c39fed181756be6f357c284354e0ab55b64443"
[[patch.unused]]
name = "egui_system_font_provider"
version = "0.37.0"
source = "git+https://github.com/storytold/egui.git?rev=14c39fed181756be6f357c284354e0ab55b64443#14c39fed181756be6f357c284354e0ab55b64443"
+1 -8
View File
@@ -4,11 +4,10 @@ members = ["crates/*", "apps/*", "xtask"]
default-members = ["crates/*", "apps/vectorcraft", "apps/vectorcraft-cli", "xtask"]
[workspace.package]
version = "0.24.1"
version = "0.25.0"
edition = "2024"
license = "MIT OR Apache-2.0"
rust-version = "1.95"
repository = "https://github.com/storytold/vectorcraft"
[workspace.dependencies]
craft-cms = { git = "https://github.com/storytold/craft-libs", rev = "186a229c8da8db5916f8a863dfd894f1879af735" }
@@ -89,7 +88,6 @@ vectorcraft-apischema = { path = "crates/apischema" }
# foundation
kurbo = { version = "0.13", features = ["serde"] }
peniko = "0.6"
thiserror = "2"
serde = { version = "1", features = ["derive", "rc"] }
serde_json = { version = "1", features = ["float_roundtrip"] }
@@ -159,10 +157,8 @@ egui = "0.37"
egui_extras = { version = "0.37", default-features = false, features = ["svg"] }
eframe = { version = "0.37", default-features = false }
egui_kittest = "0.37"
rfd = "0.17"
arboard = { version = "3.6", default-features = false }
clipboard-win = "5.4"
webbrowser = "1"
[workspace.lints.rust]
unsafe_code = "deny"
@@ -213,8 +209,5 @@ egui-wgpu = { git = "https://github.com/storytold/egui.git", rev = "14c39fed1817
egui_glow = { git = "https://github.com/storytold/egui.git", rev = "14c39fed181756be6f357c284354e0ab55b64443" }
egui_extras = { git = "https://github.com/storytold/egui.git", rev = "14c39fed181756be6f357c284354e0ab55b64443" }
egui_kittest = { git = "https://github.com/storytold/egui.git", rev = "14c39fed181756be6f357c284354e0ab55b64443" }
egui_system_font_provider = { git = "https://github.com/storytold/egui.git", rev = "14c39fed181756be6f357c284354e0ab55b64443" }
eframe = { git = "https://github.com/storytold/egui.git", rev = "14c39fed181756be6f357c284354e0ab55b64443" }
egui_demo_lib = { git = "https://github.com/storytold/egui.git", rev = "14c39fed181756be6f357c284354e0ab55b64443" }
egui_inspection = { git = "https://github.com/storytold/egui.git", rev = "14c39fed181756be6f357c284354e0ab55b64443" }
winit = { git = "https://github.com/storytold/winit.git", rev = "a517b3846ee8457d84ee4975110bfda6797c44dc" }
+4
View File
@@ -5,6 +5,10 @@ dist = "../../dist/web"
public_url = "./"
filehash = true
[tools]
# Binaryen 123 crashes while optimizing the release bundle; keep the optimizer explicit.
wasm_opt = "version_133"
[serve]
addresses = ["127.0.0.1"]
port = 8766
+55 -10
View File
@@ -194,6 +194,51 @@ impl Options {
/// Outlines with their layer colours ([`highlights`]).
pub type Outlines = Vec<(BezPath, [u8; 3])>;
/// The outlines [`highlights`] gives the canvas, grouped by layer color. The canvas asks every frame and gets the same
/// allocation back until the outlines are found again.
#[derive(Debug, Default, PartialEq)]
pub struct Highlights {
/// A number given to each set of outlines when it is found, and never to another set: the canvas keeps the lines
/// it stroked for these outlines while the number stays the same.
pub revision: u64,
/// The outlines in each layer color, the colors in the order of their first outline.
pub groups: Vec<([u8; 3], std::sync::Arc<[BezPath]>)>,
}
/// The [`Highlights::revision`] the next set of outlines takes.
static NEXT_HIGHLIGHTS: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(1);
/// [`Highlights`] with no outline, shared so the frames that show none allocate nothing.
static NO_HIGHLIGHTS: std::sync::LazyLock<std::sync::Arc<Highlights>> = std::sync::LazyLock::new(Default::default);
impl Highlights {
/// `outlines` grouped by color, under a new revision.
fn new(outlines: Outlines) -> std::sync::Arc<Self> {
if outlines.is_empty() {
return NO_HIGHLIGHTS.clone();
}
let mut groups: Vec<([u8; 3], Vec<BezPath>)> = vec![];
for (path, color) in outlines {
match groups.iter_mut().find(|(c, _)| *c == color) {
Some((_, paths)) => paths.push(path),
None => groups.push((color, vec![path])),
}
}
let revision = NEXT_HIGHLIGHTS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
std::sync::Arc::new(Highlights { revision, groups: groups.into_iter().map(|(c, paths)| (c, paths.into())).collect() })
}
/// How many outlines there are, in every color.
pub fn len(&self) -> usize {
self.groups.iter().map(|(_, paths)| paths.len()).sum()
}
/// Whether there is no outline.
pub fn is_empty(&self) -> bool {
self.groups.iter().all(|(_, paths)| paths.is_empty())
}
}
/// A Global Edit in progress (per document; not saved, not an undo step).
#[derive(Clone, Debug, PartialEq)]
pub struct GlobalEdit {
@@ -202,7 +247,7 @@ pub struct GlobalEdit {
/// outline onto its own.
pub members: Vec<(NodeId, Affine)>,
/// [`highlights`] as of a document revision: the canvas asks every frame.
outlines: std::cell::RefCell<Option<(u64, Outlines)>>,
outlines: std::cell::RefCell<Option<(u64, std::sync::Arc<Highlights>)>>,
}
/// An outline reduced to its form: the anchors and handles placed in a unit box, with what tells
@@ -1021,15 +1066,15 @@ fn keep_series_changes(before: &Document, d: &mut Document, edited: &[NodeId]) {
/// highlights them while Global Edit is on. While it is off, with one supported object selected,
/// they are the outlines of the objects Start Global Edit would take with the Global Edit Options
/// ([`similar`]).
pub fn highlights(s: &Session) -> Outlines {
let Some(st) = s.active() else { return vec![] };
pub fn highlights(s: &Session) -> std::sync::Arc<Highlights> {
let Some(st) = s.active() else { return NO_HIGHLIGHTS.clone() };
let Some(ge) = &st.global_edit else { return similar(s) };
if let Some((rev, out)) = &*ge.outlines.borrow()
&& *rev == st.revision
{
return out.clone();
}
let out = outlines(st, &ge.members);
let out = Highlights::new(outlines(st, &ge.members));
*ge.outlines.borrow_mut() = Some((st.revision, out.clone()));
out
}
@@ -1046,7 +1091,7 @@ pub struct Similar {
doc: Arc<Document>,
key: NodeId,
isolation: Option<NodeId>,
out: Outlines,
out: Arc<Highlights>,
}
/// Before Global Edit starts: with one supported object selected, the outlines of the other
@@ -1056,11 +1101,11 @@ pub struct Similar {
/// options, as finding them walks the whole document. After an edit that replaced only the
/// selected object, and left what the others are compared with as it was (a move), the outlines
/// found before are kept without a walk.
pub fn similar(s: &Session) -> Outlines {
let Some(st) = s.active() else { return vec![] };
pub fn similar(s: &Session) -> std::sync::Arc<Highlights> {
let Some(st) = s.active() else { return NO_HIGHLIGHTS.clone() };
// Global Edit is refused while an object of a dynamic symbol instance's art is selected.
if st.global_edit.is_some() || st.interaction.is_some() || st.selection.objects.len() != 1 || super::edit::refuse_symbol_part(s).is_err() {
return vec![];
return NO_HIGHLIGHTS.clone();
}
let o = &s.global_edit_options;
let key = st.selection.objects[0];
@@ -1074,10 +1119,10 @@ pub fn similar(s: &Session) -> Outlines {
c.doc = st.doc.clone();
return c.out.clone();
}
let out = match matches(s, o) {
let out = Highlights::new(match matches(s, o) {
Ok(m) if m.len() >= 2 => outlines(st, &m),
_ => vec![],
};
});
*st.similar_outlines.borrow_mut() =
Some(Similar { revision: st.revision, options: o.clone(), doc: st.doc.clone(), key, isolation: st.isolation, out: out.clone() });
out
+49 -13
View File
@@ -150,7 +150,7 @@ fn after_an_edit_only_the_changed_objects_are_compared_again_from_scratch() {
assert_eq!(since(before), (4, 2), "the selected object and the three edited copies, two of them still similar");
assert_eq!(shown.len(), 38, "the widened copy is another shape; the moved and the enlarged ones still match");
let moved = node(&s, copies[1]).stroke_path().unwrap();
assert!(shown.iter().any(|(p, _)| *p == moved), "the moved copy is shown where it is now");
assert!(shown.groups.iter().flat_map(|(_, paths)| paths.iter()).any(|p| *p == moved), "the moved copy is shown where it is now");
s.execute("select.globalEditOptions", &json!({"size": true})).unwrap();
assert_eq!(highlights(&s).len(), 37, "with Size, the enlarged copy is left out");
assert_eq!(crate::cmd::globaledit::match_count(&s), 38);
@@ -166,6 +166,8 @@ fn an_edit_to_the_selected_object_alone_keeps_the_similar_objects_without_a_walk
let out = highlights(s);
(out, walked() - before)
};
// The outlines in each layer color.
let paths = |h: &crate::cmd::globaledit::Highlights| h.groups.iter().map(|(c, p)| (*c, p.to_vec())).collect::<Vec<_>>();
// The outlines a walk finds, the options set again so that nothing is kept.
let fresh = |s: &mut Session| {
let size = s.global_edit_options.size;
@@ -175,7 +177,7 @@ fn an_edit_to_the_selected_object_alone_keeps_the_similar_objects_without_a_walk
let before = walked();
let out = highlights(s);
assert!(walked() > before, "a walk");
out
paths(&out)
};
let mut s = session();
let key = rect(&mut s, 0.37, 0.91, 10.3, 10.3);
@@ -189,8 +191,8 @@ fn an_edit_to_the_selected_object_alone_keeps_the_similar_objects_without_a_walk
s.execute("object.move", &json!({"dx": 3.17, "dy": 1.29})).unwrap();
let (out, n) = shown(&s);
assert_eq!(n, 0, "a move of the selected object alone compares the others as before");
assert_eq!(out, first);
assert_eq!(out, fresh(&mut s));
assert!(std::sync::Arc::ptr_eq(&out, &first), "the canvas keeps the outlines it stroked");
assert_eq!(paths(&out), fresh(&mut s));
// Another object moved: it is shown where it is now.
sel(&mut s, &[copies[0]]);
@@ -199,8 +201,8 @@ fn an_edit_to_the_selected_object_alone_keeps_the_similar_objects_without_a_walk
let (out, n) = shown(&s);
assert!(n > 0, "another object changed");
let moved = node(&s, copies[0]).stroke_path().unwrap();
assert!(out.iter().any(|(p, _)| *p == moved), "the moved copy is shown where it is now");
assert_eq!(out, fresh(&mut s));
assert!(out.groups.iter().flat_map(|(_, p)| p.iter()).any(|p| *p == moved), "the moved copy is shown where it is now");
assert_eq!(paths(&out), fresh(&mut s));
// The selected object took another shape: none of the squares is like it.
s.execute("object.scale", &json!({"sx": 200, "sy": 100})).unwrap();
@@ -331,8 +333,8 @@ fn a_group_selected_inside_a_group_keeps_its_similar_objects_after_a_move() {
sel(s, ids);
NodeId(s.execute("object.group", &json!({})).unwrap()["id"].as_u64().unwrap())
};
// A group of two squares inside an outer group with a third square, and a copy of the outer
// group: the copy is like the outer group, not like the inner one.
// A group of two squares inside an outer group with a third square, and a copy of both: the
// copy's inner group is like the selected inner group.
let a = [rect(&mut s, 0.0, 0.0, 10.0, 10.0), rect(&mut s, 20.0, 0.0, 10.0, 10.0)];
let inner = group(&mut s, &a);
let third = rect(&mut s, 40.0, 0.0, 10.0, 10.0);
@@ -347,11 +349,11 @@ fn a_group_selected_inside_a_group_keeps_its_similar_objects_after_a_move() {
assert!(!first.is_empty());
s.execute("object.move", &json!({"dx": 5, "dy": 0})).unwrap();
let before = walked();
assert_eq!(highlights(&s), first);
assert!(std::sync::Arc::ptr_eq(&highlights(&s), &first));
assert_eq!(walked(), before, "the outer group changed with the selected group only");
s.execute("select.globalEditOptions", &json!({"size": true})).unwrap();
s.execute("select.globalEditOptions", &json!({"size": false})).unwrap();
assert_eq!(highlights(&s), first, "a walk finds the same");
assert_eq!(highlights(&s).groups, first.groups, "a walk finds the same");
assert!(walked() > before);
}
@@ -361,9 +363,7 @@ fn the_canvas_highlights_similar_objects_before_the_start_with_the_selection_too
let [a, b, ..] = squares(&mut s);
let outline = node(&s, b).stroke_path().unwrap();
let shown = |s: &mut Session| {
s.overlays(ViewInfo::default())
.iter()
.any(|o| matches!(o, vectorcraft_tools::Overlay::Path { path, width, .. } if *path == outline && *width == 1.0))
s.overlays(ViewInfo::default()).iter().any(|o| matches!(o, vectorcraft_tools::Overlay::Outlines { paths, .. } if paths.contains(&outline)))
};
sel(&mut s, &[a]);
s.select_tool("selection", ViewInfo::default()).unwrap();
@@ -374,6 +374,42 @@ fn the_canvas_highlights_similar_objects_before_the_start_with_the_selection_too
assert!(shown(&mut s), "while Global Edit is on, with any tool");
}
/// Each frame hands the canvas the kept outlines, one overlay per layer color sharing them, with no copy of a path; the
/// revision changes when the outlines are found again.
#[test]
fn every_frame_shares_the_kept_outlines_instead_of_copying_each_one() {
use std::sync::Arc;
use vectorcraft_tools::Overlay;
let outlines = |s: &mut Session| -> Vec<(Arc<[vectorcraft_geom::BezPath]>, u64)> {
s.overlays(ViewInfo::default())
.into_iter()
.filter_map(|o| if let Overlay::Outlines { paths, revision, .. } = o { Some((paths, revision)) } else { None })
.collect()
};
let mut s = session();
let key = rect(&mut s, 0.0, 0.0, 10.0, 10.0);
for i in 1..200 {
rect(&mut s, 20.0 * f64::from(i % 20), 100.0 + 20.0 * f64::from(i / 20), 10.0, 10.0);
}
sel(&mut s, &[key]);
s.select_tool("selection", ViewInfo::default()).unwrap();
let first = outlines(&mut s);
let [(paths, revision)] = &first[..] else { panic!("one overlay for the one layer color, not one per object: {}", first.len()) };
assert_eq!(paths.len(), 199);
let second = outlines(&mut s);
let [(again, same)] = &second[..] else { panic!("{}", second.len()) };
assert!(Arc::ptr_eq(paths, again), "the next frame gets the same outlines, not a copy");
assert_eq!(same, revision);
s.execute("select.globalEdit", &json!({})).unwrap();
let on = outlines(&mut s);
let [(members, started)] = &on[..] else { panic!("{}", on.len()) };
assert_eq!(members.len(), 199);
assert_ne!(started, revision, "outlines found again take a new revision");
let next = outlines(&mut s);
let [(kept, still)] = &next[..] else { panic!("{}", next.len()) };
assert!(Arc::ptr_eq(members, kept) && still == started, "and are kept from frame to frame while Global Edit is on");
}
#[test]
fn size_and_appearance_options_narrow_the_match() {
let mut s = session();
+6 -3
View File
@@ -1478,9 +1478,12 @@ impl Session {
// Global Edit: the objects edited with the selected one are highlighted; before it starts,
// with the Selection tool, the objects it would take.
let ge_on = self.active().is_some_and(|d| d.global_edit.is_some());
let shown = if ge_on || self.tool.id() == "selection" { crate::cmd::globaledit::highlights(self) } else { vec![] };
for (path, color) in shown {
v.push(Overlay::Path { path, color, width: 1.0, dashed: false });
// One overlay per layer color, sharing the kept outlines.
if ge_on || self.tool.id() == "selection" {
let shown = crate::cmd::globaledit::highlights(self);
for (color, paths) in &shown.groups {
v.push(Overlay::Outlines { paths: paths.clone(), color: *color, revision: shown.revision });
}
}
if let Some((cmd, p)) = deferred_preview {
v.extend(self.deferred_preview_overlays_from_command(&cmd, &p));
+5
View File
@@ -88,6 +88,11 @@ pub enum Overlay {
/// the dash pattern: the pieces of one line, each starting where the one before it ends, dash
/// as the whole line does.
SharedPath { path: std::sync::Arc<BezPath>, color: [u8; 3], width: f32, dash: Option<f64> },
/// Thin solid outlines of many objects in one color (the objects Global Edit takes). Later calls
/// return the same `paths` with the same `revision` for as long as the outlines do not change, and
/// a new `revision` when they do. The host strokes them again only when `revision` or the view
/// changes.
Outlines { paths: std::sync::Arc<[BezPath]>, color: [u8; 3], revision: u64 },
/// A line segment (smart guide, handle line).
Line { a: Point, b: Point, color: [u8; 3], dashed: bool },
/// An anchor square: filled = selected.
+8 -2
View File
@@ -48,7 +48,7 @@ pub(super) fn show(app: &VectorcraftApp, ui: &mut egui::Ui, space: &CanvasSpace,
});
}
/// The framework control `o` stands for, if it is one: a marquee, a settled outline or a distance.
/// The framework control `o` stands for, if it is one: a marquee, a settled outline, a set of outlines or a distance.
fn show_control(ui: &mut egui::Ui, rect: ScreenRect, o: &Overlay) {
match o {
Overlay::Marquee(r) => {
@@ -65,6 +65,11 @@ fn show_control(ui: &mut egui::Ui, rect: ScreenRect, o: &Overlay) {
let outline = if dash.is_some() { SelectionOutline::dashed(Label::Empty, paths) } else { SelectionOutline::solid(Label::Empty, paths) };
outline.color(data(*color)).revision(revision).show_at(ui, rect);
}
Overlay::Outlines { paths, color, revision } => {
// The overlay's revision changes whenever its paths do, so the lines are stroked again only then or when
// the view changes.
SelectionOutline::solid(Label::Empty, paths).color(data(*color)).revision(*revision).show_at(ui, rect);
}
Overlay::Distance { .. } => {
if let Some((measure, color)) = distance_measure(o) {
SmartGuides::new(&[], std::slice::from_ref(&measure)).color(color).show_at(ui, rect);
@@ -180,7 +185,7 @@ impl Component for ToolMarks<'_> {
}
}
/// Paints the marks of `overlays` through `draw` in `view`; the marquees, shared paths and distances are controls
/// Paints the marks of `overlays` through `draw` in `view`; the marquees, shared paths, outlines and distances are controls
/// of their own and paint nothing here.
// PLAN: contract cv.S14 gives `paint(draw, view, overlays, options)`; the pill, ink and ring colours come from the theme, so the style goes too.
fn paint(draw: &Draw<'_>, view: &CanvasView, overlays: &[Overlay], options: &PathOptionsSettings, style: &ToolMarksStyle) {
@@ -244,6 +249,7 @@ fn paint(draw: &Draw<'_>, view: &CanvasView, overlays: &[Overlay], options: &Pat
Overlay::Marquee(_)
| Overlay::SelectionMarquee { .. }
| Overlay::SharedPath { .. }
| Overlay::Outlines { .. }
| Overlay::Distance { .. }
| Overlay::HoverText { .. } => {}
}
+24
View File
@@ -333,6 +333,30 @@ fn a_selection_drag_draws_its_marks_in_the_frame_the_pointer_moves() {
assert!(moved >= 4, "the drag moves the object: {moved} frames");
}
/// With one rectangle selected, the canvas outlines its copies, which Start Global Edit would take, at their corners.
#[test]
fn the_canvas_outlines_the_objects_global_edit_would_take() {
let mut app = drag_app();
let rect = |app: &mut VectorcraftApp, x: f64| {
app.session.execute("shape.rectangle", &json!({"x": x, "y": 100, "width": 40, "height": 30})).unwrap()["id"].as_u64().unwrap()
};
let key = rect(&mut app, 20.0);
let copies = [rect(&mut app, 120.0), rect(&mut app, 220.0)];
app.select_tool("selection");
app.session.execute("select.set", &json!({"ids": [key]})).unwrap();
let ctx = crate::testing::ui_context();
frame(&mut app, &ctx, vec![]);
let xf = app.canvas_view().unwrap();
let points = painted_points(&mut app, &ctx, vec![]);
for id in copies {
let b = app.session.active().unwrap().doc.bounds_of(&[vectorcraft_doc::NodeId(id)], false).unwrap();
for corner in [Point::new(b.x0, b.y0), Point::new(b.x1, b.y1)] {
let at = xf.to_screen(corner);
assert!(points.iter().any(|p| p.distance(at) < 1.0), "copy {id} is outlined at {at:?}");
}
}
}
/// A Pen drag draws the handle it pulls out in the frame the pointer moves: its end at that frame's pointer, and
/// none at the pointer of the frame before.
#[test]
+84 -46
View File
@@ -1,5 +1,5 @@
use super::{ROTATE_VIEW_ANGLES, Ui, VectorcraftApp, json};
use craft::behavior::kurbo::Size;
use craft::behavior::kurbo::{Point, Size};
use craft::behavior::{CanvasView, IconId};
use craft::ui::bars::{Bar, BarKind, StatusMessage, StatusProgress};
use craft::ui::buttons::{Button, IconButton};
@@ -31,7 +31,7 @@ pub fn status_bar(app: &mut VectorcraftApp, ui: &mut Ui) {
let view = app.view();
let rotation = view.map_or(0.0, |v| v.rotation);
let lang = crate::i18n::current();
let canvas_view = app.canvas_view();
let canvas_zoom = app.canvas_view().map(|v| v.zoom);
// PLAN: assumed Artboard::rect has `width()` and `height()`.
let document = st.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 scaling = app.ui_scaling();
@@ -92,21 +92,10 @@ pub fn status_bar(app: &mut VectorcraftApp, ui: &mut Ui) {
};
// PLAN: assumed VectorcraftApp::canvas_view() -> Option<CanvasView> (cv.S4) and the label msgid "Status Bar".
Bar::new(tl!("Status Bar"), BarKind::Status).trailing(readouts).show(ui, |ui, _| {
let navigation = Navigation {
view: canvas_view,
document,
scaling,
print,
shown_zoom,
has_view: view.is_some(),
turned,
degrees,
cur,
revision,
artboards,
lang,
picked: Outbox::new(&mut picks),
};
let zoom =
ZoomControls { zoom: canvas_zoom, document, scaling, print, shown_zoom, has_view: view.is_some(), lang, picked: Outbox::new(&mut picks) };
let _ = MemoView::new("status-bar-zoom", zoom, show_zoom).show(ui);
let navigation = Navigation { has_view: view.is_some(), turned, degrees, cur, revision, artboards, lang, picked: Outbox::new(&mut picks) };
let _ = MemoView::new("status-bar-navigation", navigation, show_navigation).show(ui);
Divider::vertical().show(ui);
// An empty readout shows a dash.
@@ -187,13 +176,12 @@ pub fn status_bar(app: &mut VectorcraftApp, ui: &mut Ui) {
}
}
/// What the status bar's navigation controls read: the Zoom field, the Rotation menu and the artboard navigator. The
/// bar replays them while these hold still and nothing reaches them (`MemoView`), as most frames only move the
/// readouts.
/// What the status bar's Zoom field and Zoom Presets menu read. The bar replays them while these hold still and
/// nothing reaches them (`MemoView`). The canvas view's center is not among them, so a pan replays them.
#[derive(MemoProps)]
struct Navigation<'a> {
/// The canvas view the Zoom field shows and edits.
view: Option<CanvasView>,
struct ZoomControls<'a> {
/// The canvas view's zoom (`CanvasView::zoom`), which the Zoom field shows and edits.
zoom: Option<f64>,
/// The size of the artboard the navigator shows, which the Zoom field fits.
document: Size,
/// UI Scaling, which divides the canvas view's zoom.
@@ -202,6 +190,45 @@ struct Navigation<'a> {
print: Option<f64>,
/// The view's zoom percentage, which the Zoom Presets menu checks.
shown_zoom: Option<f64>,
/// Whether the active document has a view to zoom.
has_view: bool,
#[memo_props(hash = "an interface language: an index into the languages offered")]
lang: crate::i18n::Lang,
/// What the controls chose in the pass.
picked: Outbox<'a, NavigationPick>,
}
/// The Zoom field and the Zoom Presets menu of the status bar, from [`ZoomControls`].
fn show_zoom(p: &mut ZoomControls<'_>, ui: &mut Ui) {
#[cfg(test)]
tests::ZOOM_RUNS.with(|n| n.set(n.get() + 1));
// The field reads only the view's zoom, and the bar reads only the zoom of the view it commits.
let view = p.zoom.map(|zoom| CanvasView::new(egui::Rect::ZERO, Point::ZERO, zoom));
let document = p.document;
let zoom = Field::new(tl!("Zoom"))
.side(SideLabel::new().kind(LabelKind::Hidden))
.show(ui, |ui, _| ZoomField::new(tl!("Zoom"), view, document).scrub(true).status_bar().show(ui));
// The field edits the canvas view, whose zoom is divided by UI Scaling; `view.setZoom` takes the view's zoom.
if let Some(zoom) = zoom.inner {
if let Some(view) = zoom.view.committed() {
let percent = crate::state::zoom_display_percent(crate::state::View::zoom_of_canvas(view, p.scaling), p.print);
p.picked.send(NavigationPick::Zoom(percent));
}
if let Some(invalid) = zoom.invalid_zoom {
p.picked.send(NavigationPick::InvalidZoom(invalid.message(&Env::of(ui))));
}
}
let presets = zoom_presets(p.shown_zoom, p.print);
let open_presets = IconButton::new(IconId::new("chevron_down")).label(tl!("Zoom Presets")).enabled(p.has_view).show(ui);
if let Some(preset) = Menu::new(tl!("Zoom Presets")).values().opened_by(open_presets.response(), Trigger::Press).pick(ui, &presets).picked {
p.picked.send(NavigationPick::Preset(preset));
}
}
/// What the status bar's Rotation menu and artboard navigator read. The bar replays them while these hold still and
/// nothing reaches them (`MemoView`), as most frames only move the readouts, and a pan or a zoom leaves them alone.
#[derive(MemoProps)]
struct Navigation<'a> {
/// Whether the active document has a view to turn.
has_view: bool,
/// The Rotate View preset the view is turned to, else `usize::MAX`.
@@ -234,29 +261,10 @@ enum NavigationPick {
Artboard(serde_json::Value),
}
/// The Zoom field, the Rotation menu and the artboard navigator of the status bar, from [`Navigation`].
/// The Rotation menu and the artboard navigator of the status bar, from [`Navigation`].
fn show_navigation(p: &mut Navigation<'_>, ui: &mut Ui) {
#[cfg(test)]
tests::NAVIGATION_RUNS.with(|n| n.set(n.get() + 1));
let (view, document) = (p.view, p.document);
let zoom = Field::new(tl!("Zoom"))
.side(SideLabel::new().kind(LabelKind::Hidden))
.show(ui, |ui, _| ZoomField::new(tl!("Zoom"), view, document).scrub(true).status_bar().show(ui));
// The field edits the canvas view, whose zoom is divided by UI Scaling; `view.setZoom` takes the view's zoom.
if let Some(zoom) = zoom.inner {
if let Some(view) = zoom.view.committed() {
let percent = crate::state::zoom_display_percent(crate::state::View::zoom_of_canvas(view, p.scaling), p.print);
p.picked.send(NavigationPick::Zoom(percent));
}
if let Some(invalid) = zoom.invalid_zoom {
p.picked.send(NavigationPick::InvalidZoom(invalid.message(&Env::of(ui))));
}
}
let presets = zoom_presets(p.shown_zoom, p.print);
let open_presets = IconButton::new(IconId::new("chevron_down")).label(tl!("Zoom Presets")).enabled(p.has_view).show(ui);
if let Some(preset) = Menu::new(tl!("Zoom Presets")).values().opened_by(open_presets.response(), Trigger::Press).pick(ui, &presets).picked {
p.picked.send(NavigationPick::Preset(preset));
}
let angles: Vec<Entry<usize>> = ROTATE_VIEW_ANGLES.iter().enumerate().map(|(i, (label, _))| Entry::new(i, *label)).collect();
let (turned, angle, has_view) = (p.turned, format!("{}°", p.degrees), p.has_view);
let mut rotate_to = None;
@@ -388,13 +396,15 @@ mod tests {
thread_local! {
/// How many times this thread ran the status bar's navigation controls ([`show_navigation`]).
pub(super) static NAVIGATION_RUNS: std::cell::Cell<u64> = const { std::cell::Cell::new(0) };
/// How many times this thread ran the status bar's Zoom field and Zoom Presets menu ([`show_zoom`]).
pub(super) static ZOOM_RUNS: std::cell::Cell<u64> = const { std::cell::Cell::new(0) };
}
/// Frames that change nothing the navigation controls show replay them instead of laying them out again; a new
/// zoom or a new artboard runs them once, and they show it.
/// Frames that change nothing the zoom and navigation controls show replay them instead of laying them out again;
/// a new zoom or a new artboard runs them once, and they show it.
#[test]
fn idle_frames_replay_the_navigation_controls() {
let runs = || NAVIGATION_RUNS.with(std::cell::Cell::get);
let runs = || ZOOM_RUNS.with(std::cell::Cell::get) + NAVIGATION_RUNS.with(std::cell::Cell::get);
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
app.run("file.new", json!({"width": 300, "height": 200})).unwrap();
app.view_mut().unwrap().rect = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(600.0, 400.0));
@@ -423,6 +433,34 @@ mod tests {
assert!(panel.enabled("Next Artboard") || panel.enabled("Previous Artboard"), "the navigator counts the new artboard");
}
/// Scrolling the view moves its center and nothing the navigation controls show, so frames of a wheel pan replay
/// them; a new zoom runs only the Zoom field and its presets, not the Rotation menu and the artboard navigator.
#[test]
fn wheel_frames_run_only_the_controls_that_show_what_changed() {
let runs = || (ZOOM_RUNS.with(std::cell::Cell::get), NAVIGATION_RUNS.with(std::cell::Cell::get));
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
app.run("file.new", json!({"width": 300, "height": 200})).unwrap();
app.view_mut().unwrap().rect = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(600.0, 400.0));
let mut panel = Panel::new(app, status_bar);
panel.room(egui::vec2(1200.0, 300.0));
panel.frame();
panel.frame();
let before = runs();
for i in 0..10 {
panel.app().view_mut().unwrap().center.y += if i % 2 == 0 { 40.0 } else { -25.0 };
panel.frame();
}
assert_eq!(runs(), before, "a pan runs neither the zoom controls nor the navigation controls");
for i in 0..4 {
panel.app().run("view.setZoom", json!({"zoom": 150 + 25 * i})).unwrap();
panel.frame();
}
let after = runs();
assert!(after.0 > before.0, "a new zoom runs the zoom controls");
assert_eq!(after.1, before.1, "a new zoom does not run the Rotation menu and the artboard navigator");
assert_eq!(panel.value("Zoom").as_deref(), Some("225%"), "the field shows the last zoom");
}
#[test]
fn the_zoom_presets_menu_sets_a_stop_and_fits_the_view() {
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
@@ -1126,15 +1126,7 @@ macro_rules! style_dialog {
}
fn show(&mut self, ui: &mut egui::Ui, stack: &craft::ui::dialog::DialogStack) -> Option<craft::ui::dialog::DialogResult<Self::Result>> {
// A measuring run can end without running the dialog's body and then sets the first tab as the
// shown one. The dialog keeps the tab that was shown before that run.
let measuring = craft::ui::runtime::measure::active(ui.ctx());
let tab = self.inner.tab();
let shown = craft::ui::dialog::StackDialog::show(&mut self.inner, ui, stack);
if measuring && self.inner.tab() != tab {
let _ = craft::ui::dialog::StackDialog::set_json_field(&mut self.inner, ui.ctx(), "tab", serde_json::json!(tab));
}
shown
craft::ui::dialog::StackDialog::show(&mut self.inner, ui, stack)
}
fn key(&self) -> Option<&str> {
@@ -1079,6 +1079,38 @@ fn new_character_style_refuses_size_and_leading_errors_at_ok() {
}
}
/// Character Style Options and New Character Style opened on a tab other than General still show that tab after
/// their first frames, which measure the dialog before its body runs.
#[test]
fn a_style_dialog_opened_on_a_later_tab_keeps_it_through_its_first_frames() {
use egui::{Pos2, RawInput, Rect, vec2};
let mut app = app();
app.run("charStyle.new", json!({"name": "Body", "attrs": {}})).unwrap();
let ctx = app.ui_ctx.clone().unwrap();
let screen = Rect::from_min_size(Pos2::ZERO, vec2(800.0, 500.0));
let mut time = 0.0;
let mut frame = |app: &mut VectorcraftApp| {
time += 0.25;
crate::testing::app_frame(app, &ctx, RawInput { time: Some(time), screen_rect: Some(screen), ..Default::default() });
};
frame(&mut app);
open(&mut app, "Body");
set::<Existing>(&app, "tab", json!("advanced"));
for _ in 0..5 {
frame(&mut app);
}
assert_eq!(fields::<Existing>(&app)["tab"], json!("advanced"), "Character Style Options left Advanced Character Formats");
cancel::<Existing>(&mut app);
app.run("ui.newCharStyle", json!({})).unwrap();
set::<Fresh>(&app, "tab", json!("color"));
for _ in 0..5 {
frame(&mut app);
}
assert_eq!(fields::<Fresh>(&app)["tab"], json!("color"), "New Character Style left Character Color");
}
#[test]
fn invalid_number_keeps_last_valid_preview() {
let mut app = app();
@@ -907,6 +907,34 @@ mod tests {
assert!(st.history.undo.is_empty());
}
/// Document Setup opened on a tab other than General still shows that tab after its first frames, which
/// measure the dialog before its body runs.
#[test]
fn a_later_tab_picked_before_the_first_frame_stays_shown() {
for tab in ["Transparency", "Type", "Color"] {
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()));
app.run("file.new", json!({"width": 200, "height": 200})).unwrap();
let ctx = app.ui_ctx.clone().unwrap();
let screen = Rect::from_min_size(Pos2::ZERO, vec2(1200.0, 900.0));
let mut time = 0.0;
let mut frame = |app: &mut VectorcraftApp| {
time += 0.25;
crate::testing::app_frame(app, &ctx, egui::RawInput { time: Some(time), screen_rect: Some(screen), ..Default::default() });
};
frame(&mut app);
app.run("file.documentSetup", json!({})).unwrap();
set(&app, &ctx, "tab", json!(tab));
for _ in 0..5 {
frame(&mut app);
}
let shown = app.dialogs().unwrap().with(|h| {
use craft::ui::dialog::StackDialog as _;
h.get_by_id::<HostedPropertiesDialog>(id()).and_then(|d| d.json_fields())
});
assert_eq!(shown.map(|f| f["tab"].clone()), Some(json!(tab)), "Document Setup left {tab}");
}
}
#[test]
fn every_tab_draws_and_ok_is_one_undo_step() {
let (mut app, ctx) = setup_open();
@@ -568,6 +568,31 @@ fn save_options_radios_have_no_empty_caption_over_them() {
}
}
/// The All and Range radios start where the artboard check box above them starts, in the control column past the
/// captions, and EPS's Transparent and Opaque radios start where the Preview menu starts.
#[test]
fn save_options_radios_start_in_the_control_column() {
for (picked, check) in [("art.eps", "Use Artboards"), ("art.ai", "Save each artboard to a separate file")] {
let (mut app, _, _) = desktop(picked);
save_as(&mut app, "file.saveAs");
let controls = labelled_controls(&mut app);
let (check, all, range) = (control(&controls, check), control(&controls, "All"), control(&controls, "Range:"));
assert!((all.left() - check.left()).abs() < 1.0, "{picked}: All at {all:?}, the check box at {check:?}");
assert!((range.left() - check.left()).abs() < 1.0, "{picked}: Range at {range:?}, the check box at {check:?}");
if picked == "art.eps" {
let (transparent, opaque) = (control(&controls, "Transparent"), control(&controls, "Opaque"));
let preview = controls
.iter()
.filter(|(l, r)| l.trim_end_matches(':') == "Preview" && r.bottom() <= transparent.top())
.map(|(_, r)| *r)
.max_by(|a, b| a.bottom().total_cmp(&b.bottom()))
.expect("the Preview menu above Transparent");
assert!((transparent.left() - preview.left()).abs() < 1.0, "Transparent at {transparent:?}, Preview at {preview:?}");
assert!((opaque.left() - preview.left()).abs() < 1.0, "Opaque at {opaque:?}, Preview at {preview:?}");
}
}
}
#[test]
fn a_native_save_options_draft_cannot_redirect_its_path_to_another_drawing() {
let (mut app, written, _) = desktop("original.vectorcraft");
+19
View File
@@ -245,3 +245,22 @@ fn ime_delete_surrounding_then_commit_edit_the_type_tool_once_in_order() {
ime_frame(&mut app, &ctx, vec![Event::Ime(egui::ImeEvent::Commit("Q".into()))], |_| {});
assert_eq!(plain(&app, id), "abcQZ");
}
/// While the Type tool edits text, each idle frame and each typing frame runs its UI once: the text part measures the
/// same in the measuring run and the real run, so no frame is discarded and run again.
#[test]
fn an_edit_runs_each_idle_and_typing_frame_once() {
let (mut app, id) = app_with_text("abc");
let ctx = crate::testing::ui_context();
ime_frame(&mut app, &ctx, vec![], |_| {});
ime_frame(&mut app, &ctx, vec![], |_| {});
begin_typing(&mut app, &ctx, id);
for _ in 0..3 {
ime_frame(&mut app, &ctx, vec![], |_| {});
}
let idle: Vec<usize> = (0..6).map(|_| run_frame(&mut app, &ctx, vec![], |_| {}, false).0).collect();
assert_eq!(idle, [1; 6], "each idle frame of the edit runs one pass");
let typing: Vec<usize> = (0..6).map(|_| run_frame(&mut app, &ctx, vec![Event::Text("x".into())], |_| {}, false).0).collect();
assert_eq!(typing, [1; 6], "each typing frame runs one pass");
assert!(plain(&app, id).contains("xxxxxx"), "every frame's typing reached the text");
}
+6 -2
View File
@@ -456,6 +456,10 @@ fn show_rail(app: &mut VectorcraftApp, ui: &mut Ui, owner: Owner, at: GroupAt, m
if app.session.prefs.tool_group_labels {
rail = rail.captions();
}
// The Tools panel's controls under the tools scroll with them, so a short window shows more tools.
if tools_panel {
rail = rail.footer_scrolls();
}
if own_bar {
rail = rail.tear_off().edit_toolbar(tl!("Edit Toolbar"));
}
@@ -768,8 +772,8 @@ fn quad_bounds(quad: &[Point; 4]) -> vectorcraft_geom::Rect {
/// The Fill/Stroke proxy, Color/Gradient/None, the drawing modes and screen mode under the rail's
/// tools: in two columns the three drawing modes show, in one only the current one, which cycles
/// them. A row the rail is too narrow for goes on in the next line. The All Tools drawer's Show
/// section hides any of them. The rail's footer region draws the rule that parts them from the tools, which scroll
/// above it in a short rail.
/// section hides any of them. The rail draws the rule that parts them from the tools, and they scroll with the tools
/// in a short rail.
fn bottom_controls(app: &mut VectorcraftApp, ui: &mut Ui, footer: RailFooter) {
let two = footer.columns > 1;
let show = app.ui.toolbar_show;
+44 -5
View File
@@ -282,17 +282,18 @@ fn polygon_and_star_canvas_counts_persist_without_new_toolbar_dialogs() {
/// The paint chips, drawing modes and the rest of the footer lie inside the rail at one and at two columns (one column
/// shows the current drawing mode alone), and in two columns the three drawing modes sit side by side, each setting
/// its mode (#1129).
/// its mode (#1129). The window is tall enough for every tool and the controls under them, which scroll with the tools.
#[test]
fn the_paint_and_drawing_mode_buttons_fit_the_toolbar_width() {
let mut app = app_with(200, 200);
let ctx = reader();
let height = 2000.0;
let footer =
["Color (, or Shift+,)", "Gradient (. or Shift+.)", "None (/)", "Draw Normal (Shift+D)", "Draw Behind (Shift+D)", "Draw Inside (Shift+D)"];
let mut nodes = vec![];
for (k, double) in [false, true].into_iter().enumerate() {
app.run("window.toolbarColumns", json!({ "double": double })).unwrap();
nodes = settled(&mut app, &ctx, k as f64 * 10.0, 900.0);
nodes = settled(&mut app, &ctx, k as f64 * 10.0, height);
// The rail itself, not its dock grip, which is named for the pane too.
let rail = nodes.iter().find(|n| n.role() == Role::Toolbar && n.label() == Some("Tools")).and_then(bounds).expect("the rail is drawn");
for label in &footer[..if double { 6 } else { 4 }] {
@@ -302,13 +303,12 @@ fn the_paint_and_drawing_mode_buttons_fit_the_toolbar_width() {
}
let modes = ["Draw Normal (Shift+D)", "Draw Behind (Shift+D)", "Draw Inside (Shift+D)"].map(|label| named_rect(&nodes, label));
assert!(modes.iter().all(|r| (r.top() - modes[0].top()).abs() < 0.5), "side by side: {modes:?}");
click(&mut app, &ctx, 20.0, modes[1].center(), 900.0);
click(&mut app, &ctx, 20.0, modes[1].center(), height);
assert_eq!(app.session.draw_mode, vectorcraft_engine::DrawMode::Behind);
}
/// In one column the Color, Gradient and None chips share one line, and one rule across the rail parts the controls
/// under the tools from the tools, which scroll above them in a short rail: it lies between the last tool and Fill and
/// Stroke, and no second rule doubles it.
/// under the tools from the tools: it lies between the last tool and Fill and Stroke, and no second rule doubles it.
#[test]
fn the_controls_under_the_tools_share_a_line_under_a_rule() {
let mut app = app_with(200, 200);
@@ -607,3 +607,42 @@ fn a_short_tools_rail_shows_its_scroll_bar_at_rest() {
assert!(bars(&mut app, 0.0, 400.0) > 0, "a short rail shows its scroll bar with the pointer away");
assert_eq!(bars(&mut app, 10.0, 2000.0), 0, "a rail with room for every tool shows no scroll bar");
}
/// In a window too short for the Tools panel, the controls under the tools scroll with them: the tool buttons fill
/// the rail down to its bottom edge, Fill and Stroke starts out of view under them, and scrolling to the end brings
/// Fill and Stroke into view under the last tool.
#[test]
fn the_tools_panel_controls_scroll_with_the_tools_in_a_short_window() {
let mut app = app_with(200, 200);
let ctx = reader();
app.run("window.toolbarColumns", json!({ "double": false })).unwrap();
let height = 560.0;
let nodes = settled(&mut app, &ctx, 0.0, height);
let rail = nodes.iter().find(|n| n.role() == Role::Toolbar && n.label() == Some("Tools")).and_then(bounds).expect("the rail is drawn");
let tools = cells(&app, &nodes);
let in_view: Vec<&egui::Rect> = tools.iter().filter(|r| r.bottom() <= rail.bottom() + 0.5).collect();
assert!(in_view.len() < tools.len(), "the window is too short for every tool: {} of {}", in_view.len(), tools.len());
let pitch = tools[1].top() - tools[0].top();
let lowest = in_view.iter().map(|r| r.bottom()).fold(f32::MIN, f32::max);
let bottom = rail.bottom();
assert!(bottom - lowest < pitch, "the tools fill the rail to its bottom: the last in view ends at {lowest}, the rail at {bottom}");
let proxy = named_rect(&nodes, "Fill and Stroke");
assert!(proxy.top() >= rail.bottom() - 0.5, "Fill and Stroke starts out of view: {proxy:?} under {rail:?}");
let wheel = Event::MouseWheel {
unit: egui::MouseWheelUnit::Point,
delta: egui::vec2(0.0, -400.0),
modifiers: Default::default(),
phase: egui::TouchPhase::Move,
source: egui::MouseWheelSource::Unknown,
};
let over = tools[0].center();
for k in 0..10 {
frame(&mut app, &ctx, 1.0 + f64::from(k) * 0.05, vec![Event::PointerMoved(over), wheel.clone()], height);
}
let nodes = settled(&mut app, &ctx, 2.0, height);
let proxy = named_rect(&nodes, "Fill and Stroke");
let last = cells(&app, &nodes).into_iter().max_by(|a, b| a.bottom().total_cmp(&b.bottom())).expect("the rail shows tools");
assert!(proxy.bottom() <= rail.bottom() + 0.5, "Fill and Stroke is in view after scrolling: {proxy:?} in {rail:?}");
assert!(last.bottom() <= proxy.top(), "the last tool {last:?} stands above Fill and Stroke {proxy:?}");
}
+3 -3
View File
@@ -486,7 +486,8 @@ impl Component for TypeEditor<'_> {
}
/// Shows the editor part over the Type tool's caret while the tool edits text, before the tool host; returns the part's
/// id. A new edit target is a new IME owner, so a reloaded document interrupts its composition.
/// id. A new edit target is a new IME owner, so a reloaded document interrupts its composition. The part is shown at
/// the caret's rect and takes no room in the canvas's flow, as the canvas's other overlays are.
pub(crate) fn show(app: &mut VectorcraftApp, ui: &mut egui::Ui) -> Option<egui::Id> {
if !app.session.tool_wants_text() || app.viewport_hidden(ui.ctx()) {
return None;
@@ -496,8 +497,7 @@ pub(crate) fn show(app: &mut VectorcraftApp, ui: &mut egui::Ui) -> Option<egui::
let target = app.session.tool_ime_target(view)?;
let canvas_view = app.canvas_view()?;
let caret = Rect::from_two_pos(canvas_view.to_screen(a), canvas_view.to_screen(b)).expand2(egui::vec2(1.0, 0.0));
let out =
ui.scope_builder(egui::UiBuilder::new().max_rect(caret), |ui| TypeEditor::new(app, caret, ui.ctx().clone()).id_salt(target).show(ui)).inner;
let out = TypeEditor::new(app, caret, ui.ctx().clone()).id_salt(target).show_at(ui, caret);
// Typing goes to the edit that starts, as a click on the part would take the keys.
if out.unfocused_start {
focus::request(ui.ctx(), FocusTarget::Id(out.response.id));