SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
History: an option for a folder of one kind of feature to show that kind's icon (#12514) (#12515)
Daniel Dimitrov323defa52511
diff --git a/assets/locales/pending/history-folder-kind-icon.json b/assets/locales/pending/history-folder-kind-icon.jsonnew file mode 100644index 0000000000..8fbcdeb585--- /dev/null+++ b/assets/locales/pending/history-folder-kind-icon.json@@ -0,0 +1,34 @@+{+ "en": {+ "prefs.history_folder_kind_icon": "Folder icon from its features",+ "prefs.history_folder_kind_icon_note": "A History folder whose features are all of one kind shows their icon."+ },+ "ar": {+ "prefs.history_folder_kind_icon": "أيقونة المجلد من ميزاته",+ "prefs.history_folder_kind_icon_note": "مجلد السجل الذي تكون ميزاته كلها من نوع واحد يعرض أيقونتها."+ },+ "de": {+ "prefs.history_folder_kind_icon": "Ordnersymbol aus seinen Features",+ "prefs.history_folder_kind_icon_note": "Ein Ordner im Verlauf, dessen Features alle von einer Art sind, zeigt deren Symbol."+ },+ "he": {+ "prefs.history_folder_kind_icon": "סמל התיקייה לפי התכונות שבה",+ "prefs.history_folder_kind_icon_note": "תיקייה בהיסטוריה שכל התכונות בה מאותו סוג מציגה את הסמל שלהן."+ },+ "ja": {+ "prefs.history_folder_kind_icon": "中のフィーチャーのアイコンをフォルダーに使う",+ "prefs.history_folder_kind_icon_note": "中のフィーチャーがすべて同じ種類の履歴フォルダーは、そのアイコンで表示されます。"+ },+ "vi": {+ "prefs.history_folder_kind_icon": "Biểu tượng thư mục theo các tính năng bên trong",+ "prefs.history_folder_kind_icon_note": "Thư mục Lịch sử có các tính năng cùng một loại sẽ hiện biểu tượng của chúng."+ },+ "zh": {+ "prefs.history_folder_kind_icon": "文件夹使用其中特征的图标",+ "prefs.history_folder_kind_icon_note": "历史中特征全部属于同一类型的文件夹显示该类型的图标。"+ },+ "ko": {+ "prefs.history_folder_kind_icon": "폴더 아이콘을 안의 피처에서 가져오기",+ "prefs.history_folder_kind_icon_note": "피처가 모두 같은 종류인 기록 폴더는 그 피처의 아이콘을 표시합니다."+ }+}diff --git a/crates/ui-egui/src/prefs.rs b/crates/ui-egui/src/prefs.rsindex 176dfd62a8..7b2012e80a 100644--- a/crates/ui-egui/src/prefs.rs+++ b/crates/ui-egui/src/prefs.rs@@ -1378,6 +1378,9 @@ preference_settings! {/// A Play History button in the History controls, between Previous and Next (#3688). Off/// gives the four controls History had before; right-clicking the controls toggles it too.history_play_button: bool = true, PAGE_LAYOUT;+ /// A History folder whose features are all of one kind (Holes, say) shows their icon instead of+ /// the folder icon, in both Histories. Off by default: every folder shows the folder icon.+ history_folder_kind_icon: bool = false, PAGE_LAYOUT;/// On, two or more joints show as one button with their count in the History, and a click/// shows each one (#8884). Off, the default, shows each joint as the History always has.history_group_joints: bool = false, PAGE_LAYOUT;@@ -6388,6 +6391,7 @@ mod tests {("timeline_under_browser", json!(true), PAGE_LAYOUT),("history_sketches", json!("under_feature"), PAGE_LAYOUT),("history_play_button", json!(false), PAGE_LAYOUT),+ ("history_folder_kind_icon", json!(true), PAGE_LAYOUT),("history_group_joints", json!(true), PAGE_LAYOUT),("history_bar_groups", json!(true), PAGE_LAYOUT),("browser_float", json!(true), PAGE_LAYOUT),diff --git a/crates/ui-egui/src/prefs/interface.rs b/crates/ui-egui/src/prefs/interface.rsindex f979c6d32c..49c6d3df8e 100644--- a/crates/ui-egui/src/prefs/interface.rs+++ b/crates/ui-egui/src/prefs/interface.rs@@ -466,6 +466,18 @@ pub(super) fn layout(app: &mut SolveApp, ui: &mut egui::Ui) {"browser_body_features",);});+ // A folder's icon from its features (#12514), in a row of its own: one more box in the+ // row above widens it past the page at narrow windows.+ ui.horizontal_wrapped(|ui| {+ ui.spacing_mut().item_spacing = egui::vec2(t.space_16, t.space_6);+ layout_check(+ ui,+ app.tr("prefs.history_folder_kind_icon"),+ app.tr("prefs.history_folder_kind_icon_note"),+ &mut app.preferences.history_folder_kind_icon,+ "history_folder_kind_icon",+ );+ });});ui_kit::settings_section(ui, "dialogs", app.tr("prefs.dialogs"), |ui| {ui_kit::settings_form(ui, t.form_label_width + t.space_24, |ui| {diff --git a/crates/ui-egui/src/timeline.rs b/crates/ui-egui/src/timeline.rsindex 06a98fba2c..9fbe750cb3 100644--- a/crates/ui-egui/src/timeline.rs+++ b/crates/ui-egui/src/timeline.rs@@ -212,6 +212,36 @@ pub(crate) fn icon_of(k: &FeatureKind) -> &'static str {}}+/// The icon a History folder takes from its features when Preferences says so: theirs, when every+/// feature in it (and in the folders inside it) has the same icon and it holds no joints.+pub(crate) fn folder_kind_icon(app: &SolveApp, id: u64) -> Option<&'static str> {+ if !app.preferences.history_folder_kind_icon {+ return None;+ }+ let doc = &app.session.doc;+ let mut pending = vec![id];+ let mut seen = std::collections::BTreeSet::new();+ let mut icon = None;+ while let Some(id) = pending.pop() {+ if !seen.insert(id) {+ continue;+ }+ let group = doc.timeline_groups.iter().find(|group| group.id == id)?;+ if !group.joints.is_empty() {+ return None;+ }+ for feature in &group.features {+ let this = icon_of(&doc.feature(*feature)?.kind);+ if icon.is_some_and(|icon| icon != this) {+ return None;+ }+ icon = Some(this);+ }+ pending.extend(doc.timeline_groups.iter().filter(|child| child.parent == Some(id)).map(|child| child.id));+ }+ icon+}+fn construction_plane_icon(plane: &PlaneRef) -> &'static str {match plane {PlaneRef::AtAngle { .. } => "plane_angle",@@ -1262,6 +1292,38 @@ mod tests {use crate::scenario::Harness;+ #[test]+ fn a_folder_of_one_kind_of_feature_takes_its_icon_when_preferences_say_so() {+ let mut h = Harness::new();+ h.app.home.open = false;+ h.app.run("solid.box", json!({"length": 40, "width": 30, "height": 20, "name": "Block"})).unwrap();+ for x in [8, 16, 24, 32] {+ h.app.run("solid.hole", json!({"position": [x, 10, 20], "diameter": 4, "name": format!("H{x}")})).unwrap();+ }+ let group = |h: &mut Harness, p: serde_json::Value| h.app.run("timeline.group", p).unwrap()["group"].as_u64().unwrap();+ let inner = group(&mut h, json!({"name": "Inner", "features": ["H8", "H16"]}));+ // Holes, and a folder of holes inside: all one kind.+ let holes = group(&mut h, json!({"name": "Holes", "features": ["H24"], "groups": [inner]}));+ let mixed = group(&mut h, json!({"name": "Mixed", "features": ["Block"]}));+ let hole = super::icon_of(&h.app.session.doc.find_feature("H8").unwrap().kind);+ // Off (the default): every folder keeps the folder icon.+ assert!(!h.app.preferences.history_folder_kind_icon);+ assert_eq!(super::folder_kind_icon(&h.app, holes), None);+ crate::prefs::set(&mut h.app, &json!({"history_folder_kind_icon": true})).unwrap();+ assert_eq!(super::folder_kind_icon(&h.app, holes), Some(hole));+ assert_eq!(super::folder_kind_icon(&h.app, inner), Some(hole));+ assert_eq!(super::folder_kind_icon(&h.app, mixed), Some(super::icon_of(&h.app.session.doc.find_feature("Block").unwrap().kind)));+ // A box among the holes: back to the folder icon.+ h.app.run("timeline.group", json!({"name": "Both", "groups": [holes, mixed]})).unwrap();+ let both = h.app.session.doc.timeline_groups.iter().find(|g| g.name == "Both").unwrap().id;+ assert_eq!(super::folder_kind_icon(&h.app, both), None);+ // Both Histories draw it without trouble.+ for left in [false, true] {+ h.app.preferences.timeline_left = left;+ h.frames(3);+ }+ }+#[test]fn joint_folder_hides_fifty_joint_tiles_in_both_history_layouts() {use crate::scenario::handle_at;diff --git a/crates/ui-egui/src/timeline_folders.rs b/crates/ui-egui/src/timeline_folders.rsindex b4ff47636d..4587de00a5 100644--- a/crates/ui-egui/src/timeline_folders.rs+++ b/crates/ui-egui/src/timeline_folders.rs@@ -250,8 +250,9 @@ pub(crate) fn folder_chip(let state = history.inside(folder.start, folder.end, folder.open);let picked = app.tree.picked_timeline_groups.contains(&folder.id)|| (!folder.open && history.folders.joints.get(&folder.id).is_some_and(|j| j.iter().any(|j| app.tree.picked_joints.contains(j))));+ let icon = crate::timeline::folder_kind_icon(app, folder.id).unwrap_or("feature_group");let chip = HistoryGroupChip {- icon: "feature_group",+ icon,name: &name,count,open: folder.open,diff --git a/crates/ui-egui/src/timeline_left.rs b/crates/ui-egui/src/timeline_left.rsindex 04001270db..95d0606e5a 100644--- a/crates/ui-egui/src/timeline_left.rs+++ b/crates/ui-egui/src/timeline_left.rs@@ -1128,7 +1128,8 @@ fn vertical_group_row(painter.multiply_opacity(0.42);}let icon = Rect::from_center_size(pos2(rect.left() + 27.5 + offset, rect.center().y), vec2(17.0, 17.0));- icons::paint_icon(&painter, icon, "feature_group", f32::from(t.icon.a()) / 255.0);+ let kind = crate::timeline::folder_kind_icon(app, group.id).unwrap_or("feature_group");+ icons::paint_icon(&painter, icon, kind, f32::from(t.icon.a()) / 255.0);if suppressed {painter.line_segment([icon.left_bottom(), icon.right_top()], Stroke::new(1.5, t.text_dim));}diff --git a/docs/design/preferences/pages/layout.md b/docs/design/preferences/pages/layout.mdindex c6d550d006..24f5513446 100644--- a/docs/design/preferences/pages/layout.md+++ b/docs/design/preferences/pages/layout.md@@ -32,6 +32,7 @@ Source today: Interface page (`prefs/interface.rs`, `prefs/navbar.rs`).| Sketches in History | Segmented: In order / Under feature | `Prefs.history_sketches` (`HistorySketches`) | In order | none | none | || Bodies folders | Segmented: Always / Several / Never | `Prefs.browser_bodies_folders` (`BodiesFolders`) | Several | none | none | || Play History button | Checkbox | `Prefs.history_play_button` | `true` | none | none | |+| Folder icon from its features | Checkbox | `Prefs.history_folder_kind_icon` | `false` | "A folder whose features are all of one kind shows their icon." | none | || Origin and bodies on top | Checkbox | `Prefs.timeline_origin_bodies` | `false` | "Vertical history only." | none | || Eye beside the fold arrow | Checkbox | `Prefs.browser_eye_left` | `false` | none | none | |