mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-03 15:21:17 -05:00
Quick Pen bar sits a gap below and beside the path's end, as production's corner did; Save PDF closes when its write asks first (the save panel, or whether to replace the opened file), as production did; tests: Save a Copy's Cancel cancels, Save PDF's path is read from the app's job, the recolor right-click takes the New chip, the Keyboard Shortcuts import clicks the dialog's Import… and reads its review, the in-window menu's paste is answered as egui-winit answers RequestPaste, a press and release in one frame gets the release's pass, a new Type edit follows a frame without the last one's editor, trace presets are found past a menu row's check space
This commit is contained in:
@@ -47,15 +47,19 @@ pub(super) fn quick_pen_bar(app: &mut VectorcraftApp, ui: &mut Ui, space: &Canva
|
||||
let key = (uid, end.is_some());
|
||||
let mut local = app.ui.quick_pen_bar_place.for_key(key);
|
||||
let before = local;
|
||||
let rtl = Env::of(ui).view().direction() == Direction::Rtl;
|
||||
// Beside the end, on the side the path arrives from (a path of one point: right and below); the
|
||||
// bar's sides are reading-order ones, so a rightward arrival is `End` under LTR and `Start` under RTL.
|
||||
let env = Env::of(ui);
|
||||
let rtl = env.view().direction() == Direction::Rtl;
|
||||
// Beside the end, on the side the path arrives from (a path of one point: right and below), a gap off it
|
||||
// both ways, as production's corner did; the bar's sides are reading-order ones, so a rightward arrival is
|
||||
// `End` under LTR and `Start` under RTL. The anchor moves the gap down (or up), the side adds it across.
|
||||
let (anchor, side, align) = match end {
|
||||
Some((p, dir)) => {
|
||||
let heading = dir.map(|d| space.view.to_screen(p + d) - space.view.to_screen(p));
|
||||
let right = heading.is_none_or(|d| d.x >= 0.0);
|
||||
let down = heading.is_none_or(|d| d.y >= 0.0);
|
||||
(vec![p], if right != rtl { Side::End } else { Side::Start }, if down { Align::Start } else { Align::End })
|
||||
let gap = env.tokens.space.gap.section;
|
||||
let off = space.view.to_doc(space.view.to_screen(p) + egui::vec2(0.0, if down { gap } else { -gap }));
|
||||
(vec![off], if right != rtl { Side::End } else { Side::Start }, if down { Align::Start } else { Align::End })
|
||||
}
|
||||
None => (vec![space.view.to_doc(space.view.rect.center_bottom())], Side::Above, Align::Center),
|
||||
};
|
||||
|
||||
@@ -311,11 +311,8 @@ fn drive(app: &mut VectorcraftApp, ctx: &egui::Context, open: &mut SavePdfOpen)
|
||||
Some(job) => write(app, job, &answer),
|
||||
None => save_preset(app, &open.editing, &answer),
|
||||
};
|
||||
// PLAN: a write that asked a question (replace the file the document was opened from?) leaves OK waiting; its
|
||||
// continuation must answer the dialog, which needs a hook in io.
|
||||
if reply.as_ref().is_ok_and(|r| r.get("pending").is_some()) {
|
||||
return false;
|
||||
}
|
||||
// A write that asks first (the save panel, or whether to replace the file the document was opened from) closes
|
||||
// the dialog as a written one does; the question stays open, as in production.
|
||||
let answer = reply.map(|_| ()).map_err(|e| Label::from(crate::i18n::message(crate::i18n::current(), &e)));
|
||||
dialogs.with(|host| {
|
||||
if let Some(d) = host.get_mut_by_id::<HostedPdfExport>(id) {
|
||||
|
||||
@@ -486,20 +486,26 @@ 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);
|
||||
let ctx = app.ui_ctx.clone().unwrap();
|
||||
app_frame(&ctx, &mut app, false);
|
||||
app.run("edit.keyboardShortcuts", json!({})).unwrap();
|
||||
let shortcuts = top(&app);
|
||||
asks(&mut app, "shortcuts.import");
|
||||
app_frame(&ctx, &mut app, false);
|
||||
// Keyboard Shortcuts is the framework's dialog, not one of the dialog host's: the review is its own page over it.
|
||||
let review = |app: &VectorcraftApp| app.shortcuts_dialog.as_ref().and_then(|d| d.state.snapshot(d.keymap.as_ref()?)?.review.map(|r| r.name));
|
||||
assert!(app.shortcuts_dialog.as_ref().is_some_and(|d| d.state.is_open()), "Keyboard Shortcuts opens");
|
||||
click(&mut app, "Import…", |app, ui| app.ui(ui));
|
||||
assert_eq!(picker.requests().iter().map(|r| r.kind).collect::<Vec<_>>(), [PickKind::Open], "Import… asks for the file");
|
||||
picker.answer(&[&set.to_string_lossy()]);
|
||||
settle(&mut app);
|
||||
// PLAN: assumed the review is a dialog of its own over Keyboard Shortcuts (shortcuts-w8).
|
||||
let open = open_dialogs(&app);
|
||||
assert_eq!(open.len(), 2, "{}", app.ui.status);
|
||||
assert_eq!(open[0].id, shortcuts);
|
||||
let ctx = app.ui_ctx.clone().unwrap();
|
||||
let review = top(&app);
|
||||
app.dialogs().unwrap().with(|h| h.cancel_by_id(&ctx, review));
|
||||
assert_eq!(top(&app), shortcuts);
|
||||
app_frame(&ctx, &mut app, false);
|
||||
assert_eq!(review(&app).as_deref(), Some("Mine"), "{}", app.ui.status);
|
||||
// Escape, the review's Cancel Import.
|
||||
let escape = egui::Event::Key { key: egui::Key::Escape, physical_key: None, pressed: true, repeat: false, modifiers: Default::default() };
|
||||
let raw = egui::RawInput { screen_rect: Some(Rect::from_min_size(Pos2::ZERO, vec2(1600.0, 900.0))), events: vec![escape], ..Default::default() };
|
||||
crate::testing::part_frame(&mut app, &ctx, raw, |app, ui| app.ui(ui));
|
||||
app_frame(&ctx, &mut app, false);
|
||||
assert_eq!(review(&app), None, "the review closes");
|
||||
assert!(app.shortcuts_dialog.as_ref().is_some_and(|d| d.state.is_open()), "Keyboard Shortcuts shows again");
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
|
||||
|
||||
@@ -581,11 +581,16 @@ fn the_control_bar_label_follows_edits_undo_documents_and_selection() {
|
||||
assert!(!rect.contains("Linked File") && !rect.contains("Embedded"), "{rect}");
|
||||
}
|
||||
|
||||
/// Where the Control bar draws `label`; menu items are drawn after the space a check mark takes.
|
||||
fn label_at(app: &mut VectorcraftApp, ctx: &egui::Context, label: &str) -> egui::Pos2 {
|
||||
let texts = crate::tests_removeanchors::control_frame(app, ctx, vec![]);
|
||||
texts.iter().find(|(t, _)| t.trim() == label).map(|(_, r)| r.center()).unwrap_or_else(|| panic!("no `{label}` in {texts:?}"))
|
||||
}
|
||||
|
||||
/// Click the Control bar's `label`.
|
||||
fn click_label(app: &mut VectorcraftApp, ctx: &egui::Context, label: &str) {
|
||||
use crate::tests_removeanchors::{at, click_control, control_frame};
|
||||
let p = at(&control_frame(app, ctx, vec![]), label);
|
||||
click_control(app, ctx, p);
|
||||
let p = label_at(app, ctx, label);
|
||||
crate::tests_removeanchors::click_control(app, ctx, p);
|
||||
}
|
||||
|
||||
/// The Control bar's file name opens the link menu: Replace… puts the picked file in the image's
|
||||
@@ -593,12 +598,8 @@ fn click_label(app: &mut VectorcraftApp, ctx: &egui::Context, label: &str) {
|
||||
/// old bounds; Placement Options… opens its dialog.
|
||||
#[test]
|
||||
fn the_control_bars_file_name_relinks_the_image() {
|
||||
use crate::tests_removeanchors::{click_control, control_frame};
|
||||
// Menu items are drawn after the space a check mark takes.
|
||||
let item = |app: &mut VectorcraftApp, ctx: &egui::Context, label: &str| {
|
||||
let texts = control_frame(app, ctx, vec![]);
|
||||
texts.iter().find(|(t, _)| t.trim() == label).map(|(_, r)| r.center()).unwrap_or_else(|| panic!("no `{label}` in {texts:?}"))
|
||||
};
|
||||
use crate::tests_removeanchors::click_control;
|
||||
let item = label_at;
|
||||
let mut app = app();
|
||||
let data = vectorcraft_format::base64_encode(&png(30, 30, 72.0));
|
||||
app.run("file.place", json!({"name": "red.png", "dataBase64": data, "link": false})).unwrap();
|
||||
|
||||
@@ -1227,7 +1227,8 @@ fn row_context_menu_pick_from_swatches_and_limit_to_library() {
|
||||
}
|
||||
let before = field(&r, "rows");
|
||||
let expected = if empty_new { before[row]["from"][0].clone() } else { before[row]["to"].clone() };
|
||||
let at = rect(&r, &format!("Color {}", row + 1)).center();
|
||||
// The row's New chip, as production's right-click took it; `Color N` is the row's hex field.
|
||||
let at = rect(&r, &format!("New {}", row + 1)).center();
|
||||
right_click(&mut r, at);
|
||||
assert_eq!(field(&r, "__sel"), json!([row]), "right-click selects the targeted row");
|
||||
tap(&mut r, "Pick from Swatches");
|
||||
|
||||
@@ -10,7 +10,7 @@ use std::sync::Arc;
|
||||
use serde_json::{Value, json};
|
||||
use vectorcraft_engine::Session;
|
||||
|
||||
use super::picks::{self, Picker, answer_dialog, answer_replace, open_dialogs, replace_asked, scripted};
|
||||
use super::picks::{self, Picker, answer_dialog, answer_replace, cancel_dialog, open_dialogs, replace_asked, scripted};
|
||||
use crate::{Services, VectorcraftApp, io};
|
||||
|
||||
type Written = Rc<RefCell<Vec<String>>>;
|
||||
@@ -76,6 +76,9 @@ fn type_index(picker: &Picker, ext: &str) -> Option<usize> {
|
||||
fn answer_top(app: &mut VectorcraftApp, fields: &[(&str, Value)], ok: bool) {
|
||||
let id = open_dialogs(app).pop().map(|d| d.id).expect("a dialog is open");
|
||||
answer_dialog(app, id, fields, ok);
|
||||
if !ok {
|
||||
cancel_dialog(app, id);
|
||||
}
|
||||
}
|
||||
|
||||
/// A field of the top dialog, as automation lists it.
|
||||
@@ -83,9 +86,14 @@ fn top_field(app: &VectorcraftApp, field: &str) -> Option<Value> {
|
||||
open_dialogs(app).pop()?.fields?.get(field).cloned()
|
||||
}
|
||||
|
||||
/// The path the top dialog holds: the options of the format being written.
|
||||
/// The path the top dialog holds: the options of the format being written. Save PDF's dialog lists its options only;
|
||||
/// the file it writes is the app's job.
|
||||
fn dialog_path(app: &VectorcraftApp) -> Option<String> {
|
||||
top_field(app, "path")?.as_str().map(str::to_string)
|
||||
let top = open_dialogs(app).pop()?;
|
||||
if let Some(open) = app.save_pdf.as_ref().filter(|open| open.id == top.id) {
|
||||
return open.job.as_ref()?.path.clone();
|
||||
}
|
||||
top.fields?.get("path")?.as_str().map(str::to_string)
|
||||
}
|
||||
|
||||
/// Run `run`, which opens a save panel, and answer the panel with `path` and the file type with
|
||||
|
||||
@@ -287,6 +287,8 @@ fn a_click_goes_to_the_next_artboard_in_presentation_mode() {
|
||||
}
|
||||
let left = |pos, pressed| button(egui::PointerButton::Primary, pos, pressed);
|
||||
frame(&mut app, &ctx, vec![egui::Event::PointerMoved(middle), left(middle, true), left(middle, false)]);
|
||||
// The framework reports a release that came in the press's frame in the pass after it, which it asks the host for.
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
assert_eq!(view(&app).0, 2, "a click with the Rectangle tool, pressed and released in one frame");
|
||||
assert!(!app.any_dialog_open(), "opens no Rectangle dialog");
|
||||
settle(&mut app, &ctx);
|
||||
|
||||
@@ -21,6 +21,10 @@ struct App {
|
||||
/// The accessibility nodes of the latest frame, and the one with the keyboard.
|
||||
nodes: Vec<(NodeId, Node)>,
|
||||
focus: NodeId,
|
||||
/// The text on the platform's clipboard, which the host sends as a paste event in the frame after the app asks for
|
||||
/// it (`ViewportCommand::RequestPaste`), as egui-winit does.
|
||||
paste: Option<String>,
|
||||
asked_paste: bool,
|
||||
}
|
||||
|
||||
impl App {
|
||||
@@ -46,13 +50,18 @@ impl App {
|
||||
fn bare(app: VectorcraftApp) -> Self {
|
||||
let ctx = crate::testing::ui_context();
|
||||
ctx.enable_accesskit();
|
||||
Self { app, ctx, time: 0.0, focused: true, nodes: Vec::new(), focus: NodeId(0) }
|
||||
Self { app, ctx, time: 0.0, focused: true, nodes: Vec::new(), focus: NodeId(0), paste: None, asked_paste: false }
|
||||
}
|
||||
|
||||
/// One whole app frame with `events`, as the hosts run it; `menu`: a system menu item chosen first, as the macOS
|
||||
/// host dispatches it before the app's logic.
|
||||
fn frame_with(&mut self, events: Vec<Event>, menu: Option<&str>) -> egui::FullOutput {
|
||||
fn frame_with(&mut self, mut events: Vec<Event>, menu: Option<&str>) -> egui::FullOutput {
|
||||
self.time += 0.1;
|
||||
if std::mem::take(&mut self.asked_paste)
|
||||
&& let Some(text) = &self.paste
|
||||
{
|
||||
events.insert(0, Event::Paste(text.clone()));
|
||||
}
|
||||
let raw = egui::RawInput {
|
||||
events,
|
||||
time: Some(self.time),
|
||||
@@ -71,6 +80,7 @@ impl App {
|
||||
self.focus = update.focus;
|
||||
self.nodes = update.nodes;
|
||||
}
|
||||
self.asked_paste = out.viewport_output.values().any(|v| v.commands.contains(&egui::ViewportCommand::RequestPaste));
|
||||
out
|
||||
}
|
||||
|
||||
@@ -472,6 +482,7 @@ fn the_in_window_edit_menu_acts_on_the_field_it_was_opened_from() {
|
||||
let mut a = App::over(app);
|
||||
// Text on the system clipboard.
|
||||
super::sysclip::copy_elsewhere(&board, vec![(vectorcraft_engine::cmd::clipboard::TEXT, b"42 pt".to_vec())]);
|
||||
a.paste = Some("42 pt".into());
|
||||
let (id, rect) = a.field("37");
|
||||
a.frame(vec![Event::PointerMoved(rect.center()), click(rect.center(), true)]);
|
||||
a.frame(vec![click(rect.center(), false)]);
|
||||
@@ -496,7 +507,8 @@ fn the_in_window_edit_menu_acts_on_the_field_it_was_opened_from() {
|
||||
a.app.run("edit.copy", json!({})).unwrap();
|
||||
a.frame(vec![press(Key::A, Modifiers::COMMAND)]);
|
||||
menu(&mut a, edit, "Paste");
|
||||
assert_eq!(a.field_text(id), Some("42 pt"), "Paste pasted into the field");
|
||||
// The field holds the pasted text, its unit painted after it.
|
||||
assert!(a.field_text(id).is_some_and(|v| v.starts_with("42 pt")), "Paste pasted into the field: {:?}", a.field_text(id));
|
||||
assert_eq!(a.selected(), 1, "nothing pasted on the canvas");
|
||||
// With no field focused, the menu's Select All selects the art.
|
||||
a.frame(vec![press(Key::Escape, Modifiers::NONE)]);
|
||||
|
||||
@@ -683,6 +683,8 @@ fn a_paste_chord_into_type_waits_for_the_formats() {
|
||||
frame(app, events);
|
||||
}
|
||||
app.select_tool("selection");
|
||||
// The window draws the frame without the edit's editor, as a host does before the next click starts one.
|
||||
frame(app, vec![]);
|
||||
};
|
||||
let t = run(&mut app, "text.create", json!({"x": 20, "y": 250, "text": "Words"}))["id"].clone();
|
||||
run(&mut app, "select.set", json!({"ids": [t]}));
|
||||
|
||||
Reference in New Issue
Block a user