From 303fddb20e8a61f9e7b3707e3e389236a5c2da49 Mon Sep 17 00:00:00 2001 From: CamWight <91156642+CamWight@users.noreply.github.com> Date: Wed, 28 Oct 2026 00:24:17 +0000 Subject: [PATCH] Browser: Bodies folders only where they help: Always, Several bodies only (the default) or Never (#4217) (#4219) * claim: #4217 Co-Authored-By: Claude Opus 5.5 * Browser: Bodies folders only where they help: Always, Several bodies only (the default) or Never (#4217) A new preference on the Interface page, in the Layout section under Browser, sets when a component's bodies sit in a Bodies folder of their own. Several bodies only lists a component's lone body, when it has no groups, straight under its placement. Never lists every component's bodies and groups there. Always keeps the folder as before. The design's own Bodies folder and a folder hidden with its eye always stay. One rule, browser::bodies_folded, decides it for the rows and for the menu. A folded folder draws no row and stays open; its items move up one level, and their own eyes, hover and drops do its jobs. While a folder is folded, its placement's menu takes the folder's Create Components from Bodies and Group Selected; New Group and Show All were already there. ui.prefs takes browser_bodies_folders (always, several, never) and refuses other values; saved preferences read an unknown value as the default. The s37 scenario sets Always so that it still checks the Bodies folder's chevron. Co-Authored-By: Claude Opus 5.5 * Browser: Bodies folders in Arabic, Hebrew and Vietnamese too (#4217) Arabic, Hebrew, Japanese, Vietnamese and Chinese are complete catalogues, so every_complete_catalog_carries_every_english_message fails a new message any of them lacks. The preference's four messages get their Arabic, Hebrew and Vietnamese text, in the words those catalogues already use for a body and a folder. Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Opus 5.5 --- .../pending/browser-bodies-folders.json | 50 +++++++ crates/ui-egui/src/browser.rs | 80 +++++++++--- crates/ui-egui/src/context_menu.rs | 1 + crates/ui-egui/src/occurrence_ui_tests.rs | 122 ++++++++++++++++++ crates/ui-egui/src/prefs.rs | 64 +++++++++ crates/ui-egui/src/prefs/interface.rs | 10 ++ .../scenarios/browser_bodies_folders.json | 33 +++++ .../tests/scenarios/s37_browser_chevrons.json | 9 ++ docs/book/src/guide/ui-tour.md | 7 +- docs/control-protocol.md | 2 +- 10 files changed, 358 insertions(+), 20 deletions(-) create mode 100644 assets/locales/pending/browser-bodies-folders.json create mode 100644 crates/ui-egui/tests/scenarios/browser_bodies_folders.json diff --git a/assets/locales/pending/browser-bodies-folders.json b/assets/locales/pending/browser-bodies-folders.json new file mode 100644 index 000000000..5ccccfc18 --- /dev/null +++ b/assets/locales/pending/browser-bodies-folders.json @@ -0,0 +1,50 @@ +{ + "en": { + "prefs.bodies_folders": "Bodies folders", + "prefs.bodies_folders_always": "Always", + "prefs.bodies_folders_never": "Never", + "prefs.bodies_folders_several": "Several bodies only" + }, + "ar": { + "prefs.bodies_folders": "مجلدات الأجسام", + "prefs.bodies_folders_always": "دائمًا", + "prefs.bodies_folders_never": "أبدًا", + "prefs.bodies_folders_several": "عند تعدد الأجسام فقط" + }, + "he": { + "prefs.bodies_folders": "תיקיות גופים", + "prefs.bodies_folders_always": "תמיד", + "prefs.bodies_folders_never": "אף פעם", + "prefs.bodies_folders_several": "רק כשיש כמה גופים" + }, + "de": { + "prefs.bodies_folders": "Körperordner", + "prefs.bodies_folders_always": "Immer", + "prefs.bodies_folders_never": "Nie", + "prefs.bodies_folders_several": "Nur bei mehreren Körpern" + }, + "ja": { + "prefs.bodies_folders": "ボディフォルダー", + "prefs.bodies_folders_always": "常に表示", + "prefs.bodies_folders_never": "表示しない", + "prefs.bodies_folders_several": "複数ボディのみ" + }, + "ko": { + "prefs.bodies_folders": "바디 폴더", + "prefs.bodies_folders_always": "항상 표시", + "prefs.bodies_folders_never": "표시 안 함", + "prefs.bodies_folders_several": "바디가 여러 개일 때만" + }, + "vi": { + "prefs.bodies_folders": "Thư mục thân khối", + "prefs.bodies_folders_always": "Luôn luôn", + "prefs.bodies_folders_never": "Không bao giờ", + "prefs.bodies_folders_several": "Chỉ khi có nhiều thân khối" + }, + "zh": { + "prefs.bodies_folders": "实体文件夹", + "prefs.bodies_folders_always": "始终显示", + "prefs.bodies_folders_never": "不显示", + "prefs.bodies_folders_several": "仅限多个实体" + } +} diff --git a/crates/ui-egui/src/browser.rs b/crates/ui-egui/src/browser.rs index e801f8243..b95d5db42 100644 --- a/crates/ui-egui/src/browser.rs +++ b/crates/ui-egui/src/browser.rs @@ -360,6 +360,26 @@ pub fn folder_items(app: &SolveApp, component: u64, folder: &str, scope: &str) - v } +/// A component's or placement's menu, while its Bodies folder is folded away (#4217), takes the +/// folder's items it lacks: Create Components from Bodies and Group Selected (New Group and Show +/// All are on every component's menu). +pub fn folded_folder_items(app: &SolveApp, target: &Target) -> Vec { + let (comp, scope) = match target { + Target::Component { id } => (*id, format!("c{id}")), + Target::Occurrence { path } => match app.session.occurrence_placement(path) { + Ok(placement) => (placement.component, occurrence_key(path)), + Err(_) => return Vec::new(), + }, + _ => return Vec::new(), + }; + if !bodies_folded(app, comp, &scope, entries(app, comp, "bodies").len()) { + return Vec::new(); + } + let items = + folder_items(app, comp, "bodies", &scope).into_iter().filter(|i| matches!(i.id.as_str(), "component.from_bodies" | "ui.groupSelected")); + std::iter::once(Item::sep()).chain(items).collect() +} + /// The menu of the Origin folder. pub fn origin_items(app: &SolveApp) -> Vec { let planes = ["XY", "XZ", "YZ"].iter().all(|p| !app.session.visibility.hidden_origin.iter().any(|h| h == p)); @@ -2275,6 +2295,22 @@ fn folder_static(folder: &str) -> &'static str { } } +/// Whether a component's Bodies folder is folded away, its bodies (and groups) listed straight +/// under the component or placement row (Preferences › Interface › Bodies folders, #4217). +/// `scope` is that row's tree key (`c{id}`, `o:{path}`) and `bodies` how many items the folder +/// holds. The design's own folder always stays, and so does a hidden one: its eye is the way back. +fn bodies_folded(app: &SolveApp, comp: u64, scope: &str, bodies: usize) -> bool { + use crate::prefs::BodiesFolders; + if comp == 0 || bodies == 0 || app.session.folder_hidden(&format!("{scope}/bodies")) { + return false; + } + match app.preferences.browser_bodies_folders { + BodiesFolders::Always => false, + BodiesFolders::Several => bodies == 1 && !app.session.doc.browser_groups.iter().any(|g| g.component == comp && g.folder == "bodies"), + BodiesFolders::Never => true, + } +} + /// A component's folder: its row, its groups and its items. Rows are drag sources; items, /// groups and the folder row are drop targets (reorder, into a group, out of groups). #[allow(clippy::too_many_arguments)] @@ -2304,26 +2340,34 @@ fn folder_rows_at( app.tree.collapsed.remove(&format!("g{}", g.id)); } } - let open = is_open(app, key, true); + // A folded folder draws no row: its groups and items move up into its place, and their own + // eyes, hover and drops do its jobs. It is always open, as nothing could open it again. + let folded = folder == "bodies" && bodies_folded(app, comp, prefix, data.entries().count()); + let open = folded || is_open(app, key, true); + let inner = if folded { depth } else { depth + 1 }; // The folder's eye is its own: hiding it hides its items without changing theirs, and its // items never change it. It and everything in it fade while it or a placement above is // hidden, whatever their own eyes say. let shown = !app.session.folder_hidden(key); let folder_faded = !shown || path.is_some_and(|p| !app.session.occurrence_visible(p)); - let r = draw_row( - ui, - ui.id().with(key), - &Row { - depth, - fold: Some(open), - eye: Some(shown), - icon: "folder", - label: folder_label(folder), - dim: folder_faded, - mark: acts.lit.branch(app, data.entries()), - ..Default::default() - }, - ); + let r = if folded { + RowResp::default() + } else { + draw_row( + ui, + ui.id().with(key), + &Row { + depth, + fold: Some(open), + eye: Some(shown), + icon: "folder", + label: folder_label(folder), + dim: folder_faded, + mark: acts.lit.branch(app, data.entries()), + ..Default::default() + }, + ) + }; if r.fold { toggle(app, key, true); } else if r.clicked { @@ -2368,7 +2412,7 @@ fn folder_rows_at( ui, ui.id().with(gkey), &Row { - depth: depth + 1, + depth: inner, fold: Some(gopen), eye: Some(gshown), icon: "folder", @@ -2403,12 +2447,12 @@ fn folder_rows_at( } if gopen { for e in items { - entry_row(app, ui, comp, path, fstatic, e, depth + 2, Some(id), loose_keys, group_faded, acts); + entry_row(app, ui, comp, path, fstatic, e, inner + 1, Some(id), loose_keys, group_faded, acts); } } } for e in &data.loose { - entry_row(app, ui, comp, path, fstatic, e, depth + 1, None, loose_keys, folder_faded, acts); + entry_row(app, ui, comp, path, fstatic, e, inner, None, loose_keys, folder_faded, acts); } } diff --git a/crates/ui-egui/src/context_menu.rs b/crates/ui-egui/src/context_menu.rs index 692c2655d..2bb9734f3 100644 --- a/crates/ui-egui/src/context_menu.rs +++ b/crates/ui-egui/src/context_menu.rs @@ -398,6 +398,7 @@ pub fn items(app: &SolveApp, target: &Target) -> Vec { .collect(), Target::NamedView { name } => crate::browser::view_items(app, name), }; + v.extend(crate::browser::folded_folder_items(app, target)); // Several items of the folder selected: they can be grouped. if let Some(p) = crate::browser::selection_group(app, target) { v.push(Item::sep()); diff --git a/crates/ui-egui/src/occurrence_ui_tests.rs b/crates/ui-egui/src/occurrence_ui_tests.rs index 7f77c3b2a..5639eb0e2 100644 --- a/crates/ui-egui/src/occurrence_ui_tests.rs +++ b/crates/ui-egui/src/occurrence_ui_tests.rs @@ -335,3 +335,125 @@ fn a_copied_component_pastes_into_its_parent_not_into_itself() { assert!((pasted.transform[3][0] - 50.0).abs() < 1e-9, "where the copied instance is"); assert!(!crate::browser::is_open(&h.app, &format!("o:{}", pasted.id), true), "it arrives folded"); } + +/// #4217: whether a component's Bodies folder folds away, under Always, Several bodies only and +/// Never. Several bodies only (the default) folds a lone body with no groups, Never every +/// component's folder, Always none. The design's own folder, an empty one and a hidden one never +/// fold, and hiding is per placement. +#[test] +fn bodies_folders_fold_by_the_preference_but_never_the_designs_or_a_hidden_one() { + use crate::prefs::BodiesFolders; + let (mut h, component, first, second) = fixture(); + assert_eq!(h.app.preferences.browser_bodies_folders, BodiesFolders::Several, "the default"); + let modes = |h: &mut Harness, comp: u64, scope: &str| { + let bodies = super::entries(&h.app, comp, "bodies").len(); + BodiesFolders::ALL.map(|mode| { + h.app.preferences.browser_bodies_folders = mode; + super::bodies_folded(&h.app, comp, scope, bodies) + }) + }; + let (one, two) = (super::occurrence_key(&[first]), super::occurrence_key(&[second])); + assert_eq!(modes(&mut h, component, &one), [false, true, true], "one body"); + assert_eq!(modes(&mut h, component, &two), [false, true, true], "one body, the other placement"); + h.app.run("solid.box", json!({"length":5,"width":5,"height":5,"corner":[0,40,0]})).unwrap(); + assert_eq!(modes(&mut h, 0, "c0"), [false; 3], "the design's own folder"); + let empty = h.app.run("component.create", json!({"name":"Empty"})).unwrap(); + h.app.run("component.activate", json!({"component":0})).unwrap(); + let empty_scope = super::occurrence_key(&[empty["occurrence"].as_u64().unwrap()]); + assert_eq!(modes(&mut h, empty["component"].as_u64().unwrap(), &empty_scope), [false; 3], "no bodies"); + let show = |h: &mut Harness, visible: bool| { + h.app.run("browser.visibility", json!({"tree_folders":[format!("{one}/bodies")],"visible":visible})).unwrap() + }; + show(&mut h, false); + assert_eq!(modes(&mut h, component, &one), [false; 3], "a hidden folder stays: its eye is the way back"); + assert_eq!(modes(&mut h, component, &two), [false, true, true], "the other placement's folder has its own eye"); + show(&mut h, true); + let group = h.app.run("browser.group", json!({"component":component,"folder":"bodies","items":["Body1"]})).unwrap()["group"].clone(); + assert_eq!(modes(&mut h, component, &one), [false, false, true], "a group"); + h.app.run("browser.ungroup", json!({"group":group})).unwrap(); + assert_eq!(modes(&mut h, component, &one), [false, true, true], "the group gone"); + h.app.run("component.activate", json!({"component":component})).unwrap(); + h.app.run("solid.box", json!({"length":5,"width":5,"height":5,"corner":[20,0,0]})).unwrap(); + h.app.run("component.activate", json!({"component":0})).unwrap(); + assert_eq!(modes(&mut h, component, &one), [false, false, true], "two bodies"); +} + +/// #4217: a folded folder's lone body is drawn one level under its placement, two placements +/// deep, with no Bodies row, even when that folder was closed while it was still drawn (nothing +/// could open it again). Always draws the folder, closed as it was left, then open with the body +/// two levels under the placement. +#[test] +fn a_folded_body_sits_one_level_under_its_nested_placement() { + use crate::prefs::BodiesFolders; + let mut h = Harness::new(); + let parent = h.app.run("component.create", json!({"name":"Assembly"})).unwrap()["occurrence"].as_u64().unwrap(); + let child = h.app.run("component.create", json!({"name":"Child"})).unwrap()["occurrence"].as_u64().unwrap(); + h.app.run("solid.box", json!({"length":10,"width":10,"height":10,"body_name":"Pin"})).unwrap(); + h.app.run("component.activate", json!({"component":0})).unwrap(); + h.app.tree.collapsed.insert(format!("{}/bodies", super::occurrence_key(&[parent, child]))); + // How many levels the body's row sits under its placement's (each eye sits at the same offset + // in its row). + let levels = || -> Option { + let placement = crate::scenario::handle_at(&format!("eye:occurrence:{parent}/{child}"))?; + let body = crate::scenario::handle_at("eye:Pin")?; + Some(((body.x - placement.x) / super::INDENT).round() as i32) + }; + for (mode, want) in [(BodiesFolders::Several, Some(1)), (BodiesFolders::Never, Some(1)), (BodiesFolders::Always, None)] { + h.app.preferences.browser_bodies_folders = mode; + h.frames(2); + assert_eq!(levels(), want, "{mode:?}"); + assert_eq!(crate::scenario::handle_at("fold:Bodies").is_some(), mode == BodiesFolders::Always, "{mode:?}: the Bodies row"); + } + h.app.tree.collapsed.clear(); + h.frames(2); + assert_eq!(levels(), Some(2), "Always, open: under the Bodies folder"); +} + +/// #4217: Find in Browser reaches a body whose folder is folded away: its closed placement opens +/// and the body's row is drawn and scrolled to. +#[test] +fn find_in_browser_reaches_a_folded_body() { + let (mut h, _, first, second) = fixture(); + let body = h.app.session.occurrence_bodies(&[second], true).unwrap()[0].clone(); + let scope = super::occurrence_key(&[second]); + h.app.tree.collapsed.extend([super::occurrence_key(&[first]), scope.clone(), format!("{scope}/bodies")]); + h.frames(2); + assert!(!h.app.tree.order.contains(&format!("b:{body}")), "the body's row is closed away"); + h.app.session.selection = vec![Sel::Body { name: body.clone() }]; + let find = context_menu::items(&h.app, &Target::Viewport).into_iter().find(|i| i.id == "ui.findBrowser").unwrap(); + context_menu::run_item(&mut h.app, &find, egui::Pos2::ZERO); + assert_eq!(h.app.tree.reveal.as_deref(), Some(body.as_str())); + h.frames(2); + assert!(h.app.tree.reveal.is_none(), "revealed"); + assert!(!h.app.tree.collapsed.contains(&scope)); + assert!(h.app.tree.order.contains(&format!("b:{body}")), "the row is drawn"); + assert!(crate::scenario::handle_at("fold:Bodies").is_none(), "with no folder row"); +} + +/// #4217: while a placement's Bodies folder is folded away, the placement's menu takes the +/// folder's items it lacks: Create Components from Bodies (the folder's bodies) and, with several +/// of them selected, Group Selected. With the folder drawn they stay on the folder's own menu. +#[test] +fn a_folded_folders_menu_items_move_to_the_placements_menu() { + use crate::prefs::BodiesFolders; + let (mut h, component, first, _) = fixture(); + h.app.run("component.activate", json!({"component":component})).unwrap(); + h.app.run("solid.box", json!({"length":5,"width":5,"height":5,"corner":[20,0,0],"body_name":"Second"})).unwrap(); + h.app.run("component.activate", json!({"component":0})).unwrap(); + let target = Target::Occurrence { path: vec![first] }; + let has = |h: &Harness, id: &str| context_menu::items(&h.app, &target).iter().any(|i| i.id == id); + assert!(!has(&h, "component.from_bodies"), "Several bodies only: two bodies keep their folder"); + h.app.preferences.browser_bodies_folders = BodiesFolders::Never; + let items = context_menu::items(&h.app, &target); + let from = items.iter().find(|i| i.id == "component.from_bodies").unwrap(); + assert_eq!(from.params.as_ref().unwrap()["bodies"], json!(["Body1", "Second"])); + assert!(has(&h, "ui.newGroup") && has(&h, "ui.showAll"), "on every component's menu"); + assert!(!has(&h, "ui.groupSelected"), "nothing selected"); + h.app.session.selection = vec![Sel::Body { name: "Body1".into() }, Sel::Body { name: "Second".into() }]; + let group = context_menu::items(&h.app, &target).into_iter().find(|i| i.id == "ui.groupSelected").unwrap(); + context_menu::run_item(&mut h.app, &group, egui::Pos2::ZERO); + let made = h.app.session.doc.browser_groups.iter().find(|g| g.component == component).unwrap(); + assert_eq!(made.items, ["Body1", "Second"]); + h.app.preferences.browser_bodies_folders = BodiesFolders::Always; + assert!(!has(&h, "component.from_bodies"), "Always: on the folder's own menu"); +} diff --git a/crates/ui-egui/src/prefs.rs b/crates/ui-egui/src/prefs.rs index 7ca3f10f4..ed38ccedd 100644 --- a/crates/ui-egui/src/prefs.rs +++ b/crates/ui-egui/src/prefs.rs @@ -596,6 +596,35 @@ pub const DEFAULT_BROWSER_WIDTH: f32 = 250.0; /// split; the column clamps what the user drags so both cards keep their header and two rows. pub const DEFAULT_BROWSER_SHARE: f32 = 0.5; +/// When a component's bodies sit in a Bodies folder of their own in the browser (#4217): each +/// folder is one more level that pushes deep assemblies right. Only folders inside components +/// fold; the design's own Bodies folder, and a folder hidden with its eye (its eye is the way +/// back), always stay (`browser::bodies_folded`). +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] +#[serde(rename_all = "snake_case")] +pub enum BodiesFolders { + Always, + /// A component with one body and no groups lists the body straight under it. Also what a + /// value this version doesn't know reads as (`lenient`). + #[default] + Several, + /// Components list their bodies and groups straight under them. + Never, +} + +impl BodiesFolders { + pub const ALL: [Self; 3] = [Self::Always, Self::Several, Self::Never]; + + /// Its name in the Preferences (a message id). + pub fn label_id(self) -> &'static str { + match self { + Self::Always => "prefs.bodies_folders_always", + Self::Several => "prefs.bodies_folders_several", + Self::Never => "prefs.bodies_folders_never", + } + } +} + // The stored fields, their defaults, page resets and simple form controls share this table. // Omitted pages keep fields such as grid_follows_view and added agents when restoring defaults. // Accepted control-channel ranges may differ from slider ranges (look_at_speed). @@ -834,6 +863,8 @@ preference_settings! { dialog_place: crate::dialog_column::DialogPlace = Default::default(), PAGE_INTERFACE; /// The names the browser, dialogs and lists show for the origin planes (#6491). origin_plane_names: OriginPlaneNames = OriginPlaneNames::default(), PAGE_INTERFACE; + /// When components' bodies sit in a Bodies folder in the browser (#4217). + browser_bodies_folders: BodiesFolders = BodiesFolders::Several, PAGE_INTERFACE; /// The wheel zooms toward the point under the cursor (else toward the view's centre). zoom_to_cursor: bool = true, PAGE_NAVIGATION => check("Zoom to the cursor", "The wheel zooms toward the point under the cursor (off: toward the view's centre)"); /// Spread discrete wheel input across frames (off: apply each event immediately). @@ -3912,6 +3943,39 @@ mod tests { assert_eq!(app.preferences.ui_font, ""); } + /// Bodies folders (#4217): Several bodies only by default, also in preferences saved before it + /// existed. Each value is saved and read back; `ui.prefs` refuses anything else and changes + /// nothing, and saved preferences read such a value as the default and keep the rest. The + /// Interface page's segments set it, Cancel puts it back and the page's Restore Defaults resets it. + #[test] + fn bodies_folders_is_saved_restored_and_refuses_unknown_values() { + use super::*; + let mut h = crate::scenario::Harness::new(); + assert_eq!(h.app.preferences.browser_bodies_folders, BodiesFolders::Several); + assert_eq!(lenient(&json!({"theme": "light"})).browser_bodies_folders, BodiesFolders::Several, "saved before it existed"); + for (mode, id) in [(BodiesFolders::Always, "always"), (BodiesFolders::Several, "several"), (BodiesFolders::Never, "never")] { + assert_eq!(control(&mut h.app, &json!({"browser_bodies_folders": id})).unwrap()["browser_bodies_folders"], id); + let mut restored = SolveApp::new(Default::default(), Default::default()); + restored.load_prefs(&h.app.prefs()); + assert_eq!(restored.preferences.browser_bodies_folders, mode, "{id}"); + } + for bad in [json!("sometimes"), json!("Never"), json!(""), json!(2), json!(null), json!(["never"])] { + let before = h.app.preferences.clone(); + assert!(set(&mut h.app, &json!({"browser_bodies_folders": bad})).is_err(), "{bad}"); + assert_eq!(h.app.preferences, before, "{bad}: a refused value changes nothing"); + let saved = lenient(&json!({"browser_bodies_folders": bad, "theme": "light"})); + assert_eq!((saved.browser_bodies_folders, saved.theme.as_str()), (BodiesFolders::Several, "light"), "{bad}"); + } + h.call("ui.prefs", json!({"open": "Interface"})); + reveal_preference(&mut h, "dialog:Bodies folders:Always"); + h.step(&json!({"click": {"handle": "dialog:Bodies folders:Always"}})).unwrap(); + assert_eq!(h.app.preferences.browser_bodies_folders, BodiesFolders::Always); + h.call("ui.prefs", json!({"button": "cancel"})); + assert_eq!(h.app.preferences.browser_bodies_folders, BodiesFolders::Never, "Cancel puts it back"); + defaults(&mut h.app, PAGE_INTERFACE); + assert_eq!(h.app.preferences.browser_bodies_folders, BodiesFolders::Several, "Interface's Restore Defaults"); + } + /// Theme files (#2255): a built-in one and an imported one turn on through `ui.prefs`, the /// next frame draws with their colours (dark following the base), an export gives the theme /// back complete, imported themes are saved with the preferences, Remove falls back to the diff --git a/crates/ui-egui/src/prefs/interface.rs b/crates/ui-egui/src/prefs/interface.rs index c692872be..112fb828b 100644 --- a/crates/ui-egui/src/prefs/interface.rs +++ b/crates/ui-egui/src/prefs/interface.rs @@ -159,6 +159,16 @@ pub(super) fn interface(app: &mut SolveApp, ui: &mut egui::Ui, t: &Tokens) { let check = setting::view_confirm_corner(app, ui).on_hover_text(app.tr("prefs.view_confirm_corner_note")); crate::scenario::publish_target("prefs:view_confirm_corner", check.rect); }); + ui_kit::row(ui, app.tr("prefs.bodies_folders"), |ui| { + let modes = BodiesFolders::ALL; + let labels: Vec<_> = modes.iter().map(|m| app.tr(m.label_id())).collect(); + let mut selected = modes.iter().position(|m| *m == app.preferences.browser_bodies_folders).unwrap_or(0); + if ui_kit::segmented(ui, &mut selected, &labels, ui_kit::Segments { proportional: true, compact: true, ..Default::default() }) + && let Some(mode) = modes.get(selected) + { + app.preferences.browser_bodies_folders = *mode; + } + }); ui_kit::text(ui, app.tr("prefs.layout_note"), ui_kit::Text::Hint("layout")); ui_kit::text(ui, app.tr("prefs.history_sketches_note"), ui_kit::Text::Hint("history_sketches")); ui_kit::LayoutPreview { diff --git a/crates/ui-egui/tests/scenarios/browser_bodies_folders.json b/crates/ui-egui/tests/scenarios/browser_bodies_folders.json new file mode 100644 index 000000000..df3c8c128 --- /dev/null +++ b/crates/ui-egui/tests/scenarios/browser_bodies_folders.json @@ -0,0 +1,33 @@ +[ + {"note": "Bodies folders (#4217, Preferences › Interface): a nested assembly of plain boxes. Frame:1 holds the body Plate and the placement Pin:1, which holds the body Shaft. The design itself has no bodies, so every Bodies row is a component's."}, + {"call": "engine.execute", "params": {"command": "component.create", "params": {"name": "Frame"}}}, + {"call": "engine.execute", "params": {"command": "solid.box", "params": {"length": 40, "width": 20, "height": 5, "body_name": "Plate"}}}, + {"call": "engine.execute", "params": {"command": "component.create", "params": {"name": "Pin"}}}, + {"call": "engine.execute", "params": {"command": "solid.box", "params": {"length": 4, "width": 4, "height": 20, "corner": [0, 40, 0], "body_name": "Shaft"}}}, + {"call": "engine.execute", "params": {"command": "component.activate", "params": {"component": "root"}}}, + {"expect": {"bodies": 2, "errors": 0, "prefs": {"browser_bodies_folders": "several"}}}, + + {"note": "Several bodies only (the default): each lone body sits straight under its placement, one level in, with no Bodies row."}, + {"expect": {"browser_has": ["Frame:1", "Plate", "Pin:1", "Shaft"], "browser_lacks": ["Bodies"], "handle_order": ["eye:Frame:1", "eye:Plate"]}}, + {"expect": {"handle_order": ["eye:Pin:1", "eye:Shaft"]}}, + + {"note": "A second body in Frame brings Frame's folder back; Pin's lone body stays folded."}, + {"call": "engine.execute", "params": {"command": "component.activate", "params": {"component": "Frame"}}}, + {"call": "engine.execute", "params": {"command": "solid.box", "params": {"length": 5, "width": 20, "height": 15, "corner": [60, 0, 0], "body_name": "Rib"}}}, + {"call": "engine.execute", "params": {"command": "component.activate", "params": {"component": "root"}}}, + {"expect": {"bodies": 3, "browser_has": ["Bodies", "Plate", "Rib", "Shaft"], "handle_order": ["eye:Bodies", "eye:Plate"]}}, + + {"note": "Never: every component's bodies sit straight under it, two of them too."}, + {"call": "ui.prefs", "params": {"browser_bodies_folders": "never"}}, + {"expect": {"prefs": {"browser_bodies_folders": "never"}, "browser_has": ["Plate", "Rib", "Shaft"], "browser_lacks": ["Bodies"]}}, + + {"note": "Always: every component keeps its folder, Pin's too (the last Bodies row drawn, between Pin:1 and Shaft)."}, + {"call": "ui.prefs", "params": {"browser_bodies_folders": "always"}}, + {"expect": {"prefs": {"browser_bodies_folders": "always"}, "browser_has": ["Bodies", "Plate", "Rib", "Shaft"], "handle_order": ["eye:Pin:1", "eye:Bodies", "eye:Shaft"]}}, + + {"note": "A value this version doesn't know is refused and changes nothing."}, + {"call": "ui.prefs", "params": {"browser_bodies_folders": "sometimes"}, "fail": true}, + {"expect": {"prefs": {"browser_bodies_folders": "always"}}}, + {"call": "ui.prefs", "params": {"browser_bodies_folders": "several"}}, + {"expect": {"prefs": {"browser_bodies_folders": "several"}, "browser_has": ["Bodies", "Rib", "Shaft"]}} +] diff --git a/crates/ui-egui/tests/scenarios/s37_browser_chevrons.json b/crates/ui-egui/tests/scenarios/s37_browser_chevrons.json index ecb428306..786335986 100644 --- a/crates/ui-egui/tests/scenarios/s37_browser_chevrons.json +++ b/crates/ui-egui/tests/scenarios/s37_browser_chevrons.json @@ -2,6 +2,15 @@ { "note": "Browser chevrons expand and collapse every kind of node (folders, components, groups, the origin, named views, document settings). Model: two components with a body each, a joint, a sketch, an offset plane, a named view." }, + { + "note": "Each component keeps its Bodies folder (Preferences › Interface › Bodies folders: Always), so that folder's chevron is checked too." + }, + { + "call": "ui.prefs", + "params": { + "browser_bodies_folders": "always" + } + }, { "start": "component.create" }, diff --git a/docs/book/src/guide/ui-tour.md b/docs/book/src/guide/ui-tour.md index 26088578d..54378238a 100644 --- a/docs/book/src/guide/ui-tour.md +++ b/docs/book/src/guide/ui-tour.md @@ -19,7 +19,12 @@ hides an item, a component's radio button makes it the active component, and right-clicking any row gives that item's menu. Right-click the design or a component and choose **Expand All** or **Collapse All** to open or close every folder under that row (the design row stays visible - when the whole tree is collapsed). Rows drag into groups and other components. + when the whole tree is collapsed). Rows drag into groups and other components. **Preferences › + Interface › Bodies folders** sets when a component's bodies sit in a Bodies folder of their own: + **Several bodies only** (the default) lists a component's body straight under it when it has + only one and no groups, **Never** lists every component's bodies and groups straight under it + (the folder's menu items are then on the component's menu), and **Always** keeps the folder. + The design's own Bodies folder, and a folder hidden with its eye, always stay. - **Viewport.** Click to select, Shift or Ctrl to add (Preferences › Selection), drag for a window or crossing box. While sketching, Ctrl/Cmd or Alt/Option suppress auto-snap by default; Shift prefers a midpoint; the pointer also snaps to where two curves cross. To reach something under something else (two lines drawn on top of each other, coincident points, an edge in front of a face, overlapping bodies), hold the left button still for half a second diff --git a/docs/control-protocol.md b/docs/control-protocol.md index 870f95fae..5f5f31b7d 100644 --- a/docs/control-protocol.md +++ b/docs/control-protocol.md @@ -303,7 +303,7 @@ labels; `prefs:measure_axis_distances` identifies the checkbox. | `ui.home` | `open?`: bool; `sample?`: index | the start page: show or hide it, open a built-in sample (once built); returns `open` and the recent designs | | `ui.shortcut` | `command`, `key?`, `replace?` | a command's key, or rebinds it (`""` clears; a key another command uses is refused unless `replace`) | | `ui.help` | `item?`: `about`, `shortcuts` (read only), `report` (opens a report draft for review), `crashes` (the Crash Reports window) | the version, commit, build date and diagnostic text | -| `ui.prefs` | any of `default_units`, `nav` (`fusion`, `solidworks`, `inventor`, `alias`, `blender`, `tinkercad`, `openscad`, `touchpad`), `zoom_reverse`, `pan_reverse_x` (default false: horizontal scrolling pans the other way), `zoom_to_cursor`, `smooth_wheel_zoom` (default true), `trackpad_pan` (default true: two-finger scroll pans, except Touchpad always zooms; pinch zooms), `orbit_around` (`view_centre` (default: what Pan moves and Fit frames), `origin` (the world origin stays still on screen), `cursor` (the model point under the pointer when the drag began); the older `orbit_cursor` boolean still sets `cursor` when true), `sketch_exit_view` (`keep` (default: the view stays where it is when a sketch ends), `previous` (back to the view from before the sketch), `unless_rotated` (back unless the sketch view was turned)), `look_at_anim`, `look_at_speed`, `middle_double_click` (`home` (default), `fit`, `off`), `msaa`, `show_frame_rate` (default false: frames per second in the view's bottom-right corner, counting the frames the view draws anyway; it reads 0 FPS once the view is idle), `window_system` (Linux: `auto` (default: XWayland whenever there is an X display, native Wayland on niri), `wayland`, `x11`; saved in `graphics.json`, applies at the next start; `SOLIDCRAFT_WAYLAND` overrides it), `graphics_adapter` (exact card name, or empty for Automatic; applies after restart; `WGPU_ADAPTER_NAME` takes precedence), `frame_rate_details` (default false: with the frame rate, a frame-time graph of the frames drawn with the triangles over it, a frame-time histogram and what the GPU drew; clicking the readout switches it), `length_decimals`, `angle_decimals`, `step_values` (default false: Up/Down and the wheel step a plain number in a focused value field), `theme` (`dark`, `light`, `system` or a theme file's id: a built-in one such as `gruvbox-dark`, or an imported one; the reply's `theme_ids` lists them), `viewport_theme` (`theme` (default: the theme's own), `light`, `dark`: the 3D view in the Light or Dark theme's colours whatever the window uses, #4146), `theme_import` (a `solidcraft-theme/1` file's JSON or text: adds the theme and turns it on; the reply's `theme_imported` is its id), `theme_remove` (an imported theme's id), `theme_export: true` (the reply's `theme_file` is the theme on now as a complete file; see [colour themes](book/src/guide/ui-tour.md#colour-themes)), `theme_follow` (desktop only, default `""`: a `solidcraft-theme/1` file's path to follow as the theme, reloaded within about a second whenever it changes and when the window gains the focus; the file is read at once, and a file that doesn't read keeps the last good theme; `""` stops following, as does setting `theme`; in the browser it is an error; the launch flag `--theme-file PATH` follows a file for one run without saving it; the reply's `theme_followed` is the path followed now or null, and `theme_follow_error` why its last read was not applied, or null), `language` (`en`, `ar`, `ja`, `de`, `fr`, `he`, `ko`, `ms`, `ru`, `uk`, `zh`; see [localization](localization.md)), `ui_scale`, `ui_font` (an installed font family or a font file for the interface; empty for the built-in font), `up_axis` (`z`, `y`), `offer_stand_up`, `extrude_auto_to_object` (default false: in the Extrude dialog, with a profile picked, a face, vertex or parallel plane picked off its plane switches the extent to To Object; it applies to Extrude dialogs opened afterwards), `hole_snaps` (default false: a Single hole snaps to its face's middle and round edges' centres), `hole_moves` (default false: a placed Single hole has a drag handle (`hole:`), and a pick on a face that has a hole moves it there), `placement_handles` (default false: handles on the preview of a Rest, Boss or Snap Fit that move it across the model and turn it), `color_vision` (`off` (default), `protan`, `deutan`, `tritan`: colour vision modes, #778), `view_confirm_corner` (default false: while a dialog or a sketch is open, a check and a cross at the view's top right, handles `view:confirm:ok` and `view:confirm:cancel`, do what the dialog's OK and Cancel do, or Finish Sketch and Cancel Sketch; the axis view or cube moves down below them, #6709), `history_sketches` (`in_order` (default), `under_feature`: the History at the left lists a sketch under the first feature built from it, #6489; the timeline at the bottom keeps the creation order), `dialog_buttons` (`bottom` (default), `top`: a feature dialog's OK, Cancel and Apply sit in its title row instead of under its inputs, #6708; the buttons keep their handles, and `dialog:close` is then Cancel's), `timeline_origin_bodies` (default false: the History on the left or under the browser starts with the active component's Bodies folder and the Origin, the browser's rows with their eyes, folds and menus; the bottom History is unchanged), `origin_plane_names` (`xyz` (default) or `top_front_right`: the browser, dialogs and lists call the origin planes Top, Front and Right; their ids, commands and saved designs keep XY, XZ and YZ), `dialog_place` (`edge` (default) or `left_column`: command dialogs open in the left column in place of the browser and the History, #6707), `check_updates` (default true; [updates](book/src/guide/updates.md)), `nav_bridge_enabled` (default false) and `nav_bridge_port` (default 8765: a device's own app on this computer moves the view, [the navigation bridge](3d-mouse.md#device-apps-the-navigation-bridge)); `open` (a page: General, Interface, Design, Navigation, Keyboard Shortcuts, Sketch, Graphics, AI, Plugins; Shortcuts, Assistant and Sketch & selection are aliases, and the former Selection page opens Sketch) opens the Preferences dialog there; `button`: `ok`, `cancel`, `apply`, `defaults`; `stand_up: true` stands up a just-opened Y-up file, `stand_up: false` leaves it as it is ("Leave it": the offer closes and `offer_stand_up` stays on); the offer's buttons are the handles `stand_up:stand`, `stand_up:leave` and `stand_up:never` | sets preferences (kept between runs), returns them all plus `dialog` (the open page or null), `dark`, `viewport_dark` (whether the 3D view is dark), `stand_up_offer`, `theme_followed` and `theme_follow_error` | +| `ui.prefs` | any of `default_units`, `nav` (`fusion`, `solidworks`, `inventor`, `alias`, `blender`, `tinkercad`, `openscad`, `touchpad`), `zoom_reverse`, `pan_reverse_x` (default false: horizontal scrolling pans the other way), `zoom_to_cursor`, `smooth_wheel_zoom` (default true), `trackpad_pan` (default true: two-finger scroll pans, except Touchpad always zooms; pinch zooms), `orbit_around` (`view_centre` (default: what Pan moves and Fit frames), `origin` (the world origin stays still on screen), `cursor` (the model point under the pointer when the drag began); the older `orbit_cursor` boolean still sets `cursor` when true), `sketch_exit_view` (`keep` (default: the view stays where it is when a sketch ends), `previous` (back to the view from before the sketch), `unless_rotated` (back unless the sketch view was turned)), `look_at_anim`, `look_at_speed`, `middle_double_click` (`home` (default), `fit`, `off`), `msaa`, `show_frame_rate` (default false: frames per second in the view's bottom-right corner, counting the frames the view draws anyway; it reads 0 FPS once the view is idle), `window_system` (Linux: `auto` (default: XWayland whenever there is an X display, native Wayland on niri), `wayland`, `x11`; saved in `graphics.json`, applies at the next start; `SOLIDCRAFT_WAYLAND` overrides it), `graphics_adapter` (exact card name, or empty for Automatic; applies after restart; `WGPU_ADAPTER_NAME` takes precedence), `frame_rate_details` (default false: with the frame rate, a frame-time graph of the frames drawn with the triangles over it, a frame-time histogram and what the GPU drew; clicking the readout switches it), `length_decimals`, `angle_decimals`, `step_values` (default false: Up/Down and the wheel step a plain number in a focused value field), `theme` (`dark`, `light`, `system` or a theme file's id: a built-in one such as `gruvbox-dark`, or an imported one; the reply's `theme_ids` lists them), `viewport_theme` (`theme` (default: the theme's own), `light`, `dark`: the 3D view in the Light or Dark theme's colours whatever the window uses, #4146), `theme_import` (a `solidcraft-theme/1` file's JSON or text: adds the theme and turns it on; the reply's `theme_imported` is its id), `theme_remove` (an imported theme's id), `theme_export: true` (the reply's `theme_file` is the theme on now as a complete file; see [colour themes](book/src/guide/ui-tour.md#colour-themes)), `theme_follow` (desktop only, default `""`: a `solidcraft-theme/1` file's path to follow as the theme, reloaded within about a second whenever it changes and when the window gains the focus; the file is read at once, and a file that doesn't read keeps the last good theme; `""` stops following, as does setting `theme`; in the browser it is an error; the launch flag `--theme-file PATH` follows a file for one run without saving it; the reply's `theme_followed` is the path followed now or null, and `theme_follow_error` why its last read was not applied, or null), `language` (`en`, `ar`, `ja`, `de`, `fr`, `he`, `ko`, `ms`, `ru`, `uk`, `zh`; see [localization](localization.md)), `ui_scale`, `ui_font` (an installed font family or a font file for the interface; empty for the built-in font), `up_axis` (`z`, `y`), `offer_stand_up`, `extrude_auto_to_object` (default false: in the Extrude dialog, with a profile picked, a face, vertex or parallel plane picked off its plane switches the extent to To Object; it applies to Extrude dialogs opened afterwards), `hole_snaps` (default false: a Single hole snaps to its face's middle and round edges' centres), `hole_moves` (default false: a placed Single hole has a drag handle (`hole:`), and a pick on a face that has a hole moves it there), `placement_handles` (default false: handles on the preview of a Rest, Boss or Snap Fit that move it across the model and turn it), `color_vision` (`off` (default), `protan`, `deutan`, `tritan`: colour vision modes, #778), `view_confirm_corner` (default false: while a dialog or a sketch is open, a check and a cross at the view's top right, handles `view:confirm:ok` and `view:confirm:cancel`, do what the dialog's OK and Cancel do, or Finish Sketch and Cancel Sketch; the axis view or cube moves down below them, #6709), `history_sketches` (`in_order` (default), `under_feature`: the History at the left lists a sketch under the first feature built from it, #6489; the timeline at the bottom keeps the creation order), `dialog_buttons` (`bottom` (default), `top`: a feature dialog's OK, Cancel and Apply sit in its title row instead of under its inputs, #6708; the buttons keep their handles, and `dialog:close` is then Cancel's), `timeline_origin_bodies` (default false: the History on the left or under the browser starts with the active component's Bodies folder and the Origin, the browser's rows with their eyes, folds and menus; the bottom History is unchanged), `origin_plane_names` (`xyz` (default) or `top_front_right`: the browser, dialogs and lists call the origin planes Top, Front and Right; their ids, commands and saved designs keep XY, XZ and YZ), `dialog_place` (`edge` (default) or `left_column`: command dialogs open in the left column in place of the browser and the History, #6707), `browser_bodies_folders` (`several` (default): a component with one body and no groups lists it straight under the component in the browser, without a Bodies folder; `always`; `never`: components list their bodies and groups straight under them, and the folder's menu items are on the component's menu; the design's own Bodies folder, and one hidden with its eye, always show; #4217), `check_updates` (default true; [updates](book/src/guide/updates.md)), `nav_bridge_enabled` (default false) and `nav_bridge_port` (default 8765: a device's own app on this computer moves the view, [the navigation bridge](3d-mouse.md#device-apps-the-navigation-bridge)); `open` (a page: General, Interface, Design, Navigation, Keyboard Shortcuts, Sketch, Graphics, AI, Plugins; Shortcuts, Assistant and Sketch & selection are aliases, and the former Selection page opens Sketch) opens the Preferences dialog there; `button`: `ok`, `cancel`, `apply`, `defaults`; `stand_up: true` stands up a just-opened Y-up file, `stand_up: false` leaves it as it is ("Leave it": the offer closes and `offer_stand_up` stays on); the offer's buttons are the handles `stand_up:stand`, `stand_up:leave` and `stand_up:never` | sets preferences (kept between runs), returns them all plus `dialog` (the open page or null), `dark`, `viewport_dark` (whether the 3D view is dark), `stand_up_offer`, `theme_followed` and `theme_follow_error` | | `ui.capture` | `action?`: `capture`, `revert`, `cancel` | answers the Capture Position question (asked when a command starts or the design is saved while components were moved without capturing); without `action`, what waits | | `ui.window` | `action`: minimize, maximize, restore, toggle, close | what the title bar's caption buttons do (on Windows and Linux the application bar is the title bar); close asks about unsaved designs first | | `ui.agent_cursor` | `show` (bool), `speed`: a number from 1 to 5 (times the normal speed) or `"instant"` (no animation: the command runs at once and the pointer jumps to where it acted), `follow_camera` (bool); all optional | the settings. While the cursor is shown, `engine.execute` first glides to the command's toolbar button and to each pick, then runs and replies; later requests wait their turn. The pointer shows the command's localized name, including commands inside a closed toolbar group; an animated batch names each command it visits. It also follows the pointer input sent with `ui.move`, `ui.click`, `ui.drag` and `ui.scroll`, as each event reaches the app, and a press leaves a ripple. `"animate": false` on a call skips it |