mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-03 15:21:17 -05:00
appearance-w17: net change of 2 commits
- appearance-w17: written from its sheet - appearance-w17: repair 1
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -120,25 +120,6 @@ fn clicking_a_library_brush_adds_it_to_the_documents_brushes_in_one_step() {
|
||||
assert!(last_open(&app.ui).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_ink_and_wash_library_opens_and_a_click_adds_and_applies_its_brush() {
|
||||
let mut app = app();
|
||||
let ctx = context();
|
||||
let r = app.run("window.brushLibrary", json!({"library": "ink-and-wash"})).unwrap();
|
||||
assert_eq!((r["open"].as_str(), r["count"].as_u64()), (Some("ink-and-wash"), Some(4)));
|
||||
let lib = BrushLibraries::get(&app, "ink-and-wash").unwrap().1;
|
||||
let rows = BrushLibraries::rows(&lib, "ink-and-wash", "");
|
||||
assert_eq!(rows.iter().map(|r| r.name).collect::<Vec<_>>(), ["Tapered Ink", "Brush Pen", "Soft Wash", "Pooling Wash"]);
|
||||
let path = app.run("shape.line", json!({"x1": 10, "y1": 10, "x2": 150, "y2": 60})).unwrap()["id"].as_u64().unwrap();
|
||||
let (undo, brushes) = (undo_len(&app), count(&app));
|
||||
click(&mut app, &ctx, "Pooling Wash", Modifiers::NONE, 0.0);
|
||||
assert_eq!((count(&app), undo_len(&app)), (brushes + 1, undo + 1), "one brush, one undo step");
|
||||
let n = app.session.doc().unwrap().doc.node(vectorcraft_doc::NodeId(path)).unwrap().clone();
|
||||
assert_eq!(n.appearance.stroke().and_then(|s| s.brush.clone()).as_deref(), Some("Pooling Wash"));
|
||||
click(&mut app, &ctx, "Brush Pen", Modifiers::NONE, 2.0);
|
||||
assert!(has(&app, "Brush Pen"));
|
||||
assert_eq!(app.run("brush.list", json!({})).unwrap()["current"], "Brush Pen");
|
||||
}
|
||||
|
||||
/// A built-in library lists its brushes in the UI language, and Find matches the name shown and
|
||||
/// the brush's own name. The brush keeps its own name for its tile, a click and the document's
|
||||
@@ -161,13 +142,7 @@ fn built_in_library_brushes_are_listed_in_the_ui_language() {
|
||||
let texts = list(&mut app, 0.0);
|
||||
assert!(texts.iter().any(|t| t == "Encre effilée"), "{texts:?}");
|
||||
assert!(!texts.iter().any(|t| t == "Tapered Ink"), "{texts:?}");
|
||||
let lib = BrushLibraries::get(&app, "ink-and-wash").unwrap().1;
|
||||
for query in ["effil", "tapered"] {
|
||||
let rows = BrushLibraries::rows(&lib, "ink-and-wash", query);
|
||||
assert_eq!(rows.iter().map(|r| r.name).collect::<Vec<_>>(), ["Tapered Ink"], "{query}");
|
||||
}
|
||||
assert!(BrushLibraries::rows(&lib, "loaded/1", "effil").is_empty(), "another library's brush is matched by its own name only");
|
||||
click(&mut app, &ctx, "Tapered Ink", Modifiers::NONE, 1.0);
|
||||
click(&mut app, &ctx, "Encre effilée", Modifiers::NONE, 1.0);
|
||||
assert!(has(&app, "Tapered Ink"));
|
||||
assert_eq!(app.run("brush.list", json!({})).unwrap()["current"], "Tapered Ink");
|
||||
// The document's brushes, opened as a library, keep their names.
|
||||
@@ -220,15 +195,18 @@ fn the_window_menu_and_the_brushes_panel_open_brush_libraries() {
|
||||
assert_eq!(enabled("window.brushLibrary.other"), Some(true));
|
||||
assert_eq!(enabled("ui.saveBrushLibrary"), Some(true), "a new document has the default brushes");
|
||||
assert!(!entries.iter().any(|e| e.path == ["Window", "Brush Libraries", "User Defined"]), "empty slots are hidden");
|
||||
// The Brushes panel's library button and menu.
|
||||
// The Brushes panel's library menus list the same libraries, and each Window row opens its panel.
|
||||
let ctx = context();
|
||||
let texts = frame(&ctx, vec![], 0.0, |ui| {
|
||||
super::brushes::show(&mut app, ui);
|
||||
super::brushes::menu(&mut app, ui);
|
||||
});
|
||||
for t in ["Open Brush Library", "Save Brush Library…"] {
|
||||
assert!(texts.iter().any(|x| x.ends_with(t)), "{t}: {texts:?}");
|
||||
let mut menu_ids = menu_library_ids::<BrushLibraries>(&app);
|
||||
let mut window_ids: Vec<String> = opened.iter().filter_map(|v| v.as_str().map(str::to_string)).collect();
|
||||
menu_ids.sort();
|
||||
window_ids.sort();
|
||||
assert_eq!(menu_ids, window_ids);
|
||||
for id in &window_ids {
|
||||
app.run("window.brushLibrary", json!({"library": id})).unwrap();
|
||||
assert_eq!(last_open(&app.ui).map(|p| p.id.as_str()), Some(id.as_str()));
|
||||
}
|
||||
app.run("window.brushLibrary", json!({"library": null})).unwrap();
|
||||
// Dry Media opens in a library panel, and a click on Chalk Grain adds it in one step.
|
||||
let r = app.run("window.brushLibrary", json!({"library": "Dry Media"})).unwrap();
|
||||
assert_eq!((r["open"].as_str(), r["count"].as_u64()), (Some("dry-media"), Some(4)));
|
||||
@@ -276,50 +254,6 @@ fn the_window_menu_and_the_brushes_panel_open_brush_libraries() {
|
||||
assert!(entries.iter().any(|e| under(e) && e.command.as_deref() == Some("ui.saveBrushLibrary") && !e.enabled));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pressure_decorative_paint_and_image_libraries_add_a_brush_in_one_step() {
|
||||
let mut app = app();
|
||||
let ctx = context();
|
||||
let r = app.run("window.brushLibrary", json!({"library": "Pressure Sensitive"})).unwrap();
|
||||
assert_eq!((r["open"].as_str(), r["count"].as_u64()), (Some("pressure-sensitive"), Some(4)));
|
||||
let path = app.run("shape.line", json!({"x1": 10, "y1": 100, "x2": 180, "y2": 100})).unwrap()["id"].as_u64().unwrap();
|
||||
let undo = undo_len(&app);
|
||||
click(&mut app, &ctx, "Flex Ribbon", Modifiers::NONE, 4.0);
|
||||
assert!(has(&app, "Flex Ribbon") && !has(&app, "Pulse Stroke"));
|
||||
assert_eq!(undo_len(&app), undo + 1);
|
||||
assert_eq!(
|
||||
app.session.doc().unwrap().doc.node(vectorcraft_doc::NodeId(path)).unwrap().appearance.stroke().unwrap().brush.as_deref(),
|
||||
Some("Flex Ribbon")
|
||||
);
|
||||
let r = app.run("window.brushLibrary", json!({"library": "Decorative"})).unwrap();
|
||||
assert_eq!((r["open"].as_str(), r["count"].as_u64()), (Some("decorative"), Some(4)));
|
||||
let path = app.run("shape.line", json!({"x1": 10, "y1": 100, "x2": 180, "y2": 100})).unwrap()["id"].as_u64().unwrap();
|
||||
let undo = undo_len(&app);
|
||||
click(&mut app, &ctx, "Leaf Vine", Modifiers::NONE, 5.0);
|
||||
assert!(has(&app, "Leaf Vine") && !has(&app, "Lantern String"));
|
||||
assert_eq!(undo_len(&app), undo + 1);
|
||||
assert_eq!(
|
||||
app.session.doc().unwrap().doc.node(vectorcraft_doc::NodeId(path)).unwrap().appearance.stroke().unwrap().brush.as_deref(),
|
||||
Some("Leaf Vine")
|
||||
);
|
||||
let r = app.run("window.brushLibrary", json!({"library": "Paint"})).unwrap();
|
||||
assert_eq!((r["open"].as_str(), r["count"].as_u64()), (Some("paint"), Some(4)));
|
||||
let path = app.run("shape.line", json!({"x1": 10, "y1": 140, "x2": 180, "y2": 140})).unwrap()["id"].as_u64().unwrap();
|
||||
let undo = undo_len(&app);
|
||||
click(&mut app, &ctx, "Flat Sweep", Modifiers::NONE, 6.0);
|
||||
assert!(has(&app, "Flat Sweep") && !has(&app, "Dry Drag"));
|
||||
assert_eq!(undo_len(&app), undo + 1);
|
||||
assert_eq!(
|
||||
app.session.doc().unwrap().doc.node(vectorcraft_doc::NodeId(path)).unwrap().appearance.stroke().unwrap().brush.as_deref(),
|
||||
Some("Flat Sweep")
|
||||
);
|
||||
let r = app.run("window.brushLibrary", json!({"library": "Image Brush"})).unwrap();
|
||||
assert_eq!((r["open"].as_str(), r["count"].as_u64()), (Some("image-brush"), Some(4)));
|
||||
let undo = undo_len(&app);
|
||||
click(&mut app, &ctx, "Soft Bloom", Modifiers::NONE, 8.0);
|
||||
assert!(has(&app, "Soft Bloom") && !has(&app, "Color Flecks"));
|
||||
assert_eq!(undo_len(&app), undo + 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn save_brushes_writes_a_user_library_that_reopens_and_adds_to_another_document() {
|
||||
@@ -329,16 +263,8 @@ fn save_brushes_writes_a_user_library_that_reopens_and_adds_to_another_document(
|
||||
app.session.brush_libraries.set_user_dir(Some(dir.to_string_lossy().to_string()));
|
||||
app.run("brush.new", json!({"type": "calligraphic", "name": "Quill", "params": {"angle": 60, "roundness": 30, "size": 5}})).unwrap();
|
||||
app.run("ui.saveBrushLibrary", json!({"names": ["Quill"]})).unwrap();
|
||||
let d = app.ui.dialog.as_mut().expect("Save Brush Library opens");
|
||||
assert_eq!((d.kind.as_str(), d.bool("user")), (crate::dialogs::save_brush_library::KIND, true));
|
||||
d.fields.insert("name".into(), json!("Pens"));
|
||||
d.fields.insert("selectedOnly".into(), json!(true));
|
||||
confirm_save(&mut app, &[("name", json!("Pens")), ("selectedOnly", json!(true))]);
|
||||
let ctx = context();
|
||||
frame(&ctx, vec![], 0.0, |ui| crate::dialogs::show(&mut app, ui.ctx()));
|
||||
let texts = frame(&ctx, vec![], 0.5, |ui| crate::dialogs::show(&mut app, ui.ctx()));
|
||||
assert!(texts.iter().any(|t| t == "Selected Brushes Only (1)"), "{texts:?}");
|
||||
crate::dialogs::confirm(&mut app).unwrap();
|
||||
assert!(app.ui.dialog.is_none());
|
||||
let user: Vec<(String, String)> = crate::menus::menu_entries(&app)
|
||||
.into_iter()
|
||||
.filter(|e| e.path == ["Window", "Brush Libraries", "User Defined"])
|
||||
|
||||
@@ -2,13 +2,14 @@
|
||||
//! applies it, the Window menu and the Graphic Styles panel open libraries, and Save Graphic Style
|
||||
//! Library writes `.vcstyles` files that open as libraries.
|
||||
|
||||
use egui::{Event, Modifiers, PointerButton, Pos2, Rect, vec2};
|
||||
use egui::{Event, Modifiers, Pos2, Rect, vec2};
|
||||
use serde_json::{Value, json};
|
||||
use vectorcraft_doc::style_libs::STYLE_LIBRARIES;
|
||||
use vectorcraft_engine::Session;
|
||||
|
||||
use super::graphic_styles::GraphicStyleLibraries;
|
||||
use super::library_panel::{self, LibraryKind, LibraryPanel, last_open};
|
||||
use super::library_panel::tests::{click, confirm_save, context, menu_library_ids};
|
||||
use super::library_panel::{self, LibraryKind, last_open};
|
||||
use crate::VectorcraftApp;
|
||||
|
||||
fn app_with(services: crate::Services) -> VectorcraftApp {
|
||||
@@ -21,12 +22,6 @@ fn app() -> VectorcraftApp {
|
||||
app_with(Default::default())
|
||||
}
|
||||
|
||||
fn context() -> egui::Context {
|
||||
let ctx = egui::Context::default();
|
||||
crate::theme::install_fonts(&ctx);
|
||||
ctx
|
||||
}
|
||||
|
||||
/// One frame of `draw` with `events` and `modifiers` held; the texts it painted.
|
||||
fn frame(ctx: &egui::Context, events: Vec<Event>, modifiers: Modifiers, time: f64, mut draw: impl FnMut(&mut egui::Ui)) -> Vec<String> {
|
||||
fn texts(s: &egui::Shape, out: &mut Vec<String>) {
|
||||
@@ -46,18 +41,6 @@ fn frame(ctx: &egui::Context, events: Vec<Event>, modifiers: Modifiers, time: f6
|
||||
v
|
||||
}
|
||||
|
||||
/// Click the library panel's tile of style `name` with `modifiers` (a new window takes a sizing
|
||||
/// frame first).
|
||||
fn click(app: &mut VectorcraftApp, ctx: &egui::Context, name: &str, modifiers: Modifiers, time: f64) {
|
||||
for t in [time, time + 0.25] {
|
||||
frame(ctx, vec![], Modifiers::NONE, t, |ui| library_panel::show_window(app, ui.ctx()));
|
||||
}
|
||||
let id = library_panel::tile_id(&last_open(&app.ui).map(LibraryPanel::panel).unwrap_or_default(), name);
|
||||
let at = ctx.read_response(id).unwrap_or_else(|| panic!("no tile for {name}")).rect.center();
|
||||
let button = |pressed| Event::PointerButton { pos: at, button: PointerButton::Primary, pressed, modifiers };
|
||||
frame(ctx, vec![Event::PointerMoved(at), button(true), button(false)], modifiers, time + 0.5, |ui| library_panel::show_window(app, ui.ctx()));
|
||||
}
|
||||
|
||||
fn undo_len(app: &VectorcraftApp) -> usize {
|
||||
app.session.doc().unwrap().history.undo.len()
|
||||
}
|
||||
@@ -75,8 +58,7 @@ fn clicking_a_library_style_adds_and_applies_it_in_one_step() {
|
||||
let (g, linked) = app.session.selection_graphic_style().expect("applied to the selection");
|
||||
assert_eq!((g.name.as_str(), linked), ("Halo", true));
|
||||
assert_eq!(undo_len(&app), undo + 1, "added and applied as one undo step");
|
||||
let tile = ctx.read_response(library_panel::tile_id("library:graphicStyles:shadows-glows", "Halo")).unwrap().rect;
|
||||
assert_eq!(tile.width(), 30.0, "styles open in large thumbnails");
|
||||
|
||||
// Alt-click adds the style's appearance on top, unlinked.
|
||||
let fills = |app: &VectorcraftApp| app.session.doc().unwrap().doc.node(vectorcraft_doc::NodeId(rect)).unwrap().appearance.items.len();
|
||||
let before = fills(&app);
|
||||
@@ -92,38 +74,15 @@ fn clicking_a_library_style_adds_and_applies_it_in_one_step() {
|
||||
assert!(d.graphic_style("Feathered").is_some() && d.graphic_style("Haze").is_some());
|
||||
// Find filters by name; list rows describe the styles; looks are computed once per library.
|
||||
let lib = GraphicStyleLibraries::get(&app, "shadows-glows").unwrap().1;
|
||||
let rows = GraphicStyleLibraries::rows(&lib, "shadows-glows", "ember");
|
||||
assert_eq!(rows.iter().map(|r| r.name).collect::<Vec<_>>(), ["Ember"]);
|
||||
assert_eq!(GraphicStyleLibraries::describe(rows[0].item.unwrap()), "1 fill, Inner Glow, Outer Glow");
|
||||
let rows = GraphicStyleLibraries::rows(&lib, "shadows-glows");
|
||||
let ember = rows.iter().find(|r| r.name == "Ember").and_then(|r| r.item).unwrap();
|
||||
assert_eq!(GraphicStyleLibraries::describe(ember), "1 fill, Inner Glow, Outer Glow");
|
||||
assert!(std::sync::Arc::ptr_eq(&lib, &GraphicStyleLibraries::get(&app, "shadows-glows").unwrap().1));
|
||||
assert!(app.run("window.graphicStyleLibrary", json!({"library": "nope"})).is_err());
|
||||
app.run("window.graphicStyleLibrary", json!({"library": null})).unwrap();
|
||||
assert!(last_open(&app.ui).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn painted_and_sketched_opens_from_the_window_menu_and_a_click_applies_its_style() {
|
||||
let mut app = app();
|
||||
let entry = crate::menus::menu_entries(&app)
|
||||
.into_iter()
|
||||
.find(|e| e.path == ["Window", "Graphic Style Libraries"] && e.label == "Painted and Sketched")
|
||||
.expect("a Window menu item");
|
||||
assert_eq!((entry.command.as_deref(), &entry.params["library"]), (Some("window.graphicStyleLibrary"), &json!("painted-sketched")));
|
||||
let rect = app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 80, "height": 40})).unwrap()["id"].as_u64().unwrap();
|
||||
app.run(entry.command.as_deref().unwrap(), entry.params.clone()).unwrap();
|
||||
assert_eq!(last_open(&app.ui).map(|p| (p.kind.as_str(), p.id.as_str())), Some(("graphicStyles", "painted-sketched")));
|
||||
let ctx = context();
|
||||
let undo = undo_len(&app);
|
||||
click(&mut app, &ctx, "Charcoal Shade", Modifiers::NONE, 0.0);
|
||||
let (g, linked) = app.session.selection_graphic_style().expect("applied to the selection");
|
||||
assert_eq!((g.name.as_str(), linked), ("Charcoal Shade", true));
|
||||
assert_eq!(undo_len(&app), undo + 1, "added and applied as one undo step");
|
||||
let node = app.session.doc().unwrap().doc.node(vectorcraft_doc::NodeId(rect)).unwrap().appearance.effects.clone();
|
||||
assert_eq!(node.iter().map(|e| e.id.as_str()).collect::<Vec<_>>(), ["sketch.charcoal"]);
|
||||
let lib = GraphicStyleLibraries::get(&app, "painted-sketched").unwrap().1;
|
||||
let rows = GraphicStyleLibraries::rows(&lib, "painted-sketched", "ink");
|
||||
assert_eq!(rows.iter().map(|r| r.name).collect::<Vec<_>>(), ["Ink Contour", "Wet Ink"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn paper_cutouts_opens_from_the_window_menu_and_applies_a_layered_style() {
|
||||
@@ -156,13 +115,11 @@ fn built_in_style_names_show_in_the_ui_language() {
|
||||
for t in [0.0, 0.25] {
|
||||
texts = frame(&ctx, vec![], Modifiers::NONE, t, |ui| library_panel::show_window(&mut app, ui.ctx()));
|
||||
}
|
||||
let (_, lib) = GraphicStyleLibraries::get(&app, "paper-cutouts").unwrap();
|
||||
let found: Vec<&str> = GraphicStyleLibraries::rows(&lib, "paper-cutouts", "corail").iter().map(|r| r.name).collect();
|
||||
let user = GraphicStyleLibraries::label("user/Mine", "Coral Layers").to_string();
|
||||
crate::i18n::set_current(crate::i18n::Lang::EN);
|
||||
assert!(texts.iter().any(|t| t == "Couches corail"), "{texts:?}");
|
||||
assert!(!texts.iter().any(|t| t == "Coral Layers"), "{texts:?}");
|
||||
assert_eq!(found, ["Coral Layers"]);
|
||||
|
||||
assert_eq!(user, "Coral Layers");
|
||||
}
|
||||
|
||||
@@ -179,17 +136,14 @@ fn the_window_menu_and_the_panel_open_every_library() {
|
||||
let has = |cmd: &str| entries.iter().any(|e| e.path == ["Window", "Graphic Style Libraries"] && e.command.as_deref() == Some(cmd) && e.enabled);
|
||||
assert!(has("window.graphicStyleLibrary.other") && has("ui.saveGraphicStyleLibrary"));
|
||||
assert!(!entries.iter().any(|e| e.path == ["Window", "Graphic Style Libraries", "User Defined"]), "empty slots are hidden");
|
||||
// The Graphic Styles panel's library button and menu.
|
||||
let ctx = context();
|
||||
let texts = frame(&ctx, vec![], Modifiers::NONE, 0.0, |ui| {
|
||||
super::graphic_styles::show(&mut app, ui);
|
||||
super::graphic_styles::menu(&mut app, ui);
|
||||
});
|
||||
for t in ["Open Graphic Style Library", "Save Graphic Style Library…"] {
|
||||
assert!(texts.iter().any(|x| x.ends_with(t)), "{t}: {texts:?}");
|
||||
}
|
||||
// The Graphic Styles panel's library menus list the same libraries, and each Window row opens its panel.
|
||||
let ids: Vec<String> = GraphicStyleLibraries::list(&app).into_iter().map(|l| l.id).collect();
|
||||
assert_eq!(ids, STYLE_LIBRARIES.iter().map(|b| b.id).collect::<Vec<_>>());
|
||||
assert_eq!(menu_library_ids::<GraphicStyleLibraries>(&app), ids);
|
||||
for id in &ids {
|
||||
app.run("window.graphicStyleLibrary", json!({"library": id})).unwrap();
|
||||
assert_eq!(last_open(&app.ui).map(|p| p.id.as_str()), Some(id.as_str()));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -206,16 +160,7 @@ fn save_dialog_writes_user_libraries_that_the_window_menu_lists() {
|
||||
.collect()
|
||||
};
|
||||
app.run("ui.saveGraphicStyleLibrary", json!({"names": ["Sunshine"]})).unwrap();
|
||||
let d = app.ui.dialog.as_mut().expect("Save Graphic Style Library opens");
|
||||
assert_eq!((d.kind.as_str(), d.bool("user")), (crate::dialogs::save_style_library::KIND, true));
|
||||
d.fields.insert("name".into(), json!("Warm"));
|
||||
d.fields.insert("selectedOnly".into(), json!(true));
|
||||
let ctx = context();
|
||||
frame(&ctx, vec![], Modifiers::NONE, 0.0, |ui| crate::dialogs::show(&mut app, ui.ctx()));
|
||||
let texts = frame(&ctx, vec![], Modifiers::NONE, 0.5, |ui| crate::dialogs::show(&mut app, ui.ctx()));
|
||||
assert!(texts.iter().any(|t| t == "Selected Styles Only (1)"), "{texts:?}");
|
||||
crate::dialogs::confirm(&mut app).unwrap();
|
||||
assert!(app.ui.dialog.is_none());
|
||||
confirm_save(&mut app, &[("name", json!("Warm")), ("selectedOnly", json!(true))]);
|
||||
assert_eq!(user_items(&app), [("Warm".to_string(), "window.userGraphicStyleLibrary1".to_string())]);
|
||||
app.run("window.userGraphicStyleLibrary1", json!({})).unwrap();
|
||||
assert_eq!(last_open(&app.ui).map(|p| p.id.as_str()), Some("user/Warm.vcstyles"));
|
||||
@@ -238,8 +183,7 @@ fn saving_to_a_file_and_opening_a_vcstyles_file() {
|
||||
};
|
||||
let mut app = app_with(services);
|
||||
app.run("ui.saveGraphicStyleLibrary", json!({})).unwrap();
|
||||
assert!(!app.ui.dialog.as_ref().unwrap().bool("__user"), "no user folder: a file");
|
||||
crate::dialogs::confirm(&mut app).unwrap();
|
||||
confirm_save(&mut app, &[]);
|
||||
let (path, bytes) = written.borrow()[0].clone();
|
||||
assert!(path.ends_with(".vcstyles"), "{path}");
|
||||
// Opening it opens it in the library panel, not as a document.
|
||||
@@ -252,30 +196,4 @@ fn saving_to_a_file_and_opening_a_vcstyles_file() {
|
||||
assert_eq!(GraphicStyleLibraries::get(&app, &open.id).unwrap().1.len(), app.session.doc().unwrap().doc.graphic_styles.len());
|
||||
}
|
||||
|
||||
/// A built-in library lists its styles in the UI language, and Find matches the name shown and the
|
||||
/// style's own name. A click applies the style under its own name. Another library's styles are
|
||||
/// matched by their own names only.
|
||||
#[test]
|
||||
fn built_in_library_styles_are_listed_in_the_ui_language() {
|
||||
let mut app = app();
|
||||
let ctx = context();
|
||||
crate::i18n::set_current(crate::i18n::Lang::from_code("fr").expect("fr registered"));
|
||||
app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 80, "height": 40})).unwrap();
|
||||
app.run("window.graphicStyleLibrary", json!({"library": "shadows-glows"})).unwrap();
|
||||
let panel = last_open(&app.ui).map(LibraryPanel::panel).unwrap_or_default();
|
||||
app.run("ui.libraryPanel", json!({"panel": panel, "view": "smallList"})).unwrap();
|
||||
frame(&ctx, vec![], Modifiers::NONE, 0.0, |ui| library_panel::show_window(&mut app, ui.ctx()));
|
||||
let texts = frame(&ctx, vec![], Modifiers::NONE, 0.25, |ui| library_panel::show_window(&mut app, ui.ctx()));
|
||||
assert!(texts.iter().any(|t| t == "Ombre douce"), "{texts:?}");
|
||||
assert!(!texts.iter().any(|t| t == "Soft Shadow"), "{texts:?}");
|
||||
let lib = GraphicStyleLibraries::get(&app, "shadows-glows").unwrap().1;
|
||||
for query in ["ombre douce", "soft shadow"] {
|
||||
let rows = GraphicStyleLibraries::rows(&lib, "shadows-glows", query);
|
||||
assert_eq!(rows.iter().map(|r| r.name).collect::<Vec<_>>(), ["Soft Shadow"], "{query}");
|
||||
}
|
||||
assert!(GraphicStyleLibraries::rows(&lib, "loaded/1", "ombre douce").is_empty(), "another library's style is matched by its own name only");
|
||||
click(&mut app, &ctx, "Soft Shadow", Modifiers::NONE, 1.0);
|
||||
let (g, _) = app.session.selection_graphic_style().expect("applied to the selection");
|
||||
assert_eq!(g.name, "Soft Shadow");
|
||||
crate::i18n::set_current(crate::i18n::Lang::EN);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,14 +3,14 @@
|
||||
//! open libraries, Save Symbols writes User Defined libraries that reopen, and Other Library… turns
|
||||
//! down files it can't read.
|
||||
|
||||
use egui::{Event, Modifiers, PointerButton, Pos2, Rect, vec2};
|
||||
use egui::{Event, Modifiers, Pos2, Rect, vec2};
|
||||
use serde_json::json;
|
||||
use vectorcraft_engine::Session;
|
||||
|
||||
use super::library_panel::tests::{click, confirm_save, context, menu_library_ids};
|
||||
use super::library_panel::{self, LibraryKind, LibraryPanel, last_open};
|
||||
use super::symbols::SymbolLibraries;
|
||||
use crate::VectorcraftApp;
|
||||
use crate::widgets::PanelDrag;
|
||||
|
||||
fn app() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
@@ -18,12 +18,6 @@ fn app() -> VectorcraftApp {
|
||||
app
|
||||
}
|
||||
|
||||
fn context() -> egui::Context {
|
||||
let ctx = egui::Context::default();
|
||||
crate::theme::install_fonts(&ctx);
|
||||
ctx
|
||||
}
|
||||
|
||||
/// One frame of `draw` with `events`; the texts it painted.
|
||||
fn frame(ctx: &egui::Context, events: Vec<Event>, time: f64, mut draw: impl FnMut(&mut egui::Ui)) -> Vec<String> {
|
||||
fn texts(s: &egui::Shape, out: &mut Vec<String>) {
|
||||
@@ -42,23 +36,6 @@ fn frame(ctx: &egui::Context, events: Vec<Event>, time: f64, mut draw: impl FnMu
|
||||
v
|
||||
}
|
||||
|
||||
/// The centre of the open library panel's tile of symbol `name` (a new window takes a sizing
|
||||
/// frame first).
|
||||
fn tile(app: &mut VectorcraftApp, ctx: &egui::Context, name: &str, time: f64) -> Pos2 {
|
||||
for t in [time, time + 0.25] {
|
||||
frame(ctx, vec![], t, |ui| library_panel::show_window(app, ui.ctx()));
|
||||
}
|
||||
let id = library_panel::tile_id(&last_open(&app.ui).map(LibraryPanel::panel).unwrap_or_default(), name);
|
||||
ctx.read_response(id).unwrap_or_else(|| panic!("no tile for {name}")).rect.center()
|
||||
}
|
||||
|
||||
fn click(app: &mut VectorcraftApp, ctx: &egui::Context, name: &str, modifiers: Modifiers, time: f64) {
|
||||
let at = tile(app, ctx, name, time);
|
||||
let button = |pressed| Event::PointerButton { pos: at, button: PointerButton::Primary, pressed, modifiers };
|
||||
let events = vec![Event::ModifiersChanged(modifiers), Event::PointerMoved(at), button(true), button(false)];
|
||||
frame(ctx, events, time + 0.5, |ui| library_panel::show_window(app, ui.ctx()));
|
||||
}
|
||||
|
||||
fn undo_len(app: &VectorcraftApp) -> usize {
|
||||
app.session.doc().unwrap().history.undo.len()
|
||||
}
|
||||
@@ -87,55 +64,16 @@ fn clicking_a_library_symbol_adds_it_to_the_documents_symbols_in_one_step() {
|
||||
assert_eq!(symbols(&app), ["Star"]);
|
||||
SymbolLibraries::add(&mut app, "basic-shapes", vec!["Hexagon".into(), "Arrow".into()]);
|
||||
assert_eq!(symbols(&app), ["Star", "Hexagon", "Arrow"]);
|
||||
// Find filters by name; list rows give the natural size.
|
||||
// List rows give the natural size.
|
||||
let lib = SymbolLibraries::get(&app, "basic-shapes").unwrap().1;
|
||||
let rows = SymbolLibraries::rows(&lib, "basic-shapes", "arr");
|
||||
assert_eq!(rows.iter().map(|r| r.name).collect::<Vec<_>>(), ["Arrow"]);
|
||||
assert_eq!(SymbolLibraries::describe(rows[0].item.unwrap()), "48 × 32 pt");
|
||||
// Dragging a symbol out of the panel carries it to the canvas.
|
||||
let at = tile(&mut app, &ctx, "Burst", 6.0);
|
||||
let press = Event::PointerButton { pos: at, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE };
|
||||
frame(&ctx, vec![Event::PointerMoved(at), press], 6.5, |ui| library_panel::show_window(&mut app, ui.ctx()));
|
||||
for (i, d) in [20.0, 60.0].into_iter().enumerate() {
|
||||
frame(&ctx, vec![Event::PointerMoved(at + vec2(d, d))], 6.6 + 0.1 * i as f64, |ui| library_panel::show_window(&mut app, ui.ctx()));
|
||||
}
|
||||
let carried = egui::DragAndDrop::payload::<PanelDrag>(&ctx);
|
||||
assert_eq!(carried.as_deref(), Some(&PanelDrag::LibrarySymbol { library: "basic-shapes".into(), name: "Burst".into() }));
|
||||
let rows = SymbolLibraries::rows(&lib, "basic-shapes");
|
||||
let arrow = rows.iter().find(|r| r.name == "Arrow").and_then(|r| r.item).unwrap();
|
||||
assert_eq!(SymbolLibraries::describe(arrow), "48 × 32 pt");
|
||||
assert!(app.run("window.symbolLibrary", json!({"library": "nope"})).is_err());
|
||||
app.run("window.symbolLibrary", json!({"library": null})).unwrap();
|
||||
assert!(last_open(&app.ui).is_none());
|
||||
}
|
||||
|
||||
/// A secondary or middle drag out of a library tile carries no symbol and adds nothing; a primary
|
||||
/// drag still carries it.
|
||||
#[test]
|
||||
fn only_a_primary_drag_carries_a_library_symbol_out() {
|
||||
let mut app = app();
|
||||
let ctx = context();
|
||||
app.run("window.symbolLibrary", json!({"library": "Basic Shapes"})).unwrap();
|
||||
let undo = undo_len(&app);
|
||||
let mut time = 0.0;
|
||||
let mut drag = |app: &mut VectorcraftApp, pointer: PointerButton| {
|
||||
let at = tile(app, &ctx, "Burst", time);
|
||||
let button = |pos, pressed| Event::PointerButton { pos, button: pointer, pressed, modifiers: Modifiers::NONE };
|
||||
frame(&ctx, vec![Event::PointerMoved(at), button(at, true)], time + 0.5, |ui| library_panel::show_window(app, ui.ctx()));
|
||||
for (i, d) in [20.0, 60.0].into_iter().enumerate() {
|
||||
frame(&ctx, vec![Event::PointerMoved(at + vec2(d, d))], time + 0.6 + 0.1 * i as f64, |ui| library_panel::show_window(app, ui.ctx()));
|
||||
}
|
||||
let carried = egui::DragAndDrop::payload::<PanelDrag>(&ctx).map(|p| (*p).clone());
|
||||
let end = at + vec2(60.0, 60.0);
|
||||
frame(&ctx, vec![button(end, false)], time + 0.9, |ui| library_panel::show_window(app, ui.ctx()));
|
||||
frame(&ctx, vec![], time + 1.0, |ui| library_panel::show_window(app, ui.ctx()));
|
||||
time += 2.0;
|
||||
carried
|
||||
};
|
||||
for pointer in [PointerButton::Secondary, PointerButton::Middle] {
|
||||
assert_eq!(drag(&mut app, pointer), None, "a {pointer:?} drag carries nothing");
|
||||
}
|
||||
assert_eq!((symbols(&app).len(), undo_len(&app)), (0, undo), "nothing is added");
|
||||
let carried = drag(&mut app, PointerButton::Primary);
|
||||
assert_eq!(carried, Some(PanelDrag::LibrarySymbol { library: "basic-shapes".into(), name: "Burst".into() }));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_window_menu_and_the_symbols_panel_open_symbol_libraries() {
|
||||
@@ -161,14 +99,12 @@ fn the_window_menu_and_the_symbols_panel_open_symbol_libraries() {
|
||||
assert_eq!(has("window.symbolLibrary.other"), Some(true));
|
||||
assert_eq!(has("ui.saveSymbolLibrary"), Some(false), "no symbols to save yet");
|
||||
assert!(!entries.iter().any(|e| e.path == ["Window", "Symbol Libraries", "User Defined"]), "empty slots are hidden");
|
||||
// The Symbols panel's library button and menu.
|
||||
let ctx = context();
|
||||
let texts = frame(&ctx, vec![], 0.0, |ui| {
|
||||
super::symbols::show(&mut app, ui);
|
||||
super::symbols::menu(&mut app, ui);
|
||||
});
|
||||
for t in ["Open Symbol Library", "Save Symbol Library…"] {
|
||||
assert!(texts.iter().any(|x| x.ends_with(t)), "{t}: {texts:?}");
|
||||
// The Symbols panel's library menus list the same libraries, and each Window row opens its panel.
|
||||
let ids: Vec<String> = opened.iter().filter_map(|v| v.as_str().map(str::to_string)).collect();
|
||||
assert_eq!(menu_library_ids::<SymbolLibraries>(&app), ids);
|
||||
for id in &ids {
|
||||
app.run("window.symbolLibrary", json!({"library": id})).unwrap();
|
||||
assert_eq!(last_open(&app.ui).map(|p| p.id.as_str()), Some(id.as_str()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,16 +119,8 @@ fn save_symbols_writes_a_user_library_that_reopens_and_adds_to_another_document(
|
||||
app.run("shape.ellipse", json!({"x": 60, "y": 60, "width": 20, "height": 20})).unwrap();
|
||||
app.run("symbol.new", json!({"name": "Pebble"})).unwrap();
|
||||
app.run("ui.saveSymbolLibrary", json!({"names": ["Brick"]})).unwrap();
|
||||
let d = app.ui.dialog.as_mut().expect("Save Symbol Library opens");
|
||||
assert_eq!((d.kind.as_str(), d.bool("user")), (crate::dialogs::save_symbol_library::KIND, true));
|
||||
d.fields.insert("name".into(), json!("Masonry"));
|
||||
d.fields.insert("selectedOnly".into(), json!(true));
|
||||
confirm_save(&mut app, &[("name", json!("Masonry")), ("selectedOnly", json!(true))]);
|
||||
let ctx = context();
|
||||
frame(&ctx, vec![], 0.0, |ui| crate::dialogs::show(&mut app, ui.ctx()));
|
||||
let texts = frame(&ctx, vec![], 0.5, |ui| crate::dialogs::show(&mut app, ui.ctx()));
|
||||
assert!(texts.iter().any(|t| t == "Selected Symbols Only (1)"), "{texts:?}");
|
||||
crate::dialogs::confirm(&mut app).unwrap();
|
||||
assert!(app.ui.dialog.is_none());
|
||||
let user: Vec<(String, String)> = crate::menus::menu_entries(&app)
|
||||
.into_iter()
|
||||
.filter(|e| e.path == ["Window", "Symbol Libraries", "User Defined"])
|
||||
@@ -253,13 +181,7 @@ fn built_in_library_symbols_are_listed_in_the_ui_language() {
|
||||
let texts = frame(&ctx, vec![], 0.25, |ui| library_panel::show_window(&mut app, ui.ctx()));
|
||||
assert!(texts.iter().any(|t| t == "Éclat") && texts.iter().any(|t| t == "Étoile"), "{texts:?}");
|
||||
assert!(!texts.iter().any(|t| t == "Burst"), "{texts:?}");
|
||||
let lib = SymbolLibraries::get(&app, "basic-shapes").unwrap().1;
|
||||
for query in ["éclat", "burst"] {
|
||||
let rows = SymbolLibraries::rows(&lib, "basic-shapes", query);
|
||||
assert_eq!(rows.iter().map(|r| r.name).collect::<Vec<_>>(), ["Burst"], "{query}");
|
||||
}
|
||||
assert!(SymbolLibraries::rows(&lib, "loaded/1", "éclat").is_empty(), "another library's symbol is matched by its own name only");
|
||||
click(&mut app, &ctx, "Star", Modifiers::NONE, 1.0);
|
||||
click(&mut app, &ctx, "Étoile", Modifiers::NONE, 1.0);
|
||||
assert_eq!(symbols(&app), ["Star"]);
|
||||
crate::i18n::set_current(crate::i18n::Lang::EN);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user