mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-04 19:41:36 -05:00
Tests n-z: a pick replies pending, fields read with their unit painted apart, app frames feed the window
- file.open and file.place pass on the file pick's {pending: "fileDialog"} reply (fl.A3), as the
other askers do; the picks tests expect it instead of production's error.
- A save whose document closed while its panel was open says so in the status line.
- Keyboard Shortcuts > Export's save panel shows "Shortcut sets" (write_named_as).
- A parameter dialog's Preview box starts off (#5360).
- A tab press selects its document only once the press ends without moving the tab.
- Tests: Export Text's header is the framework summary's title (shortcuts-w7); the pick tests run a
frame's pumps, draw the dialog that takes a Browse answer, and open URLs from a whole app frame;
task bar, ruler origin and scrub tests find a field's number with its unit painted apart and the
labels X, Y and W; the task bar rig, plug-in harness and ruler origin frames give the window the
app's frame input; tab drops land on the first tab's left edge; PDF sections use the framework ids.
This commit is contained in:
@@ -90,8 +90,18 @@ pub fn doc_tabs(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
if let Some(w) = shown {
|
||||
strip = strip.selected(w);
|
||||
}
|
||||
// The strip selects a tab on the press; the tab is shown once the press ends without moving it, as a drag along
|
||||
// the strip or off it is not a switch.
|
||||
let pressed = egui::Id::new("vectorcraft.tabPressed");
|
||||
let held = ui.input(|i| i.pointer.primary_down());
|
||||
for event in strip.show(ui).events {
|
||||
if matches!(event, DocumentTabsEvent::Reordered { .. } | DocumentTabsEvent::TornOff { .. }) {
|
||||
ui.data_mut(|d| d.remove::<Win>(pressed));
|
||||
}
|
||||
match event {
|
||||
DocumentTabsEvent::Selected(w) if held => {
|
||||
ui.data_mut(|d| d.insert_temp(pressed, w));
|
||||
}
|
||||
DocumentTabsEvent::Selected(w) | DocumentTabsEvent::Picked(w) => doc_windows::show_window(app, w),
|
||||
DocumentTabsEvent::CloseRequested(w) => {
|
||||
if let Err(e) = doc_windows::close_window(app, w) {
|
||||
@@ -121,6 +131,9 @@ pub fn doc_tabs(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
if !held && let Some(w) = ui.data_mut(|d| d.remove_temp::<Win>(pressed)) {
|
||||
doc_windows::show_window(app, w);
|
||||
}
|
||||
}
|
||||
|
||||
/// The tab at the top of window `w`'s floating OS window ([`crate::doc_windows`]): a strip with the
|
||||
|
||||
@@ -81,6 +81,8 @@ pub(crate) fn open(app: &mut VectorcraftApp, command: &str, label: &str, mut par
|
||||
HostedParamDialog::command(&ctx, command, fields, move |_: &mut DialogFields| {
|
||||
ParamDialog::command(key.clone(), heading.clone(), command_params(&key, &opening, setting)).previews(previews)
|
||||
})
|
||||
// The Preview box starts off, as production's dialogs did (#5360).
|
||||
.preview_off()
|
||||
};
|
||||
let ok_token = token.clone();
|
||||
let cancel_token = token.clone();
|
||||
|
||||
@@ -388,10 +388,10 @@ fn open_dialog_folder(app: &VectorcraftApp) -> Option<String> {
|
||||
app.ui.recent_files.iter().find_map(|p| fileio::dialog_folder(p)).or_else(|| suggested(app, "").1)
|
||||
}
|
||||
|
||||
/// File → Open…
|
||||
pub fn open_dialog(app: &mut VectorcraftApp) -> Result<(), String> {
|
||||
/// File → Open…: `{pending: "fileDialog"}` while its picker is open.
|
||||
pub fn open_dialog(app: &mut VectorcraftApp) -> Result<Value, String> {
|
||||
let request = open_request("document", open_dialog_folder(app), fileio::open_filters());
|
||||
ask_open(app, request, Owner::Document, |app, path| open_reporting(app, &path)).map(|_| ())
|
||||
ask_open(app, request, Owner::Document, |app, path| open_reporting(app, &path))
|
||||
}
|
||||
|
||||
/// File › Open With: opens the file `p` names (`path`), else one picked among the files with the
|
||||
|
||||
@@ -151,6 +151,7 @@ pub(crate) fn pump(app: &mut VectorcraftApp, _ctx: &egui::Context) {
|
||||
for uid in busy {
|
||||
if !app.session.documents().iter().any(|d| d.uid == uid) {
|
||||
terminate(app, uid, Err(file_asks::closed().into()));
|
||||
app.status(file_asks::closed());
|
||||
if let Some(mut flow) = app.saves.flows.remove(&uid) {
|
||||
flow.cancel(app.host.files());
|
||||
}
|
||||
@@ -368,10 +369,22 @@ pub(crate) fn write_named(
|
||||
name: &str,
|
||||
bytes: Vec<u8>,
|
||||
then: impl FnOnce(&mut VectorcraftApp, String) -> Result<Value, String> + 'static,
|
||||
) -> Result<Value, String> {
|
||||
write_named_as(app, path, name, file_types(&fileio::extension(name)), bytes, then)
|
||||
}
|
||||
|
||||
/// [`write_named`] with a save panel that shows `filters`, for a file whose extension names no one
|
||||
/// type (`.json` holds shortcut sets as well as preferences).
|
||||
pub(crate) fn write_named_as(
|
||||
app: &mut VectorcraftApp,
|
||||
path: Option<String>,
|
||||
name: &str,
|
||||
filters: Vec<FileFilter>,
|
||||
bytes: Vec<u8>,
|
||||
then: impl FnOnce(&mut VectorcraftApp, String) -> Result<Value, String> + 'static,
|
||||
) -> Result<Value, String> {
|
||||
let ext = fileio::extension(name);
|
||||
let (_, folder) = suggested(app, "");
|
||||
let filters = file_types(&ext);
|
||||
ask_path(
|
||||
app,
|
||||
path,
|
||||
|
||||
@@ -192,7 +192,7 @@ fn run_ui_part1(app: &mut VectorcraftApp, id: &str, p: &Value) -> Option<Result<
|
||||
Some(params) => io::open_path_with(app, &path, params),
|
||||
None => io::open_path(app, &path),
|
||||
},
|
||||
None => io::open_dialog(app).map(|_| Value::Null),
|
||||
None => io::open_dialog(app),
|
||||
},
|
||||
"file.openWith" => io::open_with(app, p),
|
||||
// Saves write through the app (save panel, download); with no path known the panel and the
|
||||
|
||||
@@ -263,7 +263,7 @@ fn place_file_in(app: &mut VectorcraftApp, p: &Value, read: Read) -> Result<Valu
|
||||
if p.get("path").is_none() && p.get("dataBase64").is_none() {
|
||||
let files: Vec<Value> = match p.get("paths").and_then(Value::as_array) {
|
||||
Some(a) => a.iter().filter_map(Value::as_str).map(|path| json!({ "path": path })).collect(),
|
||||
None => return pick(app).map(|_| Value::Null),
|
||||
None => return Ok(pick(app)),
|
||||
};
|
||||
if files.is_empty() {
|
||||
return Err("paths: give at least one file".into());
|
||||
@@ -316,8 +316,9 @@ fn place_file_in(app: &mut VectorcraftApp, p: &Value, read: Read) -> Result<Valu
|
||||
}
|
||||
}
|
||||
|
||||
/// Pick files to place: the Place dialog opens with them (on the web once they arrive).
|
||||
fn pick(app: &mut VectorcraftApp) -> Result<(), String> {
|
||||
/// Pick files to place: the Place dialog opens with them (on the web once they arrive). Returns
|
||||
/// what [`crate::file_asks::ask`] returns.
|
||||
fn pick(app: &mut VectorcraftApp) -> Value {
|
||||
let request = fileio::place_filters().fold(PickRequest::open_many("place"), |request, (name, extensions)| request.filter(name, extensions));
|
||||
// The web answers with the files' contents instead of paths.
|
||||
crate::file_asks::ask(app, request, Owner::Document, |app, picked| {
|
||||
@@ -337,8 +338,7 @@ fn pick(app: &mut VectorcraftApp) -> Result<(), String> {
|
||||
};
|
||||
open_dialog(app, files, None);
|
||||
Ok(Value::Null)
|
||||
});
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
|
||||
/// The Place dialog for `files` (`{path}`, or `{name}` with the bytes in [`PlaceState`]), with Show
|
||||
|
||||
@@ -1369,7 +1369,8 @@ fn export(app: &mut VectorcraftApp, p: &Value) -> Result<Value, String> {
|
||||
let path = text_param(p, "path")?;
|
||||
let sets = &app.ui.shortcut_sets;
|
||||
let json = sets.export(sets.active_name(&BUILTINS), &BUILTINS).map_err(|e| e.to_string())?;
|
||||
crate::io::save::write_named(app, path, "VectorCraft Shortcuts.json", json.into_bytes(), |_, path| Ok(json!({ "path": path })))
|
||||
let filters = file_asks::filters(&[("Shortcut sets", &["json"])]);
|
||||
crate::io::save::write_named_as(app, path, "VectorCraft Shortcuts.json", filters, json.into_bytes(), |_, path| Ok(json!({ "path": path })))
|
||||
}
|
||||
|
||||
/// `shortcuts.exportText {path?, format?, pageSize?}`: the set in use as text, a shortcut sheet or
|
||||
|
||||
@@ -15,9 +15,11 @@ pub(super) fn host(app: &mut VectorcraftApp) {
|
||||
crate::testing::install(&ctx);
|
||||
}
|
||||
|
||||
/// One frame of the host (which opens a queued question), then the pump.
|
||||
/// One frame of the host (which opens a queued question), then the pump; first the answers of the save panels, as a
|
||||
/// frame's tick takes them.
|
||||
pub(super) fn pass(app: &mut VectorcraftApp) {
|
||||
let Some(ctx) = app.ui_ctx.clone() else { return };
|
||||
crate::tests_svg::picked(app);
|
||||
let Some(dialogs) = app.dialogs() else { return };
|
||||
let mut out = ctx.run_ui(egui::RawInput::default(), |ui| dialogs.with(|host| host.run(ui)));
|
||||
out.textures_delta.clear();
|
||||
@@ -66,7 +68,8 @@ fn save_as_native_asks_for_its_options_and_writes_every_artboard() {
|
||||
host(&mut app);
|
||||
three_boards(&mut app);
|
||||
let r = app.run("file.saveAs", Value::Null).unwrap();
|
||||
assert_eq!(r["pending"], "saveOptions");
|
||||
assert_eq!(r["pending"], "fileDialog");
|
||||
pass(&mut app);
|
||||
let open = open_dialogs(&app);
|
||||
assert_eq!(open.len(), 1);
|
||||
let f = open[0].fields.clone().unwrap();
|
||||
|
||||
@@ -99,8 +99,8 @@ fn a_press_on_the_canvas_commits_to_the_object_being_edited() {
|
||||
let shared = app.clone();
|
||||
let mut fixture = Fixture::new(move |ui| window(&mut shared.borrow_mut(), ui));
|
||||
fixture.settle();
|
||||
// PLAN: assumed the ported W field's label is "W:" and a click on it focuses the field (object-panels-w9).
|
||||
let label = fixture.by_label("W:").expect("the Transform panel shows the W field");
|
||||
// The Transform panel's W field is named by its label, "W"; a click on it focuses the field.
|
||||
let label = fixture.by_label("W").expect("the Transform panel shows the W field");
|
||||
fixture.click(&label).idle(2).key(Key::A, Modifiers::COMMAND).type_text("42").idle(1);
|
||||
// PLAN: assumed the artboard is centred in the window, so the window's centre is on the big rectangle only.
|
||||
let canvas = fixture.ctx().content_rect().center();
|
||||
|
||||
@@ -19,11 +19,10 @@ fn brackets(app: &VectorcraftApp, id: NodeId) -> (f64, Option<f64>) {
|
||||
}
|
||||
}
|
||||
|
||||
/// One frame of the app, then the dialog pump: the dialog host runs inside the app's pass, and a held OK or a
|
||||
/// One whole frame of the app, then the dialog pump: the dialog host runs inside the app's pass, and a held OK or a
|
||||
/// Cancel is answered by the pump.
|
||||
pub(super) fn frame(app: &mut VectorcraftApp, ctx: &egui::Context) {
|
||||
let mut out = ctx.run_ui(egui::RawInput::default(), |ui| app.ui(ui));
|
||||
out.textures_delta.clear();
|
||||
crate::testing::app_frame(app, ctx, egui::RawInput::default());
|
||||
dialogs::host::pump(app, ctx);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,8 +14,8 @@ fn output_and_advanced_choices_reach_the_pdf() {
|
||||
let ctx = shown(&mut app);
|
||||
app.run("ui.savePdfDialog", json!({"path": "/tmp/press.pdf"})).unwrap();
|
||||
frame(&mut app, &ctx);
|
||||
// PLAN: field keys assumed from the old dialog fields (`__section` is `section`); export-w6's `json_fields` names them.
|
||||
set_field(&app, &ctx, "section", json!("Output"));
|
||||
// The section ids are the framework dialog's `json_fields` ones.
|
||||
set_field(&app, &ctx, "section", json!("output"));
|
||||
set_field(
|
||||
&app,
|
||||
&ctx,
|
||||
@@ -25,7 +25,7 @@ fn output_and_advanced_choices_reach_the_pdf() {
|
||||
set_field(&app, &ctx, "advanced", json!({"outlineText": false}));
|
||||
set_field(&app, &ctx, "compression", json!({"compressText": false}));
|
||||
set_field(&app, &ctx, "standard", json!("none"));
|
||||
set_field(&app, &ctx, "section", json!("Advanced"));
|
||||
set_field(&app, &ctx, "section", json!("advanced"));
|
||||
frame(&mut app, &ctx);
|
||||
confirm(&mut app, &ctx);
|
||||
assert!(app.ui.status.starts_with("Saved /tmp/press.pdf") && !app.ui.status.contains("note"), "{}", app.ui.status);
|
||||
|
||||
@@ -86,6 +86,11 @@ pub(crate) fn install_files(app: &mut VectorcraftApp, files: Arc<ScriptedFiles>)
|
||||
Host::clone(&app.host).install(&ctx);
|
||||
}
|
||||
|
||||
/// Runs `command` with no path: it asks for a file and replies that it waits for the pick (fl.A3).
|
||||
pub(crate) fn asks(app: &mut VectorcraftApp, command: &str) {
|
||||
assert_eq!(app.run(command, json!({})), Ok(json!({"pending": "fileDialog"})), "{command} waits for its pick");
|
||||
}
|
||||
|
||||
/// Run what the frame runs for the picks: their continuations, then the saves.
|
||||
pub(crate) fn poll(app: &mut VectorcraftApp, ctx: &egui::Context) {
|
||||
file_asks::poll(app);
|
||||
@@ -183,9 +188,11 @@ fn app() -> VectorcraftApp {
|
||||
VectorcraftApp::new(Session::new(), Services::default())
|
||||
}
|
||||
|
||||
/// The picks' answers, then the rest of a frame's pumps (Save Changes goes on once its save is written).
|
||||
fn settle(app: &mut VectorcraftApp) {
|
||||
let ctx = app.ui_ctx.clone().unwrap_or_default();
|
||||
poll(app, &ctx);
|
||||
crate::dialogs::host::pump(app, &ctx);
|
||||
}
|
||||
|
||||
/// The id of the open dialog with `key`.
|
||||
@@ -202,13 +209,13 @@ fn fields_of(app: &VectorcraftApp, id: DialogId) -> Option<Value> {
|
||||
open_dialogs(app).into_iter().find(|d| d.id == id).and_then(|d| d.fields)
|
||||
}
|
||||
|
||||
/// One pass of the app's `poll` as a frame → the URLs the frame asked egui to open.
|
||||
/// One whole frame of the app (its `tick` polls the picks and opens the URL a save asked for) → the URLs the frame
|
||||
/// asked egui to open.
|
||||
fn opened_urls(app: &mut VectorcraftApp) -> Vec<String> {
|
||||
let ctx = app.ui_ctx.clone().unwrap_or_default();
|
||||
let raw = egui::RawInput { screen_rect: Some(Rect::from_min_size(Pos2::ZERO, vec2(1600.0, 900.0))), ..Default::default() };
|
||||
let mut out = ctx.run_ui(raw, |ui| poll(app, ui.ctx()));
|
||||
out.textures_delta.clear();
|
||||
out.platform_output
|
||||
crate::testing::app_frame(app, &ctx, raw)
|
||||
.platform_output
|
||||
.commands
|
||||
.iter()
|
||||
.filter_map(|c| match c {
|
||||
@@ -332,7 +339,7 @@ fn a_command_asks_for_a_file_and_goes_on_with_the_answer() {
|
||||
let picker = scripted(&mut a);
|
||||
a.run("file.new", json!({"width": 100, "height": 80})).unwrap();
|
||||
a.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 30, "height": 20})).unwrap();
|
||||
assert!(a.run(command, json!({})).is_err(), "{command} waits for its pick");
|
||||
asks(&mut a, command);
|
||||
assert_eq!(picker.requests().iter().map(|r| r.kind).collect::<Vec<_>>(), [kind], "{command}");
|
||||
settle(&mut a);
|
||||
assert!(a.file_dialog_open(), "{command}");
|
||||
@@ -345,7 +352,7 @@ fn a_command_asks_for_a_file_and_goes_on_with_the_answer() {
|
||||
let mut a = app();
|
||||
let picker = scripted(&mut a);
|
||||
a.run("file.new", json!({"width": 100, "height": 80})).unwrap();
|
||||
assert!(a.run(command, json!({})).is_err());
|
||||
asks(&mut a, command);
|
||||
picker.cancel();
|
||||
settle(&mut a);
|
||||
assert!(!a.file_dialog_open(), "{command}");
|
||||
@@ -390,10 +397,12 @@ fn a_dialogs_folder_button_fills_its_field_when_the_picker_answers() {
|
||||
assert_eq!(picker.requests().iter().map(|r| r.kind).collect::<Vec<_>>(), [PickKind::Folder]);
|
||||
picker.answer(&["/out"]);
|
||||
settle(&mut app);
|
||||
// The dialog writes the answer into its field in its next pass.
|
||||
let ctx = app.ui_ctx.clone().unwrap();
|
||||
draw_dialogs(&mut app, &ctx);
|
||||
assert_eq!(fields_of(&app, id).map(|f| f["folder"].clone()), Some(json!("/out")));
|
||||
|
||||
browse_folder(&mut app, id);
|
||||
let ctx = app.ui_ctx.clone().unwrap();
|
||||
app.dialogs().unwrap().with(|h| h.cancel_by_id(&ctx, id));
|
||||
picker.answer(&["/late"]);
|
||||
settle(&mut app);
|
||||
@@ -412,6 +421,7 @@ fn keyboard_shortcuts_export_text_writes_the_working_set_as_text() {
|
||||
Ok(())
|
||||
}));
|
||||
// PLAN: the working set is the active set's defaults here; shortcuts-w6's `Overrides` setter is not named.
|
||||
app_frame(&app.ui_ctx.clone().unwrap(), &mut app, false);
|
||||
let _ = app.run("shortcuts.exportText", json!({}));
|
||||
let requests = picker.requests();
|
||||
let [request] = requests.as_slice() else { panic!("{requests:?}") };
|
||||
@@ -422,7 +432,7 @@ fn keyboard_shortcuts_export_text_writes_the_working_set_as_text() {
|
||||
let texts = texts.borrow();
|
||||
let [(path, text)] = texts.as_slice() else { panic!("{texts:?}") };
|
||||
assert_eq!(path, "/keys/list.txt");
|
||||
assert!(text.starts_with("Keyboard Shortcuts\n"), "{text}");
|
||||
assert!(text.starts_with("Keyboard Shortcuts · VectorCraft Defaults\n"), "{text}");
|
||||
assert!(text.contains(&format!("\t{}\n", crate::keymap::chord_text("Ctrl+S"))), "{text}");
|
||||
}
|
||||
|
||||
@@ -436,7 +446,7 @@ fn keyboard_shortcuts_export_text_writes_the_format_picked_in_its_save_dialog()
|
||||
("/keys/list.csv", None, "/keys/list.csv", csv),
|
||||
("/keys/table", Some(2), "/keys/table.csv", csv),
|
||||
("/keys/sheet", Some(1), "/keys/sheet.pdf", &b"%PDF-"[..]),
|
||||
("/keys/plain", Some(0), "/keys/plain.txt", &b"Keyboard Shortcuts\n"[..]),
|
||||
("/keys/plain", Some(0), "/keys/plain.txt", "Keyboard Shortcuts · ".as_bytes()),
|
||||
] {
|
||||
let mut app = app();
|
||||
let picker = scripted(&mut app);
|
||||
@@ -446,6 +456,7 @@ fn keyboard_shortcuts_export_text_writes_the_format_picked_in_its_save_dialog()
|
||||
f.borrow_mut().push((path.to_string(), b.to_vec()));
|
||||
Ok(())
|
||||
}));
|
||||
app_frame(&app.ui_ctx.clone().unwrap(), &mut app, false);
|
||||
let _ = app.run("shortcuts.exportText", json!({}));
|
||||
picker.answer_saved(answer, file_type);
|
||||
settle(&mut app);
|
||||
@@ -467,9 +478,10 @@ fn keyboard_shortcuts_import_opens_a_text_set_over_the_dialog() {
|
||||
let set = dir.join("Mine.kys");
|
||||
std::fs::write(&set, "/Menus {\n /Acme\\ Undo { /Modifiers 11 /Key 902 }\n}\n").unwrap();
|
||||
app.services.read = Some(Box::new(|p: &str| std::fs::read(p).map_err(|e| e.to_string())));
|
||||
app_frame(&app.ui_ctx.clone().unwrap(), &mut app, false);
|
||||
app.run("edit.keyboardShortcuts", json!({})).unwrap();
|
||||
let shortcuts = top(&app);
|
||||
assert_eq!(app.run("shortcuts.import", json!({})), Err("cancelled".to_string()));
|
||||
asks(&mut app, "shortcuts.import");
|
||||
picker.answer(&[&set.to_string_lossy()]);
|
||||
settle(&mut app);
|
||||
// PLAN: assumed the review is a dialog of its own over Keyboard Shortcuts (shortcuts-w8).
|
||||
@@ -502,7 +514,7 @@ fn keyboard_shortcuts_commands_reject_a_path_that_is_not_a_string() {
|
||||
}
|
||||
}
|
||||
assert!(picker.written().is_empty() && read.borrow().is_empty());
|
||||
assert_eq!(app.run("shortcuts.export", json!({"path": null})), Err("cancelled".to_string()));
|
||||
assert_eq!(app.run("shortcuts.export", json!({"path": null})), Ok(json!({"pending": "fileDialog"})));
|
||||
assert_eq!(picker.requests().iter().map(|r| r.kind).collect::<Vec<_>>(), [PickKind::Save]);
|
||||
}
|
||||
|
||||
@@ -516,7 +528,7 @@ fn save_as_saves_the_document_that_asked() {
|
||||
app.run("file.new", json!({"width": 200, "height": 160})).unwrap();
|
||||
let uids: Vec<u64> = app.session.documents().iter().map(|d| d.uid).collect();
|
||||
app.run("document.activate", json!({"index": 0})).unwrap();
|
||||
assert!(app.run("file.saveAs", json!({})).is_err());
|
||||
asks(&mut app, "file.saveAs");
|
||||
app.run("document.activate", json!({"index": 1})).unwrap();
|
||||
picker.answer_saved("/art/a.svg", None);
|
||||
settle(&mut app);
|
||||
@@ -538,7 +550,7 @@ fn an_answer_for_a_closed_document_is_dropped() {
|
||||
app.run("file.new", json!({"width": 100, "height": 80})).unwrap();
|
||||
app.run("file.new", json!({"width": 200, "height": 160})).unwrap();
|
||||
app.run("document.activate", json!({"index": 0})).unwrap();
|
||||
assert!(app.run("file.saveAs", json!({})).is_err());
|
||||
asks(&mut app, "file.saveAs");
|
||||
app.session.execute("file.close", &json!({"index": 0})).unwrap();
|
||||
app.sync_views();
|
||||
picker.answer_saved("/art/a.svg", None);
|
||||
@@ -560,7 +572,7 @@ fn nothing_closes_or_quits_while_a_sheet_is_open() {
|
||||
app.run("file.new", json!({"width": 100, "height": 80})).unwrap();
|
||||
app.run("file.new", json!({"width": 200, "height": 160})).unwrap();
|
||||
assert!(!app.file_dialog_open() && !app.file_sheet_open());
|
||||
assert!(app.run("file.open", json!({})).is_err());
|
||||
asks(&mut app, "file.open");
|
||||
assert!(app.file_dialog_open() && app.file_sheet_open());
|
||||
let refused = |app: &mut VectorcraftApp| {
|
||||
for (id, p) in [("app.quit", json!({})), ("file.close", json!({})), ("file.close", json!({"index": 0})), ("file.closeAll", json!({}))] {
|
||||
@@ -579,14 +591,14 @@ fn nothing_closes_or_quits_while_a_sheet_is_open() {
|
||||
app.run("file.close", json!({})).unwrap();
|
||||
assert_eq!(app.session.documents().len(), 2);
|
||||
// Cancelled: the same.
|
||||
assert!(app.run("file.saveAs", json!({})).is_err());
|
||||
asks(&mut app, "file.saveAs");
|
||||
refused(&mut app);
|
||||
picker.cancel();
|
||||
settle(&mut app);
|
||||
assert!(!app.file_dialog_open());
|
||||
app.run("file.closeAll", json!({})).unwrap();
|
||||
assert!(app.session.documents().is_empty());
|
||||
assert!(app.run("file.open", json!({})).is_err());
|
||||
asks(&mut app, "file.open");
|
||||
assert!(app.run("app.quit", json!({})).is_err());
|
||||
picker.cancel();
|
||||
settle(&mut app);
|
||||
@@ -601,7 +613,7 @@ fn no_view_closes_while_a_sheet_is_open() {
|
||||
let picker = scripted_sheets(&mut app, true);
|
||||
app.run("file.new", json!({"width": 100, "height": 80})).unwrap();
|
||||
app.run("window.newWindow", json!({})).unwrap();
|
||||
assert!(app.run("file.open", json!({})).is_err());
|
||||
asks(&mut app, "file.open");
|
||||
assert_eq!(app.run("file.close", json!({})), Err(file_asks::busy().to_string()));
|
||||
assert_eq!(crate::doc_windows::windows(&app), [(0, 1), (0, 2)]);
|
||||
picker.cancel();
|
||||
@@ -619,7 +631,7 @@ fn on_linux_documents_close_while_a_dialog_is_open() {
|
||||
app.run("file.new", json!({"width": 100, "height": 80})).unwrap();
|
||||
app.run("file.new", json!({"width": 200, "height": 160})).unwrap();
|
||||
app.run("document.activate", json!({"index": 0})).unwrap();
|
||||
assert!(app.run("file.saveAs", json!({})).is_err());
|
||||
asks(&mut app, "file.saveAs");
|
||||
assert!(app.file_dialog_open() && !app.file_sheet_open());
|
||||
app.run("file.close", json!({})).unwrap();
|
||||
assert_eq!(app.session.documents().len(), 1);
|
||||
@@ -629,7 +641,7 @@ fn on_linux_documents_close_while_a_dialog_is_open() {
|
||||
assert!(picker.written().is_empty());
|
||||
assert!(find(&app, "svgOptions").is_none());
|
||||
// Quit goes on too.
|
||||
assert!(app.run("file.open", json!({})).is_err());
|
||||
asks(&mut app, "file.open");
|
||||
assert!(app.file_dialog_open());
|
||||
app.run("app.quit", json!({})).unwrap();
|
||||
assert_eq!(app.ui.status, "quit");
|
||||
@@ -642,7 +654,7 @@ fn an_open_answer_goes_on_after_the_active_document_closes() {
|
||||
let mut app = app();
|
||||
let picker = scripted_sheets(&mut app, false);
|
||||
app.run("file.new", json!({"width": 100, "height": 80})).unwrap();
|
||||
assert!(app.run("file.open", json!({})).is_err());
|
||||
asks(&mut app, "file.open");
|
||||
app.run("file.close", json!({})).unwrap();
|
||||
assert!(app.session.documents().is_empty());
|
||||
picker.answer(&["/art/b.svg"]);
|
||||
@@ -724,7 +736,7 @@ fn the_window_stays_open_while_a_sheet_is_on_it() {
|
||||
let ctx = app.ui_ctx.clone().unwrap();
|
||||
app.run("file.new", json!({"width": 100, "height": 80})).unwrap();
|
||||
app_frame(&ctx, &mut app, false);
|
||||
assert!(app.run("file.open", json!({})).is_err());
|
||||
asks(&mut app, "file.open");
|
||||
let commands = app_frame(&ctx, &mut app, true);
|
||||
assert_eq!(commands.contains(&egui::ViewportCommand::CancelClose), sheets, "sheets: {sheets}");
|
||||
assert_eq!(app.ui.status == file_asks::busy(), sheets, "sheets: {sheets}: {}", app.ui.status);
|
||||
@@ -748,9 +760,9 @@ fn inspect_tells_the_file_dialog_open() {
|
||||
/// What asks for a kind of pick.
|
||||
type Ask = fn(&mut VectorcraftApp);
|
||||
let asks: [(&str, Ask); 4] = [
|
||||
("open", |app| assert!(app.run("file.open", json!({})).is_err())),
|
||||
("save", |app| assert!(app.run("file.saveAs", json!({})).is_err())),
|
||||
("place", |app| assert!(app.run("file.place", json!({})).is_err())),
|
||||
("open", |app| asks(app, "file.open")),
|
||||
("save", |app| asks(app, "file.saveAs")),
|
||||
("place", |app| asks(app, "file.place")),
|
||||
("folder", |app| {
|
||||
let id = browse_dialog(app);
|
||||
browse_folder(app, id);
|
||||
@@ -784,6 +796,8 @@ fn missing_fonts_says_why_the_folder_picked_wasnt_searched() {
|
||||
app.run("document.save", json!({"path": doc.to_string_lossy()})).unwrap();
|
||||
app.session.execute("file.close", &json!({})).unwrap();
|
||||
crate::io::open_path(&mut app, &doc.to_string_lossy()).unwrap();
|
||||
// Missing Fonts opens from the frame's pump after the open.
|
||||
settle(&mut app);
|
||||
let missing = find(&app, "missingFonts").expect("Missing Fonts");
|
||||
// The test's folder is the home folder: its Library holds other apps' folders.
|
||||
app.session.search_rules = Some(vectorcraft_engine::cmd::findfiles::Rules { home: Some(root.clone()), ..Default::default() });
|
||||
|
||||
@@ -69,15 +69,15 @@ fn previewing(app: &VectorcraftApp) -> Option<bool> {
|
||||
app.dialogs().and_then(|d| d.with(|host| host.get::<HostedParamDialog>().map(HostedParamDialog::is_previewing)))
|
||||
}
|
||||
|
||||
/// One frame of the window, and the pump of the dialogs' answers.
|
||||
fn frame(h: &mut Harness<'_, VectorcraftApp>) {
|
||||
h.step();
|
||||
/// One whole app frame of the window, and the pump of the dialogs' answers.
|
||||
fn frame(h: &mut Harness<'static, VectorcraftApp>) {
|
||||
super::plugins::app_step(h);
|
||||
let ctx = h.state().ui_ctx.clone().unwrap();
|
||||
dialogs::host::pump(h.state_mut(), &ctx);
|
||||
}
|
||||
|
||||
/// Answers the open dialog: OK when `ok`, else Cancel; then a frame, so the pump acts on it.
|
||||
fn answer(h: &mut Harness<'_, VectorcraftApp>, ok: bool) {
|
||||
fn answer(h: &mut Harness<'static, VectorcraftApp>, ok: bool) {
|
||||
let ctx = h.state().ui_ctx.clone().unwrap();
|
||||
let id = open_id(h.state()).unwrap();
|
||||
h.state().dialogs().unwrap().with(|host| if ok { host.confirm_by_id(&ctx, id) } else { host.cancel_by_id(&ctx, id) });
|
||||
@@ -85,7 +85,7 @@ fn answer(h: &mut Harness<'_, VectorcraftApp>, ok: bool) {
|
||||
}
|
||||
|
||||
/// Sets the Preview check box of the open dialog.
|
||||
fn set_preview(h: &mut Harness<'_, VectorcraftApp>, on: bool) {
|
||||
fn set_preview(h: &mut Harness<'static, VectorcraftApp>, on: bool) {
|
||||
let ctx = h.state().ui_ctx.clone().unwrap();
|
||||
let id = open_id(h.state()).unwrap();
|
||||
h.state().dialogs().unwrap().with(|host| host.set_json_field(&ctx, id, "preview", json!(on))).unwrap();
|
||||
|
||||
@@ -30,19 +30,34 @@ pub(super) fn window(app: VectorcraftApp) -> Window {
|
||||
crate::testing::install(ui.ctx());
|
||||
return;
|
||||
}
|
||||
app.tick(ui.ctx());
|
||||
app.ui(ui);
|
||||
},
|
||||
app,
|
||||
);
|
||||
// The first frame installs the fonts; the second gives the app its context and host.
|
||||
h.step();
|
||||
app_step(&mut h);
|
||||
h
|
||||
}
|
||||
|
||||
/// One frame of `h` as the hosts run the window's (`testing::part_frame`): the app gives the frame's input, and the
|
||||
/// commands the pass fired run as the next frame begins.
|
||||
pub(super) fn app_step(h: &mut Window) {
|
||||
let ctx = h.ctx.clone();
|
||||
let input = |h: &mut Window| {
|
||||
let app = h.state_mut();
|
||||
app.adopt_context(&ctx);
|
||||
craft::ui::shell::embed::before_input(&ctx, |out| app.frame_input(out));
|
||||
};
|
||||
input(h);
|
||||
h.step();
|
||||
input(h);
|
||||
}
|
||||
|
||||
/// Draws a frame of `h` at `time` seconds.
|
||||
pub(super) fn at(h: &mut Window, time: f64) {
|
||||
h.input_mut().time = Some(time);
|
||||
h.step();
|
||||
app_step(h);
|
||||
}
|
||||
|
||||
/// Draws a frame a tenth of a second after the one before.
|
||||
|
||||
@@ -1094,7 +1094,7 @@ fn a_markers_menu_sets_the_base_color_that_the_rules_build_from() {
|
||||
key(&mut r, Key::Escape);
|
||||
// The selected color is another one; the rule still builds from the base.
|
||||
put(&mut r, "__sel", json!([0]));
|
||||
tap(&mut r, "Harmony Rules:");
|
||||
tap(&mut r, "Harmony Rules");
|
||||
tap(&mut r, "Triad");
|
||||
let now = new_hsb(&r);
|
||||
assert!(hue_gap(now[1][0], hsb[1][0]) < 1.0, "the base color keeps its hue: {hsb:?} -> {now:?}");
|
||||
|
||||
@@ -241,7 +241,8 @@ fn the_view_menu_lists_the_status_bar_angles_and_checks_the_current_one() {
|
||||
#[test]
|
||||
fn rotate_view_without_an_angle_asks_for_one() {
|
||||
assert!(crate::palette::items().iter().any(|(label, id)| (label.as_str(), id.as_str()) == ("Rotate View", "view.rotate")));
|
||||
let mut app = with_document();
|
||||
// The dialog opens on the window's host.
|
||||
let mut app = crate::testing::windowed(with_document());
|
||||
app.run("view.rotate", json!({"angle": 30})).unwrap();
|
||||
menus::invoke(&mut app, "view.rotate", json!({}));
|
||||
assert!(app.any_dialog_open(), "Rotate View dialog");
|
||||
|
||||
@@ -28,8 +28,7 @@ fn frame(app: &mut VectorcraftApp, ctx: &egui::Context, events: Vec<Event>, draw
|
||||
events,
|
||||
..Default::default()
|
||||
};
|
||||
let mut out = ctx.run_ui(raw, |ui| draw(app, ui));
|
||||
out.textures_delta.clear();
|
||||
let out = crate::testing::part_frame(app, ctx, raw, draw);
|
||||
fn walk(s: &egui::Shape, v: &mut Vec<(String, Rect)>) {
|
||||
match s {
|
||||
egui::Shape::Text(t) => v.push((t.galley.text().to_string(), Rect::from_min_size(t.pos, t.galley.size()))),
|
||||
@@ -42,6 +41,20 @@ fn frame(app: &mut VectorcraftApp, ctx: &egui::Context, events: Vec<Event>, draw
|
||||
texts
|
||||
}
|
||||
|
||||
/// How many fields show `v` points: painted as one run, or as its number with the unit as the next run on its row.
|
||||
fn shown(texts: &[(String, Rect)], v: f64) -> usize {
|
||||
let whole = Unit::Points.format(v);
|
||||
let Some((number, unit)) = whole.rsplit_once(' ') else { return texts.iter().filter(|(t, _)| *t == whole).count() };
|
||||
let unit_next = |r: &Rect| {
|
||||
texts
|
||||
.iter()
|
||||
.filter(|(_, u)| u.left() >= r.right() && (u.center().y - r.center().y).abs() < 4.0)
|
||||
.min_by(|a, b| a.1.left().total_cmp(&b.1.left()))
|
||||
.is_some_and(|(t, _)| t == unit)
|
||||
};
|
||||
texts.iter().filter(|(t, r)| *t == whole || (t == number && unit_next(r))).count()
|
||||
}
|
||||
|
||||
fn press(at: Pos2, pressed: bool) -> Event {
|
||||
Event::PointerButton { pos: at, button: PointerButton::Primary, pressed, modifiers: Default::default() }
|
||||
}
|
||||
@@ -195,14 +208,14 @@ fn ruler_origin_cancelled_drags_do_not_modify_either_document() {
|
||||
#[test]
|
||||
fn ruler_origin_position_fields_show_relative_values_and_edit_absolute_positions() {
|
||||
for draw in [panels::properties::show as fn(&mut VectorcraftApp, &mut Ui), panels::transform::show, chrome::control_bar] {
|
||||
for (label, arrow) in [("X:", (1.0, 0.0)), ("Y:", (0.0, 1.0))] {
|
||||
for (label, arrow) in [("X", (1.0, 0.0)), ("Y", (0.0, 1.0))] {
|
||||
let mut app = app();
|
||||
let id = NodeId(app.run("shape.rectangle", json!({"x": 100, "y": 50, "width": 80, "height": 40})).unwrap()["id"].as_u64().unwrap());
|
||||
app.run("document.setRulerOrigin", json!({"x": 120, "y": 50})).unwrap();
|
||||
let ctx = context();
|
||||
frame(&mut app, &ctx, vec![], draw);
|
||||
let texts = frame(&mut app, &ctx, vec![], draw);
|
||||
assert!(texts.iter().filter(|(t, _)| t == &Unit::Points.format(20.0)).count() >= 2, "{texts:?}");
|
||||
assert!(shown(&texts, 20.0) >= 2, "{texts:?}");
|
||||
let label = texts.iter().find(|(t, _)| t == label).unwrap().1;
|
||||
let at = pos2(label.right() + 40.0, label.center().y);
|
||||
frame(&mut app, &ctx, vec![Event::PointerMoved(at), press(at, true)], draw);
|
||||
@@ -220,7 +233,7 @@ fn ruler_origin_position_fields_show_relative_values_and_edit_absolute_positions
|
||||
#[test]
|
||||
fn ruler_origin_artboard_fields_preserve_the_absolute_reference_point() {
|
||||
for draw in [panels::properties::show as fn(&mut VectorcraftApp, &mut Ui), panels::transform::show] {
|
||||
for label in ["X:", "Y:"] {
|
||||
for label in ["X", "Y"] {
|
||||
let mut app = app();
|
||||
app.run("document.setRulerOrigin", json!({"x": 120, "y": 50})).unwrap();
|
||||
app.select_tool("artboard");
|
||||
@@ -233,7 +246,7 @@ fn ruler_origin_artboard_fields_preserve_the_absolute_reference_point() {
|
||||
frame(&mut app, &ctx, vec![press(at, false)], draw);
|
||||
frame(&mut app, &ctx, vec![key(Key::ArrowUp)], draw);
|
||||
let ab = app.session.doc().unwrap().doc.artboards[0].rect;
|
||||
assert_eq!((ab.x0, ab.y0), if label == "X:" { (1.0, 0.0) } else { (0.0, 1.0) });
|
||||
assert_eq!((ab.x0, ab.y0), if label == "X" { (1.0, 0.0) } else { (0.0, 1.0) });
|
||||
assert_eq!((ab.width(), ab.height()), (400.0, 300.0));
|
||||
}
|
||||
}
|
||||
@@ -263,10 +276,10 @@ fn artboard_rulers_position_fields_count_from_the_active_artboard() {
|
||||
let texts = frame(&mut app, &ctx, vec![], draw);
|
||||
// The reference point is the centre (760, -210): 60 and 40 from artboard 2's corner.
|
||||
for v in [60.0, 40.0] {
|
||||
assert!(texts.iter().any(|(t, _)| t == &Unit::Points.format(v)), "X and Y count from artboard 2: {texts:?}");
|
||||
assert!(shown(&texts, v) > 0, "X and Y count from artboard 2: {texts:?}");
|
||||
}
|
||||
// Typing a position puts the object there on the active artboard's rulers.
|
||||
let label = texts.iter().find(|(t, _)| t == "X:").unwrap().1;
|
||||
let label = texts.iter().find(|(t, _)| t == "X").unwrap().1;
|
||||
let at = pos2(label.right() + 40.0, label.center().y);
|
||||
frame(&mut app, &ctx, vec![Event::PointerMoved(at), press(at, true)], draw);
|
||||
frame(&mut app, &ctx, vec![press(at, false)], draw);
|
||||
@@ -278,8 +291,8 @@ fn artboard_rulers_position_fields_count_from_the_active_artboard() {
|
||||
assert_eq!(app.ruler_origin(), Point::ZERO);
|
||||
frame(&mut app, &ctx, vec![], draw);
|
||||
let texts = frame(&mut app, &ctx, vec![], draw);
|
||||
assert!(texts.iter().any(|(t, _)| t == &Unit::Points.format(761.0)), "{texts:?}");
|
||||
assert!(!texts.iter().any(|(t, _)| t == &Unit::Points.format(61.0)), "{texts:?}");
|
||||
assert!(shown(&texts, 761.0) > 0, "{texts:?}");
|
||||
assert_eq!(shown(&texts, 61.0), 0, "{texts:?}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,8 +17,7 @@ pub(super) fn window(app: &mut VectorcraftApp, ui: &mut egui::Ui) {
|
||||
/// One frame of the whole window with `events`. → The rect of the first text drawn as `text`.
|
||||
fn app_frame(app: &mut VectorcraftApp, ctx: &egui::Context, events: Vec<Event>, text: &str) -> Option<Rect> {
|
||||
let screen_rect = Some(Rect::from_min_size(Pos2::ZERO, vec2(1600.0, 900.0)));
|
||||
let mut out = ctx.run_ui(egui::RawInput { events, screen_rect, ..Default::default() }, |ui| window(app, ui));
|
||||
out.textures_delta.clear();
|
||||
let out = crate::testing::app_frame(app, ctx, egui::RawInput { events, screen_rect, ..Default::default() });
|
||||
fn find(shape: &egui::Shape, text: &str) -> Option<Rect> {
|
||||
match shape {
|
||||
egui::Shape::Text(t) if t.galley.text() == text => Some(t.galley.rect.translate(t.pos.to_vec2())),
|
||||
@@ -49,11 +48,11 @@ fn objects(doc: &DocState) -> usize {
|
||||
}
|
||||
|
||||
/// Drag the W label by `dx` in four moves (`escape`: Escape before the release).
|
||||
// PLAN: assumed the ported Transform W field (object-panels-w9) is labelled "W:" and scrubs by that label.
|
||||
// The Transform panel's W field scrubs by its label, "W".
|
||||
fn drag_w(app: &mut VectorcraftApp, ctx: &egui::Context, dx: f32, escape: bool) {
|
||||
let mut w = None;
|
||||
for _ in 0..4 {
|
||||
w = app_frame(app, ctx, vec![], "W:");
|
||||
w = app_frame(app, ctx, vec![], "W");
|
||||
}
|
||||
let at = w.expect("the W label is shown").center();
|
||||
let button = |pos, pressed| Event::PointerButton { pos, button: PointerButton::Primary, pressed, modifiers: Modifiers::NONE };
|
||||
@@ -171,7 +170,7 @@ fn a_scrub_closes_its_group_in_its_own_document_after_a_switch() {
|
||||
let undo = undo_len(&app);
|
||||
let mut w = None;
|
||||
for _ in 0..4 {
|
||||
w = app_frame(&mut app, &ctx, vec![], "W:");
|
||||
w = app_frame(&mut app, &ctx, vec![], "W");
|
||||
}
|
||||
let at = w.expect("the W label is shown").center();
|
||||
let button = |pos, pressed| Event::PointerButton { pos, button: PointerButton::Primary, pressed, modifiers: Modifiers::NONE };
|
||||
|
||||
@@ -61,10 +61,21 @@ fn current(app: &VectorcraftApp) -> String {
|
||||
app.session.active().map(|d| d.title()).unwrap_or_default()
|
||||
}
|
||||
|
||||
/// `name`'s tab.
|
||||
fn tab_rect(app: &mut VectorcraftApp, ctx: &egui::Context, time: f64, name: &str) -> egui::Rect {
|
||||
let (texts, _) = frame(app, ctx, time, vec![]);
|
||||
texts.iter().find(|(t, _)| t.starts_with(name)).map(|(_, r)| *r).unwrap_or_else(|| panic!("{name}'s tab: {texts:?}"))
|
||||
}
|
||||
|
||||
/// The middle of `name`'s tab.
|
||||
fn tab(app: &mut VectorcraftApp, ctx: &egui::Context, time: f64, name: &str) -> Pos2 {
|
||||
let (texts, _) = frame(app, ctx, time, vec![]);
|
||||
texts.iter().find(|(t, _)| t.starts_with(name)).map(|(_, r)| r.center()).unwrap_or_else(|| panic!("{name}'s tab: {texts:?}"))
|
||||
tab_rect(app, ctx, time, name).center()
|
||||
}
|
||||
|
||||
/// A point on the left edge of `name`'s tab: a tab dropped there goes before it.
|
||||
fn before(app: &mut VectorcraftApp, ctx: &egui::Context, time: f64, name: &str) -> Pos2 {
|
||||
let r = tab_rect(app, ctx, time, name);
|
||||
egui::pos2(r.left() + 4.0, r.center().y)
|
||||
}
|
||||
|
||||
/// Press at `from`, move to `to` in steps, and release there; → the output of the frame before
|
||||
@@ -98,8 +109,8 @@ fn a_tab_dragged_along_the_strip_moves_its_document_and_the_current_one_stays()
|
||||
|
||||
// And back to the start, before Bravo.
|
||||
let alpha = tab(&mut app, &ctx, 1.1, "Alpha");
|
||||
let bravo = tab(&mut app, &ctx, 1.15, "Bravo");
|
||||
drag(&mut app, &ctx, 1.2, alpha, bravo - egui::vec2(80.0, 0.0));
|
||||
let bravo = before(&mut app, &ctx, 1.15, "Bravo");
|
||||
drag(&mut app, &ctx, 1.2, alpha, bravo);
|
||||
assert_eq!(order(&app), NAMES);
|
||||
assert_eq!(current(&app), "Delta");
|
||||
}
|
||||
@@ -167,8 +178,8 @@ fn a_tab_dragged_off_the_strip_still_floats_and_moves_nothing() {
|
||||
fn next_document_steps_through_the_tabs_in_their_new_order() {
|
||||
let (mut app, ctx) = app();
|
||||
let delta = tab(&mut app, &ctx, 0.1, "Delta");
|
||||
let alpha = tab(&mut app, &ctx, 0.15, "Alpha");
|
||||
drag(&mut app, &ctx, 0.2, delta, alpha - egui::vec2(80.0, 0.0));
|
||||
let alpha = before(&mut app, &ctx, 0.15, "Alpha");
|
||||
drag(&mut app, &ctx, 0.2, delta, alpha);
|
||||
assert_eq!(order(&app), ["Delta", "Alpha", "Bravo", "Charlie"]);
|
||||
assert_eq!(current(&app), "Delta");
|
||||
app.run("window.nextDocument", json!({})).unwrap();
|
||||
|
||||
@@ -40,39 +40,69 @@ impl Rig {
|
||||
self.app.borrow_mut()
|
||||
}
|
||||
|
||||
/// Runs the commands the frames since the last call fired, as the window runs them, and gives the fixture the
|
||||
/// app's input for the next frame.
|
||||
pub(crate) fn run_fired(&mut self) {
|
||||
crate::testing::fixture_input(&mut self.app.borrow_mut(), &mut self.fx);
|
||||
}
|
||||
|
||||
/// Frames until the app is at rest, with the commands they fired run.
|
||||
fn settle(&mut self) -> &mut Fixture {
|
||||
self.run_fired();
|
||||
self.fx.settle();
|
||||
self.run_fired();
|
||||
&mut self.fx
|
||||
}
|
||||
|
||||
/// The node named `name` once the frames have settled.
|
||||
pub(crate) fn target(&mut self, name: &str) -> Option<Target> {
|
||||
self.fx.settle().by_label(name)
|
||||
self.settle().by_label(name)
|
||||
}
|
||||
|
||||
/// Clicks the node named `name`.
|
||||
pub(crate) fn click(&mut self, name: &str) {
|
||||
let target = self.target(name).unwrap_or_else(|| panic!("no node named {name:?}"));
|
||||
self.fx.click(&target);
|
||||
self.fx.settle();
|
||||
self.settle();
|
||||
}
|
||||
|
||||
/// The runs of text the latest frame painted, with their rects.
|
||||
fn texts(&mut self) -> Vec<(String, Rect)> {
|
||||
self.fx.settle().texts().iter().map(|t| (t.text.clone(), t.rect)).collect()
|
||||
self.settle().texts().iter().map(|t| (t.text.clone(), t.rect)).collect()
|
||||
}
|
||||
|
||||
/// Where `text` is painted: a run of it, or a field's value painted as its number with the unit apart right
|
||||
/// after it on its row ("10 pt" as "10" then "pt").
|
||||
fn painted(&mut self, text: &str) -> Vec<Rect> {
|
||||
let texts = self.texts();
|
||||
let unit_after = |r: &Rect, unit: &str| {
|
||||
texts
|
||||
.iter()
|
||||
.any(|(u, ur)| u == unit && ur.left() >= r.right() && ur.left() - r.right() < 24.0 && (ur.center().y - r.center().y).abs() < 4.0)
|
||||
};
|
||||
texts
|
||||
.iter()
|
||||
.filter(|(t, r)| t == text || text.rsplit_once(' ').is_some_and(|(number, unit)| t == number && unit_after(r, unit)))
|
||||
.map(|(_, r)| *r)
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn has_text(&mut self, text: &str) -> bool {
|
||||
self.texts().iter().any(|(t, _)| t == text)
|
||||
!self.painted(text).is_empty()
|
||||
}
|
||||
|
||||
fn count_text(&mut self, text: &str) -> usize {
|
||||
self.texts().iter().filter(|(t, _)| t == text).count()
|
||||
self.painted(text).len()
|
||||
}
|
||||
|
||||
/// Clicks the first painted run of `text`, or with `last` the last: an open list is painted after the
|
||||
/// closed menu that shows the same name.
|
||||
fn click_text(&mut self, text: &str, last: bool) {
|
||||
let centers: Vec<Pos2> = self.texts().into_iter().filter(|(t, _)| t == text).map(|(_, r)| r.center()).collect();
|
||||
let centers: Vec<Pos2> = self.painted(text).iter().map(Rect::center).collect();
|
||||
let at = if last { centers.last() } else { centers.first() };
|
||||
let at = *at.unwrap_or_else(|| panic!("no `{text}` painted"));
|
||||
self.fx.click_at(at);
|
||||
self.fx.settle();
|
||||
self.settle();
|
||||
}
|
||||
|
||||
/// Where the field painted right of `label`, on its row, centers.
|
||||
@@ -81,7 +111,8 @@ impl Rig {
|
||||
let l = texts.iter().find(|(t, _)| t == label).unwrap_or_else(|| panic!("no `{label}` in {texts:?}")).1;
|
||||
texts
|
||||
.iter()
|
||||
.filter(|(_, r)| r.left() > l.right() && (r.center().y - l.center().y).abs() < 8.0)
|
||||
// Tops, not centres: a label's painted rect can reach below its row.
|
||||
.filter(|(_, r)| r.left() > l.right() && (r.top() - l.top()).abs() < 8.0)
|
||||
.min_by(|a, b| a.1.left().total_cmp(&b.1.left()))
|
||||
.unwrap_or_else(|| panic!("no field after `{label}` in {texts:?}"))
|
||||
.1
|
||||
@@ -90,7 +121,7 @@ impl Rig {
|
||||
|
||||
/// Types `value` into the field painting `field` and presses Enter.
|
||||
fn type_into(&mut self, field: &str, value: &str) {
|
||||
let at = self.texts().into_iter().find(|(t, _)| t == field).unwrap_or_else(|| panic!("no `{field}` painted")).1.center();
|
||||
let at = self.painted(field).first().unwrap_or_else(|| panic!("no `{field}` painted")).center();
|
||||
self.enter_value(at, value);
|
||||
}
|
||||
|
||||
@@ -99,7 +130,7 @@ impl Rig {
|
||||
// The click selected the whole field, so the text typed replaces it.
|
||||
self.fx.type_text(value);
|
||||
self.fx.key(Key::Enter, Modifiers::NONE);
|
||||
self.fx.settle();
|
||||
self.settle();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,7 +144,9 @@ pub(super) fn driven<R>(app: &mut VectorcraftApp, room: Vec2, show: fn(&mut Vect
|
||||
// The window's dialog host is the fixture's, as a real window's frame gives the app its context.
|
||||
held.borrow_mut().adopt_context(fx.ctx());
|
||||
let mut rig = Rig { app: held, fx };
|
||||
rig.run_fired();
|
||||
let out = f(&mut rig);
|
||||
rig.run_fired();
|
||||
let Rig { app: held, fx } = rig;
|
||||
drop(fx);
|
||||
*app = Rc::into_inner(held).expect("the fixture's closure is gone").into_inner();
|
||||
|
||||
Reference in New Issue
Block a user