VectorCraft: An open-source, vector art tool written by scratch in pure Rust
Fix #1450: the Pathfinder panel works on a group selected alone
bflatastic7625feea08b3
diff --git a/crates/engine/src/cmd/pathops.rs b/crates/engine/src/cmd/pathops.rsindex c7937a113..8b35f394f 100644--- a/crates/engine/src/cmd/pathops.rs+++ b/crates/engine/src/cmd/pathops.rs@@ -343,10 +343,12 @@ fn run_pf(s: &mut Session, op: PathfinderOp) -> Result<Value> {continue;}if shape_mode+ && roots.len() > 1&& lv.len() > 1&& let Some(top) = lv.last(){- // A group acts as one shape (the union of its leaves) with its top leaf's style.+ // Among other objects, a group acts as one shape (the union of its leaves) with+ // its top leaf's style. Selected alone, its members are the shapes (#1450).let parts: Vec<(PathData, FillRule)> = lv.iter().filter_map(node_path).collect();let refs: Vec<(&PathData, FillRule)> = parts.iter().map(|(p, r)| (p, *r)).collect();let name = n.name.clone().or_else(|| lv.iter().find_map(|l| l.name.clone()));diff --git a/crates/engine/src/tests_pathops.rs b/crates/engine/src/tests_pathops.rsindex 05036dd0c..6796fd601 100644--- a/crates/engine/src/tests_pathops.rs+++ b/crates/engine/src/tests_pathops.rs@@ -191,6 +191,20 @@ fn pathfinder_undo_restores() {assert!(s.doc().unwrap().selection.contains(a) && s.doc().unwrap().selection.contains(b));}+/// #1450: a group selected alone gives the shape modes its members to work on.+#[test]+fn a_group_selected_alone_is_combined_member_by_member() {+ let mut s = session();+ let a = rect(&mut s, 0.0, 0.0, 20.0, 20.0);+ let b = rect(&mut s, 10.0, 0.0, 20.0, 20.0);+ s.execute("select.set", &json!({"ids": [a.0, b.0]})).unwrap();+ s.execute("object.group", &json!({})).unwrap();+ assert_eq!(s.doc().unwrap().selection.len(), 1);+ let id = s.execute("object.pathfinder.minusFront", &json!({})).unwrap()["ids"][0].as_u64().unwrap();+ let bounds = s.doc().unwrap().doc.node(NodeId(id)).unwrap().geometric_bounds().unwrap();+ assert_eq!((bounds.x0, bounds.x1), (0.0, 10.0), "the back member less the front one");+}+#[test]fn unite_with_group() {let mut s = session();diff --git a/crates/ui-egui/src/i18n/cs.tsv b/crates/ui-egui/src/i18n/cs.tsvindex 94798738e..8069b93c1 100644--- a/crates/ui-egui/src/i18n/cs.tsv+++ b/crates/ui-egui/src/i18n/cs.tsv@@ -4640,6 +4640,7 @@ mark-style Japanese JaponskéUse Outside Rectangle As Frame Použít vnější obdélník jako rámečekCreate Compound Path From Ellipses Vytvořit složenou cestu z elipsFill Grid Vyplnit mřížku+ Select two or more objects, or a group Vyberte dva nebo více objektů, nebo skupinu# 3D and Materials › Extrude & Bevel, Inflate and Rotate: options, Position presets and bevel shapes.Back ZezaduBoth sides Obě stranydiff --git a/crates/ui-egui/src/i18n/de.tsv b/crates/ui-egui/src/i18n/de.tsvindex 949f4b84a..b271a5860 100644--- a/crates/ui-egui/src/i18n/de.tsv+++ b/crates/ui-egui/src/i18n/de.tsv@@ -4163,6 +4163,7 @@ theme Appearance ErscheinungsbildUse Outside Rectangle As Frame Äußeres Rechteck als Rahmen verwendenCreate Compound Path From Ellipses Zusammengesetzten Pfad aus Ellipsen erstellenFill Grid Raster füllen+ Select two or more objects, or a group Wählen Sie zwei oder mehr Objekte oder eine Gruppe aus# 3D and Materials › Extrude & Bevel, Inflate and Rotate: options, Position presets and bevel shapes.Back HintenBoth sides Beidseitigdiff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsvindex ae6ac751d..9664be527 100644--- a/crates/ui-egui/src/i18n/es.tsv+++ b/crates/ui-egui/src/i18n/es.tsv@@ -4580,6 +4580,7 @@ mark-style Japanese JaponesasX: X:Y: Y:@id file.close Cerrar archivo+ Select two or more objects, or a group Seleccione dos o más objetos, o un grupo# 3D and Materials › Extrude & Bevel, Inflate and Rotate: options, Position presets and bevel shapes.Back PosteriorBoth sides Ambos ladosdiff --git a/crates/ui-egui/src/i18n/fr.tsv b/crates/ui-egui/src/i18n/fr.tsvindex 85242a40a..c8e813393 100644--- a/crates/ui-egui/src/i18n/fr.tsv+++ b/crates/ui-egui/src/i18n/fr.tsv@@ -4216,6 +4216,7 @@ lighting Light LumièreUse Outside Rectangle As Frame Utiliser le rectangle extérieur comme cadreCreate Compound Path From Ellipses Créer un tracé transparent à partir des ellipsesFill Grid Remplir la grille+ Select two or more objects, or a group Sélectionnez au moins deux objets, ou un groupe# 3D and Materials › Extrude & Bevel, Inflate and Rotate: options, Position presets and bevel shapes.Back ArrièreBoth sides Deux côtésdiff --git a/crates/ui-egui/src/i18n/hu.tsv b/crates/ui-egui/src/i18n/hu.tsvindex 3662f906e..f89a3dcf0 100644--- a/crates/ui-egui/src/i18n/hu.tsv+++ b/crates/ui-egui/src/i18n/hu.tsv@@ -4606,6 +4606,7 @@ theme Appearance KinézetUse Outside Rectangle As Frame Külső téglalap használata keretkéntCreate Compound Path From Ellipses Összetett útvonal létrehozása az ellipszisekbőlFill Grid Rács kitöltése+ Select two or more objects, or a group Jelöljön ki két vagy több objektumot, vagy egy csoportot# 3D and Materials › Extrude & Bevel, Inflate and Rotate: options, Position presets and bevel shapes.Back HátulrólBoth sides Mindkét oldaldiff --git a/crates/ui-egui/src/i18n/it.tsv b/crates/ui-egui/src/i18n/it.tsvindex f1c529c71..edd90df17 100644--- a/crates/ui-egui/src/i18n/it.tsv+++ b/crates/ui-egui/src/i18n/it.tsv@@ -4208,6 +4208,7 @@ lighting Light LuceUse Outside Rectangle As Frame Usa rettangolo esterno come corniceCreate Compound Path From Ellipses Crea tracciato composto dalle ellissiFill Grid Riempi griglia+ Select two or more objects, or a group Selezionate due o più oggetti, oppure un gruppo# 3D and Materials › Extrude & Bevel, Inflate and Rotate: options, Position presets and bevel shapes.Back RetroBoth sides Entrambi i latidiff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsvindex 3fdeeb5c8..328999924 100644--- a/crates/ui-egui/src/i18n/ja.tsv+++ b/crates/ui-egui/src/i18n/ja.tsv@@ -4202,6 +4202,7 @@ lighting Light ライトUse Outside Rectangle As Frame 外側の長方形をフレームとして使用Create Compound Path From Ellipses 楕円形から複合パスを作成Fill Grid グリッドを塗りつぶす+ Select two or more objects, or a group 2 つ以上のオブジェクト、またはグループを選択してください# 3D and Materials › Extrude & Bevel, Inflate and Rotate: options, Position presets and bevel shapes.Back 背面Both sides 両面diff --git a/crates/ui-egui/src/i18n/ko.tsv b/crates/ui-egui/src/i18n/ko.tsvindex cb1dad707..c3f1595cb 100644--- a/crates/ui-egui/src/i18n/ko.tsv+++ b/crates/ui-egui/src/i18n/ko.tsv@@ -4172,6 +4172,7 @@ lighting Light 광원Use Outside Rectangle As Frame 바깥쪽 사각형을 프레임으로 사용Create Compound Path From Ellipses 원에서 컴파운드 패스 만들기Fill Grid 격자 칠하기+ Select two or more objects, or a group 두 개 이상의 개체 또는 그룹을 선택하십시오# 3D and Materials › Extrude & Bevel, Inflate and Rotate: options, Position presets and bevel shapes.Back 뒷면Both sides 양면diff --git a/crates/ui-egui/src/i18n/pt-br.tsv b/crates/ui-egui/src/i18n/pt-br.tsvindex 50ed39d93..5fe36b5dd 100644--- a/crates/ui-egui/src/i18n/pt-br.tsv+++ b/crates/ui-egui/src/i18n/pt-br.tsv@@ -3687,3 +3687,4 @@ axis Both AmbosUse Outside Rectangle As Frame Usar Retângulo Externo como MolduraCreate Compound Path From Ellipses Criar Caminho Composto a partir das ElipsesFill Grid Preencher Grade+ Select two or more objects, or a group Selecione dois ou mais objetos, ou um grupodiff --git a/crates/ui-egui/src/i18n/ru.tsv b/crates/ui-egui/src/i18n/ru.tsvindex b22407a61..9c51c4887 100644--- a/crates/ui-egui/src/i18n/ru.tsv+++ b/crates/ui-egui/src/i18n/ru.tsv@@ -4204,6 +4204,7 @@ lighting Light СветUse Outside Rectangle As Frame Использовать внешний прямоугольник как рамкуCreate Compound Path From Ellipses Создать составной контур из эллипсовFill Grid Залить сетку+ Select two or more objects, or a group Выделите два или более объектов либо группу# 3D and Materials › Extrude & Bevel, Inflate and Rotate: options, Position presets and bevel shapes.Back СзадиBoth sides С обеих сторонdiff --git a/crates/ui-egui/src/i18n/uk.tsv b/crates/ui-egui/src/i18n/uk.tsvindex 293f79fa0..55c2cab93 100644--- a/crates/ui-egui/src/i18n/uk.tsv+++ b/crates/ui-egui/src/i18n/uk.tsv@@ -4188,6 +4188,7 @@ lighting Light СвітлоUse Outside Rectangle As Frame Використовувати зовнішній прямокутник як рамкуCreate Compound Path From Ellipses Створити складений контур з еліпсівFill Grid Залити сітку+ Select two or more objects, or a group Виділіть два або більше об’єктів чи групу# 3D and Materials › Extrude & Bevel, Inflate and Rotate: options, Position presets and bevel shapes.Back ЗзадуBoth sides З обох боківdiff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsvindex 95dd4b203..c07ef172b 100644--- a/crates/ui-egui/src/i18n/zh-hans.tsv+++ b/crates/ui-egui/src/i18n/zh-hans.tsv@@ -3799,6 +3799,7 @@ lighting Light 光源Use Outside Rectangle As Frame 使用外部矩形作为框架Create Compound Path From Ellipses 从椭圆形创建复合路径Fill Grid 网格填色+ Select two or more objects, or a group 请选择两个或更多对象,或一个组# 3D and Materials › Extrude & Bevel, Inflate and Rotate: options, Position presets and bevel shapes.Back 背面Both sides 双面diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsvindex 84d609b02..54d8c3444 100644--- a/crates/ui-egui/src/i18n/zh-hant.tsv+++ b/crates/ui-egui/src/i18n/zh-hant.tsv@@ -3580,6 +3580,7 @@ lighting Light 光源Use Outside Rectangle As Frame 使用外部矩形作為框架Create Compound Path From Ellipses 從橢圓形建立複合路徑Fill Grid 格線填色+ Select two or more objects, or a group 請選取兩個或更多物件,或一個群組# 3D and Materials › Extrude & Bevel, Inflate and Rotate: options, Position presets and bevel shapes.Back 背面Both sides 雙面diff --git a/crates/ui-egui/src/panels/pathfinder.rs b/crates/ui-egui/src/panels/pathfinder.rsindex 7f25d5e15..6a78816f5 100644--- a/crates/ui-egui/src/panels/pathfinder.rs+++ b/crates/ui-egui/src/panels/pathfinder.rs@@ -29,14 +29,34 @@ fn run(app: &mut VectorcraftApp, ui: &Ui, op: &str, label: &str) {}}+/// How many objects the selection gives an operation: a group selected alone counts as its+/// members (#1450).+fn operands(app: &VectorcraftApp) -> usize {+ let alone = app.session.active().filter(|d| d.selection.len() == 1).and_then(|d| d.doc.node(*d.selection.objects.first()?));+ match alone.and_then(|n| n.children().filter(|_| matches!(n.kind, vectorcraft_doc::NodeKind::Group { .. }))) {+ Some(members) => members.len(),+ None => selection_len(app),+ }+}++/// An operation's button, greyed out and saying what it needs unless the selection has `min` operands.+fn button(ui: &mut Ui, icon: &str, tip: &str, n: usize, min: usize) -> bool {+ let resp = widgets::icon_button_enabled(ui, icon, tip, false, n >= min, 34.0);+ if n < min {+ resp.on_hover_text(tl!("Select two or more objects, or a group"));+ return false;+ }+ resp.clicked()+}+pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {- let n = selection_len(app);+ let n = operands(app);let t = crate::theme::Tokens::get(ui.ctx());widgets::subheader(ui, tl!("Shape Modes:"));ui.horizontal(|ui| {ui.spacing_mut().item_spacing.x = 5.0;for (icon, tip, op) in SHAPE_MODES {- if widgets::icon_button_enabled(ui, icon, tip, false, n >= 2, 34.0).clicked() {+ if button(ui, icon, tip, n, 2) {run(app, ui, op, tip);}}@@ -53,7 +73,7 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {ui.spacing_mut().item_spacing.x = 5.0;for (icon, tip, op) in PATHFINDERS {let min = if op == "outline" || op == "divide" { 1 } else { 2 };- if widgets::icon_button_enabled(ui, icon, tip, false, n >= min, 34.0).clicked() {+ if button(ui, icon, tip, n, min) {run(app, ui, op, tip);}}