mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-01 02:35:37 +01:00
fix: name the Step and Repeat cut object param cutId
This commit is contained in:
1 parent
8074d6fbc0
commit
e5cb0d8dca
3 files changed
+14
-14
No files matched your search
@@ -20,7 +20,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Step and Repeat…",
|
||||
["Object", "Transform"],
|
||||
None,
|
||||
"{rows?: n (default 1), columns?: n (default 1), fill?: bool (rows and columns are as many as fit the sheet, ignoring `rows` and `columns`; the first copy goes to the sheet's top-left corner plus `margin`), sheet?: {x, y, width, height} (pt; default the artboard that holds the selection's center, else the first), margin?: pt (fill only, default 0), gap?: pt (between neighbors, both axes), gapX?: pt, gapY?: pt (default `gap`, default 0; measured between the bounds of `cutPath`, else of the selection, not between centers), cutPath?: id (a selected object whose geometric bounds measure the spacing and the 180° turn; default the selection), rotate?: \"none\"|\"columns\"|\"rows\" (turn every other column or row by 180° about its cell's center, the same clockwise or counter-clockwise; default none), patterns?: bool} copy the selection into a grid of cells, left to right and top to bottom, the first cell being the selection itself (moved to the sheet's corner with fill); a selection of several objects is grouped first, so that a cut contour stays with its artwork in every copy; one undo step; the copies are selected → {ids: [id…], rows, columns, count}",
|
||||
"{rows?: n (default 1), columns?: n (default 1), fill?: bool (rows and columns are as many as fit the sheet, ignoring `rows` and `columns`; the first copy goes to the sheet's top-left corner plus `margin`), sheet?: {x, y, width, height} (pt; default the artboard that holds the selection's center, else the first), margin?: pt (fill only, default 0), gap?: pt (between neighbors, both axes), gapX?: pt, gapY?: pt (default `gap`, default 0; measured between the bounds of `cutId`, else of the selection, not between centers), cutId?: id (a selected object whose geometric bounds measure the spacing and the 180° turn; default the selection), rotate?: \"none\"|\"columns\"|\"rows\" (turn every other column or row by 180° about its cell's center, the same clockwise or counter-clockwise; default none), patterns?: bool} copy the selection into a grid of cells, left to right and top to bottom, the first cell being the selection itself (moved to the sheet's corner with fill); a selection of several objects is grouped first, so that a cut contour stays with its artwork in every copy; one undo step; the copies are selected → {ids: [id…], rows, columns, count}",
|
||||
has_selection,
|
||||
step_and_repeat
|
||||
)]
|
||||
@@ -126,17 +126,17 @@ fn step_and_repeat(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
return Err(EngineError::Other("nothing selected".into()));
|
||||
}
|
||||
let d = &s.doc()?.doc;
|
||||
let cut = match p.get("cutPath").filter(|v| !v.is_null()) {
|
||||
let cut = match p.get("cutId").filter(|v| !v.is_null()) {
|
||||
None => None,
|
||||
Some(v) => {
|
||||
let id = NodeId(v.as_u64().ok_or_else(|| bad(CMD, "`cutPath` must be an object id"))?);
|
||||
let id = NodeId(v.as_u64().ok_or_else(|| bad(CMD, "`cutId` must be an object id"))?);
|
||||
let held = roots.iter().filter_map(|r| d.node(*r)).any(|n| {
|
||||
let mut found = false;
|
||||
n.walk(&mut |c| found |= c.id == id);
|
||||
found
|
||||
});
|
||||
if !held {
|
||||
return Err(bad(CMD, "`cutPath` must be part of the selection"));
|
||||
return Err(bad(CMD, "`cutId` must be part of the selection"));
|
||||
}
|
||||
Some(id)
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ fn a_cut_contour_stays_grouped_with_its_artwork_in_every_copy() {
|
||||
let (mut s, art) = setup();
|
||||
let cut = s.execute("shape.rectangle", &json!({"x": 0, "y": 0, "width": 50, "height": 30})).unwrap()["id"].as_u64().unwrap();
|
||||
s.execute("select.set", &json!({"ids": [art, cut]})).unwrap();
|
||||
let r = s.execute(CMD, &json!({"rows": 1, "columns": 3, "gap": 2, "cutPath": cut})).unwrap();
|
||||
let r = s.execute(CMD, &json!({"rows": 1, "columns": 3, "gap": 2, "cutId": cut})).unwrap();
|
||||
assert_eq!(r["count"], json!(3));
|
||||
let d = &s.doc().unwrap().doc;
|
||||
for id in r["ids"].as_array().unwrap() {
|
||||
@@ -124,7 +124,7 @@ fn rejects_bad_params_and_a_selection_that_does_not_fit() {
|
||||
assert!(s.execute(CMD, &json!({"rows": 0})).is_err());
|
||||
assert!(s.execute(CMD, &json!({"rows": 1000, "columns": 1000})).is_err());
|
||||
assert!(s.execute(CMD, &json!({"rotate": "diagonal"})).is_err());
|
||||
assert!(s.execute(CMD, &json!({"cutPath": 999999})).is_err());
|
||||
assert!(s.execute(CMD, &json!({"cutId": 999999})).is_err());
|
||||
assert!(s.execute(CMD, &json!({"fill": true, "sheet": {"x": 0, "y": 0, "width": 40, "height": 40}})).is_err());
|
||||
let mut e = Session::new();
|
||||
e.execute("file.new", &json!({"width": 100, "height": 100})).unwrap();
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
//! previewed live on the canvas.
|
||||
//!
|
||||
//! Fields: `rows`, `columns`, `gapX`, `gapY` (pt), `margin` (pt), `fill` (as many as fit the
|
||||
//! artboard), `rotate` (`none`, `columns` or `rows`), `cutPath` (an object of the selection, or
|
||||
//! artboard), `rotate` (`none`, `columns` or `rows`), `cutId` (an object of the selection, or
|
||||
//! empty for the selection itself).
|
||||
|
||||
use craft::ui::contract::Bind;
|
||||
@@ -46,7 +46,7 @@ fn rows(lengths: LengthUnits, cuts: Vec<(String, Label)>) -> Vec<Param> {
|
||||
Param::new("columns", tl!("Columns"), ParamKind::int(Some(1), Some(500), 2)).enabled_when("fill", false),
|
||||
len("gapX", tl!("Horizontal Gap")),
|
||||
len("gapY", tl!("Vertical Gap")),
|
||||
Param::new("cutPath", tl!("Cut Path"), ParamKind::choice(cuts, Some(String::new()))),
|
||||
Param::new("cutId", tl!("Cut Path"), ParamKind::choice(cuts, Some(String::new()))),
|
||||
Param::new("fill", tl!("Fill the Artboard"), ParamKind::bool(false)),
|
||||
len("margin", tl!("Margin")).enabled_when("fill", true),
|
||||
Param::new(
|
||||
@@ -72,7 +72,7 @@ pub fn fields() -> DialogFields {
|
||||
("gapY", FieldValue::Number(12.0)),
|
||||
("margin", FieldValue::Number(0.0)),
|
||||
("fill", FieldValue::Bool(false)),
|
||||
("cutPath", FieldValue::Text(String::new())),
|
||||
("cutId", FieldValue::Text(String::new())),
|
||||
("rotate", FieldValue::Text("none".into())),
|
||||
])
|
||||
}
|
||||
@@ -90,8 +90,8 @@ fn params(f: &DialogFields) -> Value {
|
||||
}
|
||||
p.insert("fill".into(), json!(f.bool("fill").unwrap_or(false)));
|
||||
p.insert("rotate".into(), json!(f.text("rotate").unwrap_or("none")));
|
||||
if let Some(id) = f.text("cutPath").and_then(|t| t.parse::<u64>().ok()) {
|
||||
p.insert("cutPath".into(), json!(id));
|
||||
if let Some(id) = f.text("cutId").and_then(|t| t.parse::<u64>().ok()) {
|
||||
p.insert("cutId".into(), json!(id));
|
||||
}
|
||||
Value::Object(p)
|
||||
}
|
||||
@@ -143,8 +143,8 @@ mod tests {
|
||||
#[test]
|
||||
fn cut_path_is_sent_only_when_one_is_chosen() {
|
||||
let mut f = fields();
|
||||
assert!(params(&f).get("cutPath").is_none());
|
||||
f.set("cutPath", FieldValue::Text("42".into()));
|
||||
assert_eq!(params(&f)["cutPath"], json!(42));
|
||||
assert!(params(&f).get("cutId").is_none());
|
||||
f.set("cutId", FieldValue::Text("42".into()));
|
||||
assert_eq!(params(&f)["cutId"], json!(42));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user