Fixes #1187. New parameters.move {name, before|after} reorders user parameters (the design's own params order, so it is saved with no format change, and undoable); the Parameters dialog's user rows get up/down buttons. Label in every catalog. I merged main in. Checked on main + this branch: cargo check --workspace, the engine parameters tests, the UI parameter_order test, and docs/features.md regenerates unchanged.
31 lines
1.3 KiB
Rust
31 lines
1.3 KiB
Rust
//! The Parameters dialog's ▲ / ▼ buttons reorder user parameters (#1187).
|
|
use serde_json::json;
|
|
use solidcraft_ui_egui::scenario::Harness;
|
|
|
|
fn order(h: &mut Harness) -> Vec<String> {
|
|
let v = h.app.session.execute("parameters.list", &json!({"filter": "user"})).unwrap();
|
|
v["parameters"].as_array().unwrap().iter().map(|r| r["name"].as_str().unwrap().to_string()).collect()
|
|
}
|
|
|
|
#[test]
|
|
fn arrows_move_user_parameters_up_and_down() {
|
|
let mut h = Harness::new();
|
|
for (n, e) in [("a", "1 mm"), ("b", "2 mm"), ("c", "3 mm")] {
|
|
h.app.session.execute("parameters.add", &json!({"name": n, "expression": e})).unwrap();
|
|
}
|
|
h.step(&json!({"widget":"Parameters"})).unwrap();
|
|
assert!(h.app.params.is_some());
|
|
h.frames(3);
|
|
h.run(&json!([{"click":{"handle":"param:after:a"}}])).unwrap();
|
|
h.frames(2);
|
|
assert_eq!(order(&mut h), ["b", "a", "c"]);
|
|
h.run(&json!([{"click":{"handle":"param:before:c"}}])).unwrap();
|
|
h.frames(2);
|
|
assert_eq!(order(&mut h), ["b", "c", "a"]);
|
|
// The first row cannot move up, the last cannot move down.
|
|
h.run(&json!([{"click":{"handle":"param:before:b"}}, {"click":{"handle":"param:after:a"}}])).unwrap();
|
|
h.frames(2);
|
|
assert_eq!(order(&mut h), ["b", "c", "a"]);
|
|
assert!(h.app.params.as_ref().unwrap().error.is_none());
|
|
}
|