mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-03 15:21:17 -05:00
Panels m-z: Enter in Pattern Options' Name field ends the editing, the keys going to the document canvas. Tests as production drove them: Appearance rows are pressed and dragged past their link's text and an effect's name is clicked on its link, the weight and length fields read with their unit, the Move dialog's lengths read from its drawn field and typed there, the pie link takes the focus before Space, the artboard history keys follow a whole window frame, and art reaches the Symbols panel carried off the canvas, not from a Layers row (harness helpers: click_role_with, click_at_with, drag_between, rect_role, focus, shows_value_with)
This commit is contained in:
@@ -109,16 +109,19 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
_ => None,
|
||||
};
|
||||
let sized = def.size_tile_to_art;
|
||||
let canvas = crate::doc_windows::current(app).map(crate::canvas::canvas_id);
|
||||
FieldGroup::new(tl!("Pattern Options")).show(ui, |ui, _| {
|
||||
// Name commits on Enter or focus loss; Shift+Enter commits too and keeps the focus, so the
|
||||
// renamed pattern's name stays selected for the next edit.
|
||||
// renamed pattern's name stays selected for the next edit. Enter ends the editing: the keys go
|
||||
// to the document canvas, as with nothing focused.
|
||||
row(ui, tl!("Name:"), |ui, label| {
|
||||
let edit = TextField::new(label.to_owned(), Bind::given(def.name.clone())).submits().select_on_focus().show(ui);
|
||||
if let Some(new) = edit.events.committed().map(|s| s.trim()).filter(|s| !s.is_empty() && *s != def.name) {
|
||||
edits.push(json!({ "newName": new }));
|
||||
}
|
||||
if edit.submitted && edit.submit_mods.shift {
|
||||
focus::request(ui.ctx(), FocusTarget::Id(edit.response.id));
|
||||
let next = if edit.submit_mods.shift { Some(edit.response.id) } else { canvas };
|
||||
if let Some(id) = next.filter(|_| edit.submitted) {
|
||||
focus::request(ui.ctx(), FocusTarget::Id(id));
|
||||
}
|
||||
});
|
||||
let tile = TileType::IDS.iter().position(|i| *i == def.tile_type.id()).unwrap_or(0);
|
||||
|
||||
@@ -439,8 +439,10 @@ fn artboard_history_new(panel: &mut Panel) {
|
||||
}
|
||||
|
||||
/// A key through the app's whole frame, as the window delivers it, so Undo and deletion take the
|
||||
/// route they take in production.
|
||||
/// route they take in production. A whole frame comes first: the key goes where the window's frame
|
||||
/// before it showed the canvas, not the panel's.
|
||||
fn artboard_history_key(panel: &mut Panel, ctx: &egui::Context, key: Key, modifiers: Modifiers) {
|
||||
key_frame(&mut panel.app(), ctx, vec![]);
|
||||
for pressed in [true, false] {
|
||||
let events = vec![Event::ModifiersChanged(modifiers), Event::Key { key, physical_key: None, pressed, repeat: false, modifiers }];
|
||||
key_frame(&mut panel.app(), ctx, events);
|
||||
|
||||
@@ -86,10 +86,28 @@ fn panel(app: VectorcraftApp) -> Panel {
|
||||
harness(app, show)
|
||||
}
|
||||
|
||||
/// The Layers panel above the Symbols panel: art dragged from a Layers row carries its objects
|
||||
/// (`PanelDrag::Art`), as production's art drags do.
|
||||
fn layers_and_symbols(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
ui.allocate_ui(vec2(ui.available_width(), 500.0), |ui| super::super::layers::show(app, ui));
|
||||
/// Art carried off the canvas above the Symbols panel: a row for each named object (a layer too), whose drag
|
||||
/// carries that object (`PanelDrag::Art`) as a move carried off the canvas does; production's tests set that
|
||||
/// payload too, as no panel row carries art.
|
||||
fn art_and_symbols(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
use craft::ui::contract::{ListDrag, ShowCollection as _};
|
||||
if let Some(st) = app.session.active() {
|
||||
let document = st.uid;
|
||||
let mut named = Vec::new();
|
||||
st.doc.walk(|n| {
|
||||
if let Some(name) = &n.name {
|
||||
named.push((name.clone(), n.id));
|
||||
}
|
||||
});
|
||||
let keys: Vec<usize> = (0..named.len()).collect();
|
||||
let rows = craft::behavior::keyed(&keys, |key: &usize| *key);
|
||||
let ids: Vec<NodeId> = named.iter().map(|(_, id)| *id).collect();
|
||||
ui.allocate_ui(vec2(ui.available_width(), 200.0), |ui| {
|
||||
let _ = craft::ui::list::List::<usize>::new("Art off the canvas")
|
||||
.drag_payload(move |drag: &ListDrag<usize>| ids.get(drag.grabbed).map(|id| PanelDrag::Art { document, ids: vec![*id] }))
|
||||
.show_items(ui, &rows, &mut |key, _| craft::ui::list::ListRow::new(named[*key].0.clone()));
|
||||
});
|
||||
}
|
||||
show(app, ui);
|
||||
}
|
||||
|
||||
@@ -417,7 +435,7 @@ fn drop_to_command() {
|
||||
let mut app = setup();
|
||||
app.run("ui.panelView", json!({"panel": "symbols", "view": view})).unwrap();
|
||||
let undo = undo_len(&app);
|
||||
let mut p = harness(app, layers_and_symbols);
|
||||
let mut p = harness(app, art_and_symbols);
|
||||
p.drag(from, to, mods);
|
||||
check(&mut p, undo, &format!("{what}, {view}"));
|
||||
}
|
||||
@@ -1546,7 +1564,7 @@ fn alt_art_drop_on_a_symbol_redefines_that_symbol_in_one_step() {
|
||||
let (app, _, placed) = alt_drop_doc(view);
|
||||
let (leaf, dot) = (symbol_art(&app, "Leaf"), symbol_art(&app, "Dot"));
|
||||
let undo = undo_len(&app);
|
||||
let mut p = harness(app, layers_and_symbols);
|
||||
let mut p = harness(app, art_and_symbols);
|
||||
p.drag("Art", "Leaf", Modifiers::ALT);
|
||||
let mut app = p.app();
|
||||
assert_eq!(symbols(&mut app), ["Leaf", "Dot"], "{view}: no symbol added");
|
||||
@@ -1573,7 +1591,7 @@ fn an_alt_art_drop_that_cannot_redefine_changes_nothing() {
|
||||
let (app, _, _) = alt_drop_doc("thumbnail");
|
||||
let leaf = symbol_art(&app, "Leaf");
|
||||
let undo = undo_len(&app);
|
||||
let mut p = harness(app, layers_and_symbols);
|
||||
let mut p = harness(app, art_and_symbols);
|
||||
let cases = [("a Leaf instance", "Placed", "Leaf"), ("a layer", "Layer 1", "Leaf"), ("art released outside the list", "Art", "Symbol Options")];
|
||||
for (case, from, to) in cases {
|
||||
p.drag(from, to, Modifiers::ALT);
|
||||
|
||||
@@ -10,6 +10,7 @@ use vectorcraft_engine::Session;
|
||||
use super::*;
|
||||
use crate::tests::panel_harness::Panel;
|
||||
use crate::tests::synthetic::key_frame;
|
||||
use craft::ui::contract::Role;
|
||||
|
||||
pub(super) fn app_with_rect() -> VectorcraftApp {
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()));
|
||||
@@ -171,7 +172,7 @@ fn stroke_panel_shows_the_active_rows_weight() {
|
||||
let mut app = app_with_rect();
|
||||
run(&mut app, "appearance.addStroke", json!({})); // [Fill, Stroke 1 pt, Stroke 1 pt]
|
||||
run(&mut app, "stroke.set", json!({"item": 1, "weight": 6}));
|
||||
let six = Unit::Points.number(6.0);
|
||||
let six = Unit::Points.format(6.0);
|
||||
let mut panel = Panel::new(app, stroke::show);
|
||||
// PLAN: assumed the weight field's accessible name
|
||||
let weight = |panel: &mut Panel| {
|
||||
@@ -353,17 +354,38 @@ fn stack_items(app: &VectorcraftApp) -> Vec<(bool, Option<f32>)> {
|
||||
const DELETE: &str = "Delete Selected Item";
|
||||
const DUPLICATE: &str = "Duplicate Selected Item";
|
||||
|
||||
/// A point of the row named by the link `name`, past the link's text: a press on the link follows it, so
|
||||
/// production's tests pressed rows there.
|
||||
pub(super) fn row_spot(panel: &mut Panel, name: &str) -> egui::Pos2 {
|
||||
panel.frame();
|
||||
let link = panel.rect_role(name, Role::LINK);
|
||||
egui::pos2(link.right() + 8.0, link.center().y)
|
||||
}
|
||||
|
||||
/// Clicks the row named by the link `name` past its text, with `mods` held.
|
||||
pub(super) fn click_row(panel: &mut Panel, name: &str, mods: egui::Modifiers) {
|
||||
let at = row_spot(panel, name);
|
||||
panel.click_at_with(at, mods);
|
||||
}
|
||||
|
||||
/// Drags the row named by the link `from`, pressed past its text, onto the control named `to`.
|
||||
pub(super) fn drag_row(panel: &mut Panel, from: &str, to: &str, mods: egui::Modifiers) {
|
||||
let from = row_spot(panel, from);
|
||||
let to = panel.rect(to).center();
|
||||
panel.drag_between(from, to, mods);
|
||||
}
|
||||
|
||||
/// "drop on footer button": fill and stroke rows dropped on Delete Selected Item are removed, on
|
||||
/// Duplicate Selected Item copied, as rows dropped on the Layers panel's buttons are.
|
||||
#[test]
|
||||
fn rows_dropped_on_delete_are_removed_and_on_duplicate_copied() {
|
||||
// [Fill, Stroke]: dropping the stroke on Delete leaves the fill.
|
||||
let mut panel = appearance_panel(app_with_rect(), &[]);
|
||||
panel.drag("Stroke:", DELETE, egui::Modifiers::NONE);
|
||||
drag_row(&mut panel, "Stroke:", DELETE, egui::Modifiers::NONE);
|
||||
assert_eq!(stack_items(&panel.app()), [(true, None)]);
|
||||
// Dropping the fill on Duplicate adds one copy of it.
|
||||
let mut panel = appearance_panel(app_with_rect(), &[]);
|
||||
panel.drag("Fill:", DUPLICATE, egui::Modifiers::NONE);
|
||||
drag_row(&mut panel, "Fill:", DUPLICATE, egui::Modifiers::NONE);
|
||||
let items = stack_items(&panel.app());
|
||||
assert_eq!(items.iter().filter(|(f, _)| *f).count(), 2, "{items:?}");
|
||||
assert_eq!(items.len(), 3, "{items:?}");
|
||||
@@ -378,23 +400,23 @@ fn dropping_a_selected_row_acts_on_the_selection() {
|
||||
let mut app = app_with_rect();
|
||||
run(&mut app, "effect.apply", json!({"effect": "distort.twist", "item": null}));
|
||||
let mut panel = appearance_panel(app, &[]);
|
||||
panel.click_with("Stroke:", egui::Modifiers::NONE);
|
||||
panel.click_with("Fill:", egui::Modifiers::COMMAND);
|
||||
click_row(&mut panel, "Stroke:", egui::Modifiers::NONE);
|
||||
click_row(&mut panel, "Fill:", egui::Modifiers::COMMAND);
|
||||
panel
|
||||
};
|
||||
// The stroke is in the selection: the fill and the stroke go, Twist stays.
|
||||
let mut panel = setup();
|
||||
panel.drag("Stroke:", DELETE, egui::Modifiers::NONE);
|
||||
drag_row(&mut panel, "Stroke:", DELETE, egui::Modifiers::NONE);
|
||||
assert!(stack_items(&panel.app()).is_empty());
|
||||
assert_eq!(object_effects(&panel.app()), ["distort.twist"]);
|
||||
// Twist is not: only it goes.
|
||||
let mut panel = setup();
|
||||
panel.drag("Twist", DELETE, egui::Modifiers::NONE);
|
||||
drag_row(&mut panel, "Twist", DELETE, egui::Modifiers::NONE);
|
||||
assert_eq!(stack_items(&panel.app()).len(), 2);
|
||||
assert!(object_effects(&panel.app()).is_empty());
|
||||
// Onto Duplicate, the selected rows are both copied.
|
||||
let mut panel = setup();
|
||||
panel.drag("Stroke:", DUPLICATE, egui::Modifiers::NONE);
|
||||
drag_row(&mut panel, "Stroke:", DUPLICATE, egui::Modifiers::NONE);
|
||||
assert_eq!(stack_items(&panel.app()).len(), 4);
|
||||
}
|
||||
|
||||
@@ -429,9 +451,9 @@ fn contents_rows_and_drops_elsewhere_change_nothing() {
|
||||
panel.drag("Contents", button, egui::Modifiers::NONE);
|
||||
assert_eq!(first_selected(&panel.app()).unwrap().appearance, before, "{button}");
|
||||
}
|
||||
panel.drag("Fill:", "Contents", egui::Modifiers::NONE);
|
||||
drag_row(&mut panel, "Fill:", "Contents", egui::Modifiers::NONE);
|
||||
assert_eq!(first_selected(&panel.app()).unwrap().appearance, before);
|
||||
panel.drag("Fill:", DELETE, egui::Modifiers::NONE);
|
||||
drag_row(&mut panel, "Fill:", DELETE, egui::Modifiers::NONE);
|
||||
assert!(first_selected(&panel.app()).unwrap().appearance.items.is_empty());
|
||||
}
|
||||
|
||||
@@ -470,8 +492,8 @@ fn ctrl_clicking_an_effect_of_another_list_starts_a_new_selection() {
|
||||
let mut app = rect_with_three_effects();
|
||||
run(&mut app, "effect.apply", json!({"effect": "distort.roughen", "item": 1}));
|
||||
let mut panel = appearance_panel(app, &[appearance::RowKey::Item(1)]);
|
||||
panel.click_with("Outer Glow", egui::Modifiers::NONE);
|
||||
panel.click_with("Roughen", egui::Modifiers::COMMAND);
|
||||
click_row(&mut panel, "Outer Glow", egui::Modifiers::NONE);
|
||||
click_row(&mut panel, "Roughen", egui::Modifiers::COMMAND);
|
||||
panel.click(DELETE);
|
||||
assert!(current_stroke_effects(&panel.app()).is_empty());
|
||||
assert_eq!(object_effects(&panel.app()).len(), 3);
|
||||
@@ -482,9 +504,9 @@ fn ctrl_clicking_an_effect_of_another_list_starts_a_new_selection() {
|
||||
#[test]
|
||||
fn alt_dragging_highlighted_effects_copies_them_together() {
|
||||
let mut panel = appearance_panel(rect_with_three_effects(), &[]);
|
||||
panel.click_with("Outer Glow", egui::Modifiers::NONE);
|
||||
panel.click_with("Twist", egui::Modifiers::COMMAND);
|
||||
panel.drag("Outer Glow", "Stroke:", egui::Modifiers::ALT);
|
||||
click_row(&mut panel, "Outer Glow", egui::Modifiers::NONE);
|
||||
click_row(&mut panel, "Twist", egui::Modifiers::COMMAND);
|
||||
drag_row(&mut panel, "Outer Glow", "Stroke:", egui::Modifiers::ALT);
|
||||
let ids: Vec<_> = current_stroke_effects(&panel.app()).iter().map(|e| e.id.clone()).collect();
|
||||
assert_eq!(ids, ["stylize.outerGlow", "distort.twist"]);
|
||||
assert_eq!(object_effects(&panel.app()).len(), 3, "the originals stay");
|
||||
@@ -496,7 +518,7 @@ fn alt_dragging_highlighted_effects_copies_them_together() {
|
||||
fn an_effects_name_edits_it_and_its_empty_space_highlights_it() {
|
||||
for m in [egui::Modifiers::NONE, egui::Modifiers::COMMAND, egui::Modifiers::SHIFT] {
|
||||
let mut panel = appearance_panel(rect_with_three_effects(), &[]);
|
||||
panel.click_with("Outer Glow", m);
|
||||
panel.click_role_with("Outer Glow", Role::LINK, m);
|
||||
assert!(dialog_open(&panel.app()), "{m:?}: a click on the name opens the dialog");
|
||||
}
|
||||
// PLAN: the row's empty space has no name, so the single Ctrl-click and the double-click there need a point driver on op.A15
|
||||
@@ -517,7 +539,7 @@ fn transform_effect_name_edits_the_displayed_appearance_target() {
|
||||
let target = app.session.doc().unwrap().selection.subjects()[0];
|
||||
app.run("effect.apply", json!({"effect": "distort.transform", "item": null, "params": {"moveH": 12}})).unwrap();
|
||||
let mut panel = Panel::new(app, appearance::show);
|
||||
panel.click("Transform");
|
||||
panel.click_role("Transform", Role::LINK);
|
||||
let mut app = panel.app();
|
||||
assert!(dialog_open(&app), "Transform did not open for {target_kind}");
|
||||
assert_eq!(dialog_number(&mut app, "moveH"), 12.0);
|
||||
@@ -781,7 +803,7 @@ fn transform_effect_preview_commit_cancel_and_undo_cover_artwork_targets() {
|
||||
if let Some(i) = item {
|
||||
panel.click(if i == 0 { "Expand Fill" } else { "Expand Stroke" });
|
||||
}
|
||||
panel.click("Transform");
|
||||
panel.click_role("Transform", Role::LINK);
|
||||
let mut app = panel.app();
|
||||
assert!(dialog_open(&app), "{kind}: dialog did not open");
|
||||
set_dialog(&mut app, "moveH", json!(40));
|
||||
@@ -907,7 +929,7 @@ fn an_opacity_row_cannot_be_deleted_duplicated_or_dragged() {
|
||||
let mut panel = appearance_panel(app, &[appearance::RowKey::Item(1)]);
|
||||
panel.frame();
|
||||
assert!(!panel.enabled(DUPLICATE), "Duplicate is greyed out");
|
||||
panel.drag("Opacity:", "Fill:", egui::Modifiers::NONE);
|
||||
drag_row(&mut panel, "Opacity:", "Fill:", egui::Modifiers::NONE);
|
||||
assert_eq!(stack_items(&panel.app()), before, "dragged: nothing moves");
|
||||
panel.key(egui::Key::Delete, egui::Modifiers::NONE);
|
||||
assert!(first_selected(&panel.app()).is_some(), "the object stays");
|
||||
@@ -1003,9 +1025,9 @@ fn the_stroke_weight_field_edits_with_or_without_a_selection() {
|
||||
fn a_drop_on_delete_that_removes_the_active_effect_leaves_no_effect_active() {
|
||||
let mut panel = appearance_panel(rect_with_three_effects(), &[]);
|
||||
// Drop Shadow, then Outer Glow with Ctrl: both highlighted, Outer Glow active.
|
||||
panel.click_with("Drop Shadow", egui::Modifiers::NONE);
|
||||
panel.click_with("Outer Glow", egui::Modifiers::COMMAND);
|
||||
panel.drag("Drop Shadow", DELETE, egui::Modifiers::NONE);
|
||||
click_row(&mut panel, "Drop Shadow", egui::Modifiers::NONE);
|
||||
click_row(&mut panel, "Outer Glow", egui::Modifiers::COMMAND);
|
||||
drag_row(&mut panel, "Drop Shadow", DELETE, egui::Modifiers::NONE);
|
||||
assert_eq!(object_effects(&panel.app()), ["distort.twist"]);
|
||||
panel.click(DELETE);
|
||||
assert_eq!(object_effects(&panel.app()), ["distort.twist"], "Twist was never highlighted");
|
||||
@@ -1018,9 +1040,9 @@ fn a_drop_on_delete_that_removes_the_active_effect_leaves_no_effect_active() {
|
||||
fn a_drop_on_delete_above_the_active_effect_keeps_the_highlight_on_its_rows() {
|
||||
let mut panel = appearance_panel(rect_with_three_effects(), &[]);
|
||||
// Drop Shadow, then Twist with Ctrl: both highlighted, Twist active.
|
||||
panel.click_with("Drop Shadow", egui::Modifiers::NONE);
|
||||
panel.click_with("Twist", egui::Modifiers::COMMAND);
|
||||
panel.drag("Outer Glow", DELETE, egui::Modifiers::NONE);
|
||||
click_row(&mut panel, "Drop Shadow", egui::Modifiers::NONE);
|
||||
click_row(&mut panel, "Twist", egui::Modifiers::COMMAND);
|
||||
drag_row(&mut panel, "Outer Glow", DELETE, egui::Modifiers::NONE);
|
||||
assert_eq!(object_effects(&panel.app()), ["stylize.dropShadow", "distort.twist"]);
|
||||
panel.click(DELETE);
|
||||
assert!(object_effects(&panel.app()).is_empty(), "both highlighted effects removed: {:?}", object_effects(&panel.app()));
|
||||
@@ -1164,8 +1186,8 @@ fn reduce_to_basic_enabled_when_any_selected_subject_needs_reduction() {
|
||||
#[test]
|
||||
fn right_clicking_multi_selected_items_shows_plural_duplicate_and_delete() {
|
||||
let mut panel = appearance_panel(app_with_rect(), &[]);
|
||||
panel.click_with("Stroke:", egui::Modifiers::NONE);
|
||||
panel.click_with("Fill:", egui::Modifiers::COMMAND);
|
||||
click_row(&mut panel, "Stroke:", egui::Modifiers::NONE);
|
||||
click_row(&mut panel, "Fill:", egui::Modifiers::COMMAND);
|
||||
panel.secondary_click("Stroke:");
|
||||
assert!(panel.shows("Duplicate Items") && panel.shows("Delete Items"));
|
||||
panel.click("Duplicate Items");
|
||||
|
||||
@@ -6,7 +6,8 @@ use craft::ui::dialog::PromptChoice;
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use super::tests_appearance::{
|
||||
answer_prompt, app_frame, app_with_rect, cancel_dialog, confirm_dialog, dialog_json, dialog_number, dialog_open, run, set_dialog,
|
||||
answer_prompt, app_frame, app_with_rect, cancel_dialog, click_row, confirm_dialog, dialog_json, dialog_number, dialog_open, drag_row, row_spot,
|
||||
run, set_dialog,
|
||||
};
|
||||
use super::*;
|
||||
use crate::tests::panel_harness::Panel;
|
||||
@@ -20,7 +21,7 @@ fn an_effect_name_opens_its_dialog_prefilled_and_ok_edits_it_in_place() {
|
||||
let mut app = app_with_rect();
|
||||
run(&mut app, "effect.apply", json!({"effect": "distort.roughen", "params": {"size": 9}}));
|
||||
let mut panel = Panel::new(app, appearance::show);
|
||||
panel.click("Roughen");
|
||||
panel.click_role("Roughen", craft::ui::contract::Role::LINK);
|
||||
let mut app = panel.app();
|
||||
assert!(dialog_open(&app), "the effect's dialog");
|
||||
assert_eq!(dialog_number(&mut app, "size"), 9.0);
|
||||
@@ -132,10 +133,11 @@ fn effect_rows_drag_to_reorder_and_into_an_item() {
|
||||
run(&mut app, "effect.apply", json!({"effect": "distort.roughen"}));
|
||||
let mut panel = Panel::new(app, appearance::show);
|
||||
let ids = |fx: Vec<vectorcraft_doc::Effect>| fx.into_iter().map(|e| e.id).collect::<Vec<_>>();
|
||||
// PLAN: assumes a drop on a lower row lands below it (`reorder_command`, appearance-w6)
|
||||
panel.drag("Twist", "Roughen", egui::Modifiers::NONE);
|
||||
// Twist below Roughen: dropped on the lower half of its row.
|
||||
let (twist, below) = (row_spot(&mut panel, "Twist"), row_spot(&mut panel, "Roughen") + egui::vec2(0.0, 6.0));
|
||||
panel.drag_between(twist, below, egui::Modifiers::NONE);
|
||||
assert_eq!(ids(effects(&panel.app(), None)), ["distort.roughen", "distort.twist"]);
|
||||
panel.drag("Twist", "Stroke:", egui::Modifiers::ALT);
|
||||
drag_row(&mut panel, "Twist", "Stroke:", egui::Modifiers::ALT);
|
||||
assert_eq!(ids(effects(&panel.app(), None)), ["distort.roughen", "distort.twist"]);
|
||||
assert_eq!(ids(effects(&panel.app(), Some(1))), ["distort.twist"]);
|
||||
// Dropped effects become the selected row (their item active).
|
||||
@@ -150,11 +152,11 @@ fn effect_rows_drag_to_reorder_and_into_an_item() {
|
||||
fn alt_dragging_an_item_duplicates_it_and_several_items_delete_together() {
|
||||
let mut panel = Panel::new(app_with_rect(), appearance::show); // [Fill, Stroke]
|
||||
let kinds = |panel: &Panel| first_selected(&panel.app()).unwrap().appearance.items.iter().map(|i| i.kind_name()).collect::<Vec<_>>();
|
||||
panel.drag("Fill:", "Stroke:", egui::Modifiers::ALT);
|
||||
drag_row(&mut panel, "Fill:", "Stroke:", egui::Modifiers::ALT);
|
||||
assert_eq!(kinds(&panel), ["fill", "stroke", "fill"]);
|
||||
// Click the stroke, Cmd-click a fill (the harness takes the topmost): both go.
|
||||
panel.click_with("Stroke:", egui::Modifiers::NONE);
|
||||
panel.click_with("Fill:", egui::Modifiers::COMMAND);
|
||||
click_row(&mut panel, "Stroke:", egui::Modifiers::NONE);
|
||||
click_row(&mut panel, "Fill:", egui::Modifiers::COMMAND);
|
||||
panel.key(egui::Key::Delete, egui::Modifiers::NONE);
|
||||
assert_eq!(kinds(&panel), ["fill"]);
|
||||
run(&mut panel.app(), "edit.undo", json!({}));
|
||||
|
||||
@@ -41,7 +41,7 @@ fn mixed_weights_show_blank() {
|
||||
assert_eq!(panel.value("Weight").unwrap_or_default(), "");
|
||||
run(&mut panel.app(), "select.set", json!({ "ids": [b] }));
|
||||
panel.frame();
|
||||
assert_eq!(panel.value("Weight").as_deref(), Some("3"), "the cache follows the selection");
|
||||
assert_eq!(panel.value("Weight"), Some(vectorcraft_doc::Unit::Points.format(3.0)), "the cache follows the selection");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -24,11 +24,6 @@ fn with_dialog<R>(app: &VectorcraftApp, f: impl FnOnce(&mut HostedParamDialog, &
|
||||
app.dialogs()?.with(|host| host.get_mut::<HostedParamDialog>().map(|d| f(d, &ctx)))
|
||||
}
|
||||
|
||||
/// The open hosted dialog's field `name`, as the dialog shows it.
|
||||
pub(crate) fn dialog_field(app: &mut VectorcraftApp, name: &str) -> Option<Value> {
|
||||
with_dialog(app, |d, _| d.json_fields()?.get(name).cloned()).flatten()
|
||||
}
|
||||
|
||||
/// Sets the open hosted dialog's field `name`, as typing in it does.
|
||||
pub(crate) fn set_dialog_field(app: &mut VectorcraftApp, name: &str, value: Value) {
|
||||
let set = with_dialog(app, |d, ctx| d.set_json_field(ctx, name, value));
|
||||
@@ -64,11 +59,12 @@ fn side_mm() -> String {
|
||||
}
|
||||
|
||||
/// Whether a length field's `value` reads `pt` points in `unit`, to the decimals it shows: a length field's value is
|
||||
/// its number, with the unit painted after it.
|
||||
/// its number and the unit's suffix painted after it, as [`Unit::format`] writes them.
|
||||
pub(crate) fn reads(value: Option<String>, unit: Unit, pt: f64) -> bool {
|
||||
value.is_some_and(|v| {
|
||||
let decimals = v.split_once('.').map_or(0, |(_, d)| d.len());
|
||||
v.parse::<f64>().is_ok_and(|shown| (shown - unit.from_pt(pt)).abs() <= 0.5 * 10f64.powi(-(decimals as i32)) + 1e-9)
|
||||
let Some(number) = v.strip_suffix(unit.suffix()).map(str::trim_end) else { return false };
|
||||
let decimals = number.split_once('.').map_or(0, |(_, d)| d.len());
|
||||
number.parse::<f64>().is_ok_and(|shown| (shown - unit.from_pt(pt)).abs() <= 0.5 * 10f64.powi(-(decimals as i32)) + 1e-9)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -98,22 +94,39 @@ fn panels_show_millimetres_after_the_preference_changes() {
|
||||
fn dialog_lengths_show_in_the_general_unit() {
|
||||
let mut app = app_with_rect();
|
||||
general_mm(&mut app);
|
||||
run_menu(&mut app, "object.move");
|
||||
assert_eq!(dialog_field(&mut app, "dx"), Some(json!(Unit::Millimeters.format(0.0))), "Move");
|
||||
// The dialog keeps its lengths in points; its fields draw them in the unit, so the window draws it.
|
||||
let mut window = Panel::new(app, |app, ui| app.ui(ui));
|
||||
window.room(egui::vec2(1440.0, 900.0));
|
||||
run_menu(&mut window.app(), "object.move");
|
||||
window.frame();
|
||||
assert!(reads(window.value("Horizontal"), Unit::Millimeters, 0.0), "Move: {:?}", window.value("Horizontal"));
|
||||
// A typed unit wins; the move is in points.
|
||||
set_dialog_field(&mut app, "dx", json!("10 mm"));
|
||||
confirm_dialog(&mut app);
|
||||
let st = app.session.active().unwrap();
|
||||
let b = st.doc.bounds_of(&st.selection.objects, false).unwrap();
|
||||
assert!((b.x0 - (10.0 + 10.0 * 72.0 / 25.4)).abs() < 1e-6, "{b:?}");
|
||||
// A shape tool's size dialog and an effect's distances.
|
||||
crate::dialogs::open_tool_dialog(&mut app, "rectangle", json!({"x": 0, "y": 0}));
|
||||
assert_eq!(dialog_field(&mut app, "width"), Some(json!(side_mm())), "Rectangle");
|
||||
cancel_dialog(&mut app);
|
||||
app.run("effect.dialog", json!({"effect": "stylize.dropShadow"})).unwrap();
|
||||
window.focus("Horizontal");
|
||||
window.key(egui::Key::A, egui::Modifiers::COMMAND);
|
||||
window.type_text("10 mm");
|
||||
window.key(egui::Key::Tab, egui::Modifiers::NONE);
|
||||
confirm_dialog(&mut window.app());
|
||||
let square = {
|
||||
let app = window.app();
|
||||
let st = app.session.active().unwrap();
|
||||
let b = st.doc.bounds_of(&st.selection.objects, false).unwrap();
|
||||
assert!((b.x0 - (10.0 + 10.0 * 72.0 / 25.4)).abs() < 1e-6, "{b:?}");
|
||||
st.selection.objects[0].0
|
||||
};
|
||||
// A shape tool's size dialog and an effect's distances, drawn in the window. The Control bar and the panels name
|
||||
// their fields as the dialogs do, so the dialog shows its length where nothing selected shows the same one.
|
||||
run(&mut window.app(), "select.set", json!({"ids": []}));
|
||||
crate::dialogs::open_tool_dialog(&mut window.app(), "rectangle", json!({"x": 0, "y": 0}));
|
||||
window.frame();
|
||||
let shows_mm = |window: &Panel, pt: f64| window.shows_value_with(|v| reads(Some(v.to_owned()), Unit::Millimeters, pt));
|
||||
assert!(shows_mm(&window, 100.0), "Rectangle");
|
||||
cancel_dialog(&mut window.app());
|
||||
run(&mut window.app(), "select.set", json!({"ids": [square]}));
|
||||
window.app().run("effect.dialog", json!({"effect": "stylize.dropShadow"})).unwrap();
|
||||
window.frame();
|
||||
let x = vectorcraft_effects::default_params("stylize.dropShadow").unwrap()["x"].as_f64().unwrap();
|
||||
assert_eq!(dialog_field(&mut app, "x"), Some(json!(Unit::Millimeters.format(x))), "Drop Shadow");
|
||||
cancel_dialog(&mut app);
|
||||
assert!(shows_mm(&window, x), "Drop Shadow");
|
||||
cancel_dialog(&mut window.app());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -274,7 +274,8 @@ fn the_constrain_pie_angle_link_keeps_the_span() {
|
||||
let mut p = panel(app);
|
||||
p.click(LINK);
|
||||
assert!(p.app().ui.constrain_pie_angle, "a click turns it on");
|
||||
// The click left the focus on the link.
|
||||
// A click leaves the focus where it was, so the link takes it first, as production's test gave it.
|
||||
p.focus(LINK);
|
||||
p.key(egui::Key::Space, egui::Modifiers::NONE);
|
||||
assert!(!p.app().ui.constrain_pie_angle, "Space turns it off");
|
||||
p.click(LINK);
|
||||
|
||||
@@ -126,11 +126,28 @@ impl Panel {
|
||||
/// Clicks the control of `role` named `name`, where nodes of other roles share the name (a section's region,
|
||||
/// heading and disclosure button).
|
||||
pub(crate) fn click_role(&mut self, name: &str, role: craft::ui::contract::Role) {
|
||||
self.click_role_with(name, role, Modifiers::NONE);
|
||||
}
|
||||
|
||||
/// [`Panel::click_role`] with `mods` held.
|
||||
pub(crate) fn click_role_with(&mut self, name: &str, role: craft::ui::contract::Role, mods: Modifiers) {
|
||||
self.frame();
|
||||
let target = self.look_role(name, role);
|
||||
self.fixture.hold(mods).click(&target).hold(Modifiers::NONE);
|
||||
self.after();
|
||||
}
|
||||
|
||||
/// The control of `role` named `name` in the latest frame, where nodes of other roles share the name.
|
||||
fn look_role(&self, name: &str, role: craft::ui::contract::Role) -> Target {
|
||||
let tree = self.fixture.tree();
|
||||
let target = self.fixture.by_role(role).into_iter().find(|t| tree.name_of(t.node) == Some(name));
|
||||
let target = target.unwrap_or_else(|| panic!("no {role:?} named {name:?} in {:?}", self.names()));
|
||||
self.fixture.click(&target);
|
||||
target.unwrap_or_else(|| panic!("no {role:?} named {name:?} in {:?}", self.names()))
|
||||
}
|
||||
|
||||
/// Gives the control named `name` the keyboard focus, as a screen reader's Focus action does.
|
||||
pub(crate) fn focus(&mut self, name: &str) {
|
||||
let target = self.find(name);
|
||||
self.fixture.access(craft::ui::testing::focus::AccessActionKind::Focus, &target);
|
||||
self.after();
|
||||
}
|
||||
|
||||
@@ -143,7 +160,12 @@ impl Panel {
|
||||
|
||||
/// Clicks at `pos`, where no control needs to be.
|
||||
pub(crate) fn click_at(&mut self, pos: Pos2) {
|
||||
self.fixture.click_at(pos);
|
||||
self.click_at_with(pos, Modifiers::NONE);
|
||||
}
|
||||
|
||||
/// Clicks at `pos` with `mods` held, where no control needs to be (a row's room past its link).
|
||||
pub(crate) fn click_at_with(&mut self, pos: Pos2, mods: Modifiers) {
|
||||
self.fixture.hold(mods).click_at(pos).hold(Modifiers::NONE);
|
||||
self.after();
|
||||
}
|
||||
|
||||
@@ -165,9 +187,7 @@ impl Panel {
|
||||
/// the name (a slider beside its number box).
|
||||
pub(crate) fn drag_hold_role(&mut self, name: &str, role: craft::ui::contract::Role, by: Vec2) {
|
||||
self.frame();
|
||||
let tree = self.fixture.tree();
|
||||
let target = self.fixture.by_role(role).into_iter().find(|t| tree.name_of(t.node) == Some(name));
|
||||
let target = target.unwrap_or_else(|| panic!("no {name:?} of the role in {:?}", self.names()));
|
||||
let target = self.look_role(name, role);
|
||||
self.fixture.drag_hold_at(target.center(), by);
|
||||
self.after();
|
||||
}
|
||||
@@ -211,8 +231,14 @@ impl Panel {
|
||||
|
||||
/// Drags from the control named `from` and releases at `to`.
|
||||
pub(crate) fn drag_to(&mut self, from: &str, to: Pos2, mods: Modifiers) {
|
||||
let from = self.find(from);
|
||||
self.fixture.hold(mods).drag(&from, to - from.center()).hold(Modifiers::NONE);
|
||||
let from = self.find(from).center();
|
||||
self.drag_between(from, to, mods);
|
||||
}
|
||||
|
||||
/// Drags from `from` and releases at `to` with `mods` held, where no control needs to be at `from` (a row's room
|
||||
/// past its link).
|
||||
pub(crate) fn drag_between(&mut self, from: Pos2, to: Pos2, mods: Modifiers) {
|
||||
self.fixture.hold(mods).drag_at(from, to - from).hold(Modifiers::NONE);
|
||||
self.after();
|
||||
}
|
||||
|
||||
@@ -272,6 +298,11 @@ impl Panel {
|
||||
self.look(name).rect
|
||||
}
|
||||
|
||||
/// Where the control of `role` named `name` is, where nodes of other roles share the name.
|
||||
pub(crate) fn rect_role(&self, name: &str, role: craft::ui::contract::Role) -> Rect {
|
||||
self.look_role(name, role).rect
|
||||
}
|
||||
|
||||
/// The value text of the control named `name`.
|
||||
pub(crate) fn value(&self, name: &str) -> Option<String> {
|
||||
self.fixture.tree().value_of(self.look(name).node).map(str::to_owned)
|
||||
@@ -284,8 +315,13 @@ impl Panel {
|
||||
|
||||
/// Whether a control in the latest frame holds the value text `value`.
|
||||
pub(crate) fn shows_value(&self, value: &str) -> bool {
|
||||
self.shows_value_with(|shown| shown == value)
|
||||
}
|
||||
|
||||
/// Whether a control in the latest frame holds a value text that `matches`.
|
||||
pub(crate) fn shows_value_with(&self, matches: impl Fn(&str) -> bool) -> bool {
|
||||
let tree = self.fixture.tree();
|
||||
tree.keys().into_iter().any(|key| tree.value_of(key) == Some(value))
|
||||
tree.keys().into_iter().any(|key| tree.value_of(key).is_some_and(&matches))
|
||||
}
|
||||
|
||||
/// The toggle state of the control named `name`.
|
||||
|
||||
Reference in New Issue
Block a user