Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

Browser: the component menu keeps its everyday actions and groups the rest in flyouts (#8769) (#8770)

Christian Hammacher4a906699eeaa
diff --git a/assets/locales/pending/component-menu-organize.json b/assets/locales/pending/component-menu-organize.json
new file mode 100644
index 0000000000..b2e98399ca
--- /dev/null
+++ b/assets/locales/pending/component-menu-organize.json
@@ -0,0 +1,29 @@
+{
+ "en": {
+ "ui.organize": "Organize"
+ },
+ "en-GB": {
+ "ui.organize": "Organise"
+ },
+ "ar": {
+ "ui.organize": "تنظيم"
+ },
+ "de": {
+ "ui.organize": "Organisieren"
+ },
+ "he": {
+ "ui.organize": "ארגון"
+ },
+ "ja": {
+ "ui.organize": "整理"
+ },
+ "ko": {
+ "ui.organize": "정리"
+ },
+ "vi": {
+ "ui.organize": "Sắp xếp"
+ },
+ "zh": {
+ "ui.organize": "整理"
+ }
+}
diff --git a/crates/ui-egui/src/browser.rs b/crates/ui-egui/src/browser.rs
index c84c1c87da..568a133828 100644
--- a/crates/ui-egui/src/browser.rs
+++ b/crates/ui-egui/src/browser.rs
@@ -557,11 +557,18 @@ pub fn folded_folder_items(app: &SolveApp, target: &Target) -> Vec<Item> {
},
_ => return Vec::new(),
};
- if !bodies_folded(app, comp, &scope, entries(app, comp, "bodies").len()) {
+ let count = entries(app, comp, "bodies").len();
+ if !bodies_folded(app, comp, &scope, count) {
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"));
+ // Components from a component's only body would just nest it one level deeper.
+ let items: Vec<_> = folder_items(app, comp, "bodies", &scope)
+ .into_iter()
+ .filter(|i| i.id == "ui.groupSelected" || (i.id == "component.from_bodies" && count > 1))
+ .collect();
+ if items.is_empty() {
+ return items;
+ }
std::iter::once(Item::sep()).chain(items).collect()
}
diff --git a/crates/ui-egui/src/context_menu.rs b/crates/ui-egui/src/context_menu.rs
index 05e0c2ce4c..5235cfc29e 100644
--- a/crates/ui-egui/src/context_menu.rs
+++ b/crates/ui-egui/src/context_menu.rs
@@ -225,11 +225,14 @@ pub struct MenuState {
pub target: Target,
/// The list row chosen with the arrow keys (Enter runs it).
pub key_row: Option<usize>,
- submenu: Option<usize>,
+ /// The open flyouts: the row of the menu that opened the first, the row of that flyout that
+ /// opened the second, and so on.
+ submenu: Vec<usize>,
+ /// The row chosen with the arrow keys in the innermost open flyout.
submenu_key: Option<usize>,
- /// When the pointer came to rest on another row while a flyout was open (it closes the
- /// flyout after [`crate::ui_kit::SUBMENU_CLOSE_DELAY`]).
- submenu_leave: Option<f64>,
+ /// The level the pointer came to rest on another row of while a flyout further in was open,
+ /// and when (it closes the flyouts further in after [`crate::ui_kit::SUBMENU_CLOSE_DELAY`]).
+ submenu_leave: Option<(usize, f64)>,
/// The radial ring is shown (viewport menus).
pub radial: bool,
/// The right button is held through the menu: releasing over a direction picks it.
@@ -531,9 +534,9 @@ pub fn items(app: &SolveApp, target: &Target) -> Vec<Item> {
v.push(Item::sep());
v.push(act("ui.groupSelected", "Group Selected", "folder").with(p));
}
- for item in &mut v {
+ each_item(&mut v, &mut |item: &mut Item| {
if item.id != "ui.appearance" {
- continue;
+ return;
}
// A selected browser body keeps the selection for the editor and its quick choices.
// A row outside the selection still targets only the body that was right-clicked.
@@ -575,7 +578,7 @@ pub fn items(app: &SolveApp, target: &Target) -> Vec<Item> {
item.children.push(Item::sep());
item.children.push(cmd(app, "appearance.assign", "Remove override").with(targets));
}
- }
+ });
v
}
@@ -948,55 +951,57 @@ fn occurrence_items(app: &SolveApp, path: &[u64]) -> Vec<Item> {
let bodies = app.session.occurrence_bodies(path, true).unwrap_or_default();
// The component's menu asks its first placement; this row may be another one.
let movable = !placement.grounded && app.session.held_by_rigid_group(placement.occurrence).is_none();
- for item in &mut entries {
- match item.id.as_str() {
- "ui.activate" => {
- item.params = Some(json!({"component": placement.component, "occurrence": placement.occurrence, "path": path}));
- item.enabled = app.session.active_occurrence_path.as_deref() != Some(path);
- }
- "ui.editInPlace" => item.params = Some(json!({"component": placement.component, "path": path})),
- "occurrence.ground" => {
- item.label = if placement.grounded { "Unground" } else { "Ground" }.into();
- item.params = Some(json!({"occurrence": placement.occurrence, "grounded": !placement.grounded}));
- }
- "ui.moveOccurrence" => {
- item.params = Some(json!({"occurrence": placement.occurrence, "path": path}));
- item.enabled = movable;
- }
- "ui.properties" => item.params = Some(json!({"occurrence": placement.occurrence, "path": path})),
- "ui.turnUpAxis" => {
- item.enabled = movable;
- for child in &mut item.children {
- child.enabled = movable;
- if let Some(params) = child.params.as_mut() {
- params["occurrence"] = json!(placement.occurrence);
- }
- }
- }
- "occurrence.copy" => item.params = Some(json!({"occurrence": placement.occurrence, "translate": [10,10,0]})),
- "ui.paste" | "ui.pasteNew" => item.params = Some(json!({"component": placement.component, "path": path})),
- "component.create" => item.params = Some(json!({"parent": placement.component, "parent_path": path})),
- "ui.rename" => item.label = "Rename Component".into(),
- "ui.appearance" => item.label = "Component Appearance".into(),
- "ui.material" => item.label = "Component Physical Material".into(),
- "ui.delete" => item.params = Some(json!({"occurrences": [placement.occurrence]})),
- "ui.hide" | "ui.show" => {
- item.id = "browser.visibility".into();
- item.params = Some(json!({"visible": app.session.occurrence_hidden(path), "paths": [path]}));
- item.enabled = true;
- }
- "ui.isolate" => {
- item.id = "ui.isolateOccurrence".into();
- item.params = Some(json!({"path": path}));
+ each_item(&mut entries, &mut |item: &mut Item| match item.id.as_str() {
+ "ui.activate" => {
+ item.params = Some(json!({"component": placement.component, "occurrence": placement.occurrence, "path": path}));
+ item.enabled = app.session.active_occurrence_path.as_deref() != Some(path);
+ }
+ "ui.editInPlace" => item.params = Some(json!({"component": placement.component, "path": path})),
+ "occurrence.ground" => {
+ item.label = if placement.grounded { "Unground" } else { "Ground" }.into();
+ item.params = Some(json!({"occurrence": placement.occurrence, "grounded": !placement.grounded}));
+ }
+ "ui.moveOccurrence" => {
+ item.params = Some(json!({"occurrence": placement.occurrence, "path": path}));
+ item.enabled = movable;
+ }
+ "ui.properties" => item.params = Some(json!({"occurrence": placement.occurrence, "path": path})),
+ "ui.turnUpAxis" => item.enabled = movable,
+ "occurrence.move" => {
+ item.enabled = movable;
+ if let Some(params) = item.params.as_mut() {
+ params["occurrence"] = json!(placement.occurrence);
}
- "ui.export" | "ui.saveMesh" | "ui.sendToSlicer" => item.params = Some(json!({"bodies": bodies})),
- "browser.expand_all" | "browser.collapse_all" => item.params = Some(json!({"path": path})),
- _ => {}
}
- }
+ "occurrence.copy" => item.params = Some(json!({"occurrence": placement.occurrence, "translate": [10,10,0]})),
+ "ui.paste" | "ui.pasteNew" => item.params = Some(json!({"component": placement.component, "path": path})),
+ "component.create" => item.params = Some(json!({"parent": placement.component, "parent_path": path})),
+ "ui.delete" => item.params = Some(json!({"occurrences": [placement.occurrence]})),
+ "ui.hide" | "ui.show" => {
+ item.id = "browser.visibility".into();
+ item.params = Some(json!({"visible": app.session.occurrence_hidden(path), "paths": [path]}));
+ item.enabled = true;
+ }
+ "ui.isolate" => {
+ item.id = "ui.isolateOccurrence".into();
+ item.params = Some(json!({"path": path}));
+ }
+ "ui.export" | "ui.saveMesh" | "ui.sendToSlicer" => item.params = Some(json!({"bodies": bodies})),
+ "browser.expand_all" | "browser.collapse_all" => item.params = Some(json!({"path": path})),
+ _ => {}
+ });
entries
}
+/// Visit every entry of a menu, each flyout's entries before the row that opens it, so a visit
+/// may add entries to that row's flyout without seeing them.
+fn each_item(items: &mut [Item], f: &mut dyn FnMut(&mut Item)) {
+ for item in items {
+ each_item(&mut item.children, f);
+ f(item);
+ }
+}
+
/// "Turn Up Axis": a quarter turn about X of a component's occurrence for a file saved with the
/// other axis up, one `occurrence.move` (one undo step).
fn turn_up_axis(occurrence: u64, enabled: bool) -> Item {
@@ -1010,6 +1015,26 @@ fn turn_up_axis(occurrence: u64, enabled: bool) -> Item {
item
}
+/// Show All Bodies would bring a body back: one hidden itself, a hidden placement, or a hidden
+/// Bodies folder or group of bodies. The name of a body that is gone does not count.
+fn bodies_hidden(app: &SolveApp) -> bool {
+ let s = &app.session;
+ let world = s.world_state().unwrap_or_default();
+ let groups: Vec<String> = s.doc.browser_groups.iter().filter(|g| g.folder == "bodies").map(|g| format!("/g{}", g.id)).collect();
+ s.visibility.hidden_bodies.iter().any(|b| world.body(b).is_some())
+ || !s.visibility.hidden_occurrences.is_empty()
+ || s.visibility.hidden_folders.iter().any(|k| k.ends_with("/bodies") || groups.iter().any(|g| k.ends_with(g.as_str())))
+}
+
+/// A category row whose entries open in a flyout.
+fn group(label: &str, icon: &str, children: Vec<Item>) -> Item {
+ let mut item = act(&format!("ui.group.{}", label.to_lowercase()), label, icon).on(children.iter().any(|c| c.enabled));
+ item.children = children;
+ item
+}
+
+/// The everyday actions stay on the menu; the placement, what concerns the component itself,
+/// export and organising the browser tree open in category flyouts.
fn component_items(app: &SolveApp, id: u64) -> Vec<Item> {
let doc = &app.session.doc;
let occ = doc.occurrence_of(id);
@@ -1026,67 +1051,78 @@ fn component_items(app: &SolveApp, id: u64) -> Vec<Item> {
if doc.parts.contains_key(&id) {
v.push(cmd(app, "parts.resize", "Edit").with(json!({"component":id})));
}
+ // What a double-click on the row does comes first.
+ let activate = act("ui.activate", "Activate", "component").with(json!({ "component": id })).on(!active);
+ let edits = crate::edit_in_place::edits_on_double_click(app, id);
+ if !edits {
+ v.push(activate.clone());
+ }
+ if id != 0 && doc.links.contains_key(&id) {
+ v.push(act("ui.editInPlace", "Edit in Place", "edit").with(json!({ "component": id })));
+ v.push(act("ui.openLinkedDesign", "Open Linked Design", "open").with(json!({ "component": id })));
+ }
+ if edits {
+ v.push(activate);
+ }
if id != 0 {
let grounded = occ.is_some_and(|o| o.grounded);
let oid = occ.map(|o| o.id).unwrap_or(0);
- v.push(act("ui.activate", "Activate", "component").with(json!({ "component": id })).on(!active));
- if doc.links.contains_key(&id) {
- v.push(act("ui.editInPlace", "Edit in Place", "edit").with(json!({ "component": id })));
- v.push(act("ui.openLinkedDesign", "Open Linked Design", "open").with(json!({ "component": id })));
- }
- v.push(cmd(app, "occurrence.ground", if grounded { "Unground" } else { "Ground" }).with(json!({ "occurrence": oid, "grounded": !grounded })));
- v.push(
- act("ui.moveOccurrence", "Move/Copy", "move")
- .key("M")
- .with(json!({ "occurrence": oid }))
- .on(!grounded && occ.is_some() && app.session.held_by_rigid_group(oid).is_none()),
- );
- v.push(turn_up_axis(oid, !grounded && occ.is_some() && app.session.held_by_rigid_group(oid).is_none()));
- v.push(cmd(app, "component.capture_position", "Capture Position").on(!app.session.pending_moves.is_empty()));
- v.push(cmd(app, "component.revert_position", "Revert Position").on(!app.session.pending_moves.is_empty()));
+ let movable = !grounded && occ.is_some() && app.session.held_by_rigid_group(oid).is_none();
+ v.push(act("ui.moveOccurrence", "Move/Copy", "move").key("M").with(json!({ "occurrence": oid })).on(movable));
+ let mut placement = vec![
+ cmd(app, "occurrence.ground", if grounded { "Unground" } else { "Ground" }).with(json!({ "occurrence": oid, "grounded": !grounded })),
+ turn_up_axis(oid, movable),
+ cmd(app, "component.capture_position", "Capture Position").on(!app.session.pending_moves.is_empty()),
+ cmd(app, "component.revert_position", "Revert Position").on(!app.session.pending_moves.is_empty()),
+ ];
// An imported assembly moves as one until its rigid group is released.
if !app.session.contents_joints(id).is_empty() {
- v.push(cmd(app, "component.unlock", "Unlock Contents").with(json!({ "component": id })));
+ placement.push(cmd(app, "component.unlock", "Unlock Contents").with(json!({ "component": id })));
}
- v.push(Item::sep());
- } else {
- v.push(act("ui.activate", "Activate", "component").with(json!({ "component": id })).on(!active));
+ v.push(group("Placement", "move", placement));
}
- v.push(cmd(app, "component.create", "New Component").with(json!({ "parent": id })));
+ v.push(Item::sep());
+ let mut own = vec![cmd(app, "component.create", "New Component").with(json!({ "parent": id }))];
if id == 0 {
- v.push(cmd(app, "component.from_bodies", "Create Components from Bodies").with(json!({ "bodies": names })).on(!bodies.is_empty()));
+ own.push(cmd(app, "component.from_bodies", "Create Components from Bodies").with(json!({ "bodies": names })).on(!bodies.is_empty()));
}
- v.push(Item::sep());
- v.push(act("ui.material", "Physical Material", "material").with(json!({ "bodies": names })).on(!bodies.is_empty()));
- v.push(
+ if doc.links.contains_key(&id) {
+ own.push(act("ui.relinkSource", "Relink Source (All Instances)…", "update").with(json!({"component": id})));
+ } else if id != 0 && app.session.can_extract(id) {
+ own.push(act("ui.extractComponent", "Extract to File…", "export").with(json!({"component": id})));
+ }
+ own.push(Item::sep());
+ own.push(
act("ui.appearance", "Appearance", "appearance")
.key("A")
.with(if id == 0 { json!({ "bodies": names }) } else { json!({"component": id}) })
.on(id != 0 || !bodies.is_empty()),
);
+ own.push(act("ui.material", "Physical Material", "material").with(json!({ "bodies": names })).on(!bodies.is_empty()));
if id != 0 {
- v.push(cmd(app, "component.cycle_color", "Cycle Component Color").with(json!({"component": id})));
- }
- v.push(act("ui.properties", "Properties", "measure").with(json!({ "component": id })));
- if doc.links.contains_key(&id) {
- v.push(act("ui.relinkSource", "Relink Source (All Instances)…", "update").with(json!({"component": id})));
- } else if id != 0 && app.session.can_extract(id) {
- v.push(act("ui.extractComponent", "Extract to File…", "export").with(json!({"component": id})));
+ own.push(cmd(app, "component.cycle_color", "Cycle Component Color").with(json!({"component": id})));
}
+ own.push(Item::sep());
+ own.push(act("ui.rename", "Rename", "rename").key("F2").with(json!({ "component": id })));
+ own.push(act("ui.properties", "Properties", "measure").with(json!({ "component": id })));
if id == 0 {
- v.push(act("ui.designProperties", "Design Properties", "settings"));
- }
- v.push(Item::sep());
- v.push(act("ui.export", "Export…", "export").with(json!({ "bodies": names })).on(!bodies.is_empty()));
- v.push(act("ui.saveMesh", "Save As Mesh", "export").with(json!({ "bodies": names })).on(!bodies.is_empty()));
- v.push(
- act("ui.sendToSlicer", "Send to Slicer", "export")
- .with(json!({ "bodies": names }))
- .on(!bodies.is_empty() && crate::dialogs_save_mesh::available(app)),
- );
+ own.push(act("ui.designProperties", "Design Properties", "settings"));
+ }
+ v.push(group(if id == 0 { "Design" } else { "Component" }, "component", own));
+ v.push(group(
+ "Export",
+ "export",
+ vec![
+ act("ui.export", "Export…", "export").with(json!({ "bodies": names })).on(!bodies.is_empty()),
+ act("ui.saveMesh", "Save As Mesh", "export").with(json!({ "bodies": names })).on(!bodies.is_empty()),
+ act("ui.sendToSlicer", "Send to Slicer", "export")
+ .with(json!({ "bodies": names }))
+ .on(!bodies.is_empty() && crate::dialogs_save_mesh::available(app)),
+ ],
+ ));
v.push(Item::sep());
- // The clipboard, then Delete and Rename, in the same place for the design and its components
- // (the design is copied as a saved design to link, and is neither cut nor deleted).
+ // The clipboard, then Delete, in the same place for the design and its components (the design
+ // is copied as a saved design to link, and is neither cut nor deleted).
if id == 0 {
v.push(act("ui.copyDesign", "Copy", "copy").key("Ctrl+C"));
} else {
@@ -1103,16 +1139,18 @@ fn component_items(app: &SolveApp, id: u64) -> Vec<Item> {
if id != 0 {
v.push(act("ui.delete", "Delete", "delete").key("Del").with(json!({ "occurrences": [occ.map(|o| o.id)] })).on(occ.is_some()));
}
- v.push(act("ui.rename", "Rename", "rename").key("F2").with(json!({ "component": id })));
v.push(Item::sep());
v.push(act(if hidden { "ui.show" } else { "ui.hide" }, "Show/Hide", "eye").key("V").with(json!({ "bodies": names })).on(!bodies.is_empty()));
- v.push(act("ui.showAll", "Show All Bodies", "eye"));
+ if bodies_hidden(app) {
+ v.push(act("ui.showAll", "Show All Bodies", "eye"));
+ }
v.push(act("ui.isolate", "Isolate", "body").with(json!({ "bodies": names })).on(!bodies.is_empty() && id != 0));
- v.push(act("ui.newGroup", "New Group", "folder").with(json!({ "component": id })));
+ v.push(Item::sep());
+ let mut organize = vec![act("ui.newGroup", "New Group", "folder").with(json!({ "component": id }))];
if id != 0 {
// Keep the component in the design but leave its features out of the History bar (#10393).
let hidden = doc.component_history_hidden(id);
- v.push(
+ organize.push(
cmd(
app,
if hidden { "component.show_history" } else { "component.hide_history" },
@@ -1121,9 +1159,10 @@ fn component_items(app: &SolveApp, id: u64) -> Vec<Item> {
.with(json!({ "component": id })),
);
}
- v.push(Item::sep());
- v.push(cmd(app, "browser.expand_all", "Expand All").with(json!({ "component": id })));
- v.push(cmd(app, "browser.collapse_all", "Collapse All").with(json!({ "component": id })));
+ organize.push(Item::sep());
+ organize.push(cmd(app, "browser.expand_all", "Expand All").with(json!({ "component": id })));
+ organize.push(cmd(app, "browser.collapse_all", "Collapse All").with(json!({ "component": id })));
+ v.push(group("Organize", "folder", organize));
v
}
@@ -1926,15 +1965,16 @@ pub fn delete(app: &mut SolveApp) {
crate::delete::delete_selection(app);
}
-/// A shortcut key pressed while a menu is open: the row of that menu showing `key` runs on the
-/// menu's target, as a click on it would, and the menu closes. A folder, the Origin folder or an
-/// origin plane is not selected by the right-click that opens its menu, so the key's own action
-/// (V on the selection) would miss it. Returns whether the open menu has a row for the key; a
-/// disabled row takes the key and does nothing, as a click on it does.
+/// A shortcut key pressed while a menu is open: the row of that menu or of one of its flyouts
+/// showing `key` runs on the menu's target, as a click on it would, and the menu closes. A
+/// folder, the Origin folder or an origin plane is not selected by the right-click that opens its
+/// menu, so the key's own action (V on the selection) would miss it. Returns whether the open
+/// menu has a row for the key; a disabled row takes the key and does nothing, as a click on it
+/// does.
pub fn press_shortcut(app: &mut SolveApp, key: &str) -> bool {
let Some(at) = app.viewport.context_menu else { return false };
let target = app.menu.target.clone();
- let Some(item) = items(app, &target).into_iter().find(|i| i.shortcut == key && i.children.is_empty()) else { return false };
+ let Some(item) = entries(app, &target).into_iter().find(|i| i.shortcut == key && i.children.is_empty()) else { return false };
if item.enabled {
close(app);
run_item(app, &item, at);
@@ -2176,7 +2216,7 @@ pub fn open(app: &mut SolveApp, at: Pos2, held: crate::tool_modifiers::Held) {
/// Open a menu for a target (the radial ring only for the viewport).
pub fn open_for(app: &mut SolveApp, at: Pos2, target: Target) {
app.menu.key_row = None;
- app.menu.submenu = None;
+ app.menu.submenu.clear();
app.menu.submenu_key = None;
app.menu.submenu_leave = None;
app.menu.radial = target == Target::Viewport && app.preferences.radial_context_menu;
@@ -2221,17 +2261,22 @@ pub fn describe(app: &SolveApp) -> Value {
return json!({ "open": false, "pending": app.menu.pending.is_some() });
};
let radial = if app.menu.radial { radial_items(app) } else { Vec::new() };
- let describe_items = |items: Vec<Item>| {
+ /// A row with its `placeholder` flag, and a flyout's rows likewise.
+ fn describe_items(items: Vec<Item>) -> Vec<Value> {
items
.into_iter()
- .map(|item| {
+ .map(|mut item| {
let placeholder = !item.icon.is_empty() && crate::icon_svg::resolve(&item.icon).placeholder;
+ let children = describe_items(std::mem::take(&mut item.children));
let mut value = json!(item);
value["placeholder"] = json!(placeholder);
+ if !children.is_empty() {
+ value["children"] = json!(children);
+ }
value
})
- .collect::<Vec<_>>()
- };
+ .collect()
+ }
json!({
"open": true,
"at": [at.x, at.y],
@@ -2242,19 +2287,33 @@ pub fn describe(app: &SolveApp) -> Value {
})
}
+/// Every entry of a target's menu, its rows first and then what their flyouts hold, level by
+/// level.
+pub fn entries(app: &SolveApp, target: &Target) -> Vec<Item> {
+ let mut all = Vec::new();
+ let mut level = items(app, target);
+ while !level.is_empty() {
+ let next = level.iter().flat_map(|item| item.children.iter().cloned()).collect();
+ all.append(&mut level);
+ level = next;
+ }
+ all
+}
+
/// Pick an item of the open menu by id or label (for `ui.menuPick`).
pub fn pick(app: &mut SolveApp, key: &str) -> Result<Value, String> {
let Some(at) = app.viewport.context_menu else { return Err("no menu is open".into()) };
let target = app.menu.target.clone();
let mut all = if app.menu.radial { radial_items(app) } else { Vec::new() };
- let roots = items(app, &target);
- all.extend(roots.iter().cloned());
- all.extend(roots.into_iter().flat_map(|item| item.children));
+ all.extend(entries(app, &target));
let item =
all.into_iter().find(|i| !i.is_sep() && !i.is_heading() && (i.id == key || i.label == key)).ok_or_else(|| format!("no menu item `{key}`"))?;
if !item.enabled {
return Err(format!("`{}` is disabled", item.label));
}
+ if !runs_itself(&item) {
+ return Err(format!("`{}` only opens a flyout: pick one of its entries", item.label));
+ }
close(app);
run_item(app, &item, at);
Ok(json!({ "ran": item.id, "label": item.label }))
@@ -2423,29 +2482,39 @@ pub fn show(app: &mut SolveApp, ctx: &egui::Context) {
place(at, Vec2::ZERO, vec2(LIST_W, list_height(&list)), screen)
};
- let had_submenu = app.menu.submenu.is_some();
- let leaving = app.menu.submenu_leave.is_some();
- let enabled: Vec<_> = list.iter().map(|i| i.enabled && !i.is_sep() && !i.is_heading()).collect();
- if app.menu.submenu.is_none() {
- let enter = crate::ui_kit::Menu::navigate(ctx, &enabled, &mut app.menu.key_row);
+ // The keys act on the innermost open level: Up and Down choose a row, Right or Enter open its
+ // flyout, Enter runs anything else and Left closes the innermost flyout.
+ let open = open_levels(&list, &app.menu.submenu).len() - 1;
+ app.menu.submenu.truncate(open);
+ if ctx.input(|i| i.key_pressed(egui::Key::ArrowLeft)) && open > 0 {
+ let back = app.menu.submenu.pop();
+ if open > 1 {
+ app.menu.submenu_key = back;
+ } else {
+ app.menu.key_row = back;
+ app.menu.submenu_key = None;
+ }
+ } else if let Some(rows) = open_levels(&list, &app.menu.submenu).pop() {
+ let cursor = if open == 0 { &mut app.menu.key_row } else { &mut app.menu.submenu_key };
+ let enabled: Vec<_> = rows.iter().map(|i| i.enabled && !i.is_sep() && !i.is_heading()).collect();
+ let enter = crate::ui_kit::Menu::navigate(ctx, &enabled, cursor);
let right = ctx.input(|i| i.key_pressed(egui::Key::ArrowRight));
- if let Some(k) = app.menu.key_row
- && let Some(item) = list.get(k)
+ if let Some(k) = *cursor
+ && let Some(item) = rows.get(k)
{
if (right || enter) && !item.children.is_empty() {
- app.menu.submenu = Some(k);
+ app.menu.submenu.push(k);
app.menu.submenu_key = item.children.iter().position(|c| c.enabled);
} else if enter {
picked = Some(item.clone());
}
}
- } else if ctx.input(|i| i.key_pressed(egui::Key::ArrowLeft)) {
- app.menu.submenu = None;
- app.menu.submenu_key = None;
}
- let mut submenu_row = None;
- let mut other_row = false;
+ let path = app.menu.submenu.clone();
+ let levels = open_levels(&list, &path);
+ let leaving = app.menu.submenu_leave.map(|(depth, _)| depth);
let key_row = app.menu.key_row;
+ let mut seen: Vec<Seen> = Vec::new();
let resp = Container::new(ctx, Surface::Popup)
.area(egui::Id::new("sc_context_menu"))
.fixed_pos(list_at)
@@ -2455,85 +2524,54 @@ pub fn show(app: &mut SolveApp, ctx: &egui::Context) {
if target == Target::Workspace {
picked = crate::ui_kit::workspace_menu(ui, &list, key_row, (screen.bottom() - list_at.y).max(160.0)).or(picked.take());
} else {
- menu_frame(ui, |ui| {
- for (k, item) in list.iter().enumerate() {
- if item.is_sep() || item.is_heading() {
- let _ = list_row_lit(ui, item, false);
- } else if item.children.is_empty() {
- let row = kit_item(item, key_row == Some(k)).show(ui);
- if row.clicked() && item.enabled {
- picked = Some(item.clone());
- }
- other_row |= row.hovered();
- } else {
- let row = kit_item(item, key_row == Some(k) || (app.menu.submenu == Some(k) && !leaving)).show(ui);
- // Appearance keeps its direct editor action as well as hover shortcuts.
- if item.enabled && row.clicked() && item.id == "ui.appearance" {
- picked = Some(item.clone());
- } else if item.enabled && (crate::ui_kit::Menu::flyout_hover(&row) || row.clicked()) {
- if app.menu.submenu != Some(k) {
- app.menu.submenu_key = None;
- }
- app.menu.submenu = Some(k);
- }
- if app.menu.submenu == Some(k) {
- submenu_row = Some((k, row.rect));
- }
- }
- }
- });
+ menu_frame(ui, |ui| seen.push(level_rows(ui, &list, 0, key_row, path.first().copied(), leaving == Some(0), &mut picked)));
}
});
inside |= resp.response.contains_pointer() || resp.response.rect.contains(pointer.unwrap_or(Pos2::ZERO));
+ let mut leftward = false;
+ for (depth, rows) in levels.iter().copied().enumerate().skip(1) {
+ let Some(row) = seen.get(depth - 1).and_then(|s| s.anchor) else { break };
+ // One area per flyout and contents: an egui area keeps its last size, so a flyout sharing
+ // one with a shorter one would be squeezed into it and scroll.
+ let id = egui::Id::new(("sc_context_submenu", depth)).with(rows.iter().map(|i| (&i.id, &i.label)).collect::<Vec<_>>());
+ let cursor = if depth == path.len() { app.menu.submenu_key } else { None };
+ let sub = crate::ui_kit::Menu::submenu(ctx, id, row, list_height(rows), leftward, |ui| {
+ egui::ScrollArea::vertical()
+ .max_height((screen.height() - 28.0).max(30.0))
+ .show(ui, |ui| level_rows(ui, rows, depth, cursor, path.get(depth).copied(), leaving == Some(depth), &mut picked))
+ .inner
+ });
+ inside |= sub.response.contains_pointer() || pointer.is_some_and(|p| sub.response.rect.contains(p));
+ leftward = sub.response.rect.center().x < row.center().x;
+ seen.push(sub.inner);
+ }
- // A flyout closes once the pointer moves on to another row of its menu and rests there
- // (#6657). A pointer that is still (the flyout opened with the keys) leaves it open.
let moved = ctx.input(|i| i.pointer.delta() != Vec2::ZERO);
- if app.menu.submenu.is_some() && other_row && (moved || app.menu.submenu_leave.is_some()) {
- if crate::ui_kit::Menu::flyout_leaving(ctx, &mut app.menu.submenu_leave) {
- app.menu.submenu = None;
+ if let Some((depth, k)) = seen.iter().enumerate().rev().find_map(|(depth, s)| s.opens.map(|k| (depth, k))) {
+ if path.get(depth) != Some(&k) {
+ app.menu.submenu.truncate(depth);
+ app.menu.submenu.push(k);
app.menu.submenu_key = None;
- submenu_row = None;
+ ctx.request_repaint();
+ }
+ app.menu.submenu_leave = None;
+ } else if let Some(depth) = seen.iter().rposition(|s| s.other_row).filter(|depth| *depth < path.len()) {
+ // The flyouts further in close once the pointer moves on to another row of this level and
+ // rests there (#6657). A pointer that is still (the flyout opened with the keys) leaves
+ // them open.
+ let mut since = app.menu.submenu_leave.filter(|(at, _)| *at == depth).map(|(_, since)| since);
+ if moved || since.is_some() {
+ if crate::ui_kit::Menu::flyout_leaving(ctx, &mut since) {
+ app.menu.submenu.truncate(depth);
+ app.menu.submenu_key = None;
+ ctx.request_repaint();
+ }
+ app.menu.submenu_leave = since.map(|since| (depth, since));
}
} else {
app.menu.submenu_leave = None;
}
- if let Some((k, row)) = submenu_row
- && let Some(parent) = list.get(k)
- {
- let enabled: Vec<_> = parent.children.iter().map(|i| i.enabled && !i.is_sep() && !i.is_heading()).collect();
- if had_submenu
- && crate::ui_kit::Menu::navigate(ctx, &enabled, &mut app.menu.submenu_key)
- && let Some(child) = app.menu.submenu_key.and_then(|r| parent.children.get(r))
- {
- picked = Some(child.clone());
- }
- let sub = crate::ui_kit::Menu::submenu(ctx, egui::Id::new("sc_context_submenu"), row, list_height(&parent.children), |ui| {
- egui::ScrollArea::vertical().max_height((screen.height() - 28.0).max(30.0)).show(ui, |ui| {
- for (n, child) in parent.children.iter().enumerate() {
- if child.is_sep() {
- crate::ui_kit::Menu::separator(ui);
- continue;
- }
- if child.is_heading() {
- crate::ui_kit::Menu::heading(ui, &child.label);
- continue;
- }
- // Child commands may share an id (swatches); preserve the parent handle
- // and publish a distinct identity for every adjacent submenu action.
- let handle = format!("{}:{}", child.id, child.label);
- let mut row = kit_item(child, app.menu.submenu_key == Some(n));
- row.id = &handle;
- if row.show(ui).clicked() && child.enabled {
- picked = Some(child.clone());
- }
- }
- });
- });
- inside |= sub.response.contains_pointer() || pointer.is_some_and(|p| sub.response.rect.contains(p));
- }
-
let shown = std::mem::replace(&mut app.menu.shown, true);
let (primary, secondary, esc) = ctx.input(|i| {
(
@@ -2586,6 +2624,79 @@ pub fn list_row_lit(ui: &mut egui::Ui, item: &Item, lit: bool) -> Option<Item> {
(row.show(ui).clicked() && item.enabled).then(|| item.clone())
}
+/// The rows of each open level: the menu itself, then every open flyout in turn. It stops at a
+/// row that is gone or has no flyout.
+fn open_levels<'a>(list: &'a [Item], path: &[usize]) -> Vec<&'a [Item]> {
+ let mut levels = vec![list];
+ for &k in path {
+ match levels.last().and_then(|rows| rows.get(k)) {
+ Some(item) if !item.children.is_empty() => levels.push(&item.children),
+ _ => break,
+ }
+ }
+ levels
+}
+
+/// A click runs the row: one without a flyout, or Appearance, which keeps its direct editor
+/// action as well as the quick choices in its flyout.
+fn runs_itself(item: &Item) -> bool {
+ item.children.is_empty() || item.id == "ui.appearance"
+}
+
+/// What the pointer did on one level of the menu this frame.
+#[derive(Default)]
+struct Seen {
+ /// Where the row whose flyout is open was drawn.
+ anchor: Option<Rect>,
+ /// A row with a flyout the pointer moved onto or clicked: its flyout opens.
+ opens: Option<usize>,
+ /// The pointer is on a row without a flyout.
+ other_row: bool,
+}
+
+/// Draw one level's rows: `cursor` is the row chosen with the keys, `open` the row whose flyout
+/// is open and `leaving` that the pointer is about to close it.
+fn level_rows(
+ ui: &mut egui::Ui,
+ rows: &[Item],
+ depth: usize,
+ cursor: Option<usize>,
+ open: Option<usize>,
+ leaving: bool,
+ picked: &mut Option<Item>,
+) -> Seen {
+ let mut seen = Seen::default();
+ for (k, item) in rows.iter().enumerate() {
+ if item.is_sep() || item.is_heading() {
+ let _ = list_row_lit(ui, item, false);
+ continue;
+ }
+ // Flyout entries may share an id (swatches): their handles add the label.
+ let handle = format!("{}:{}", item.id, item.label);
+ let mut kit = kit_item(item, cursor == Some(k) || (open == Some(k) && !leaving));
+ if depth > 0 {
+ kit.id = &handle;
+ }
+ let row = kit.show(ui);
+ if item.children.is_empty() {
+ if row.clicked() && item.enabled {
+ *picked = Some(item.clone());
+ }
+ seen.other_row |= row.hovered();
+ continue;
+ }
+ if item.enabled && row.clicked() && runs_itself(item) {
+ *picked = Some(item.clone());
+ } else if item.enabled && (crate::ui_kit::Menu::flyout_hover(&row) || row.clicked()) {
+ seen.opens = Some(k);
+ }
+ if open == Some(k) {
+ seen.anchor = Some(row.rect);
+ }
+ }
+ seen
+}
+
fn kit_item(item: &Item, lit: bool) -> crate::ui_kit::MenuItem<'_> {
crate::ui_kit::MenuItem {
id: &item.id,
diff --git a/crates/ui-egui/src/design_properties.rs b/crates/ui-egui/src/design_properties.rs
index 254f6e5726..f774bf278d 100644
--- a/crates/ui-egui/src/design_properties.rs
+++ b/crates/ui-egui/src/design_properties.rs
@@ -697,7 +697,7 @@ mod tests {
// Held until checked: under load the worker could otherwise finish before the menu returns.
let (finish, gate) = std::sync::mpsc::channel();
h.app.apply_gate = Some(std::sync::Arc::new(std::sync::Mutex::new(gate)));
- let items = crate::context_menu::items(&h.app, &crate::context_menu::Target::Component { id: 0 });
+ let items = crate::context_menu::entries(&h.app, &crate::context_menu::Target::Component { id: 0 });
let item = items.iter().find(|i| i.label == "Properties").expect("Properties item");
crate::context_menu::run_item(&mut h.app, item, egui::pos2(0.0, 0.0));
assert!(h.app.menu.props_measuring.is_some(), "the menu returns at once, the card measuring");
@@ -732,7 +732,7 @@ mod tests {
#[test]
fn the_file_menu_browser_and_root_component_open_the_window() {
let mut h = Harness::new();
- let items = crate::context_menu::items(&h.app, &crate::context_menu::Target::Component { id: 0 });
+ let items = crate::context_menu::entries(&h.app, &crate::context_menu::Target::Component { id: 0 });
let item = items.iter().find(|i| i.id == "ui.designProperties").expect("root component menu item");
assert_eq!(item.label, "Design Properties");
crate::context_menu::run_item(&mut h.app, item, egui::pos2(0.0, 0.0));
diff --git a/crates/ui-egui/src/edit_in_place.rs b/crates/ui-egui/src/edit_in_place.rs
index c497ff0588..62a143fb40 100644
--- a/crates/ui-egui/src/edit_in_place.rs
+++ b/crates/ui-egui/src/edit_in_place.rs
@@ -77,7 +77,7 @@ impl EditInPlace {
/// A linked component the window edits in place when it is double-clicked: in a saved design
/// (its links are found from its file) with `double_click_components` on.
-fn edits_on_double_click(app: &SolveApp, component: u64) -> bool {
+pub(crate) fn edits_on_double_click(app: &SolveApp, component: u64) -> bool {
app.preferences.double_click_components && app.session.path.is_some() && app.session.doc.links.contains_key(&component)
}
diff --git a/crates/ui-egui/src/edit_in_place_tests.rs b/crates/ui-egui/src/edit_in_place_tests.rs
index ba37ee2f06..0d88f167ce 100644
--- a/crates/ui-egui/src/edit_in_place_tests.rs
+++ b/crates/ui-egui/src/edit_in_place_tests.rs
@@ -354,6 +354,17 @@ fn double_clicking_a_body_of_this_design_or_with_the_preference_off_does_nothing
assert!(f.app.edit_in_place.active.is_none() && f.app.edit_in_place.pending.is_none());
}
+/// A linked component's menu starts with what a double-click on its row does.
+#[test]
+fn a_linked_components_menu_starts_with_what_a_double_click_does() {
+ use crate::context_menu::{self, Target};
+ let mut f = assembly("menu-order");
+ let ids = |app: &SolveApp| context_menu::items(app, &Target::Component { id: f.plate }).into_iter().take(3).map(|i| i.id).collect::<Vec<_>>();
+ assert_eq!(ids(&f.app), ["ui.editInPlace", "ui.openLinkedDesign", "ui.activate"]);
+ f.app.preferences.double_click_components = false;
+ assert_eq!(ids(&f.app), ["ui.activate", "ui.editInPlace", "ui.openLinkedDesign"]);
+}
+
#[test]
fn activate_only_activates_and_edit_in_place_opens_the_placement_right_clicked() {
use crate::context_menu::{self, Target};
diff --git a/crates/ui-egui/src/linked_source.rs b/crates/ui-egui/src/linked_source.rs
index d43f525af0..0d2a636698 100644
--- a/crates/ui-egui/src/linked_source.rs
+++ b/crates/ui-egui/src/linked_source.rs
@@ -293,7 +293,7 @@ mod tests {
}
fn menu(app: &SolveApp, target: Target) -> Option<context_menu::Item> {
- context_menu::items(app, &target).into_iter().find(|i| i.id == "ui.relinkSource")
+ context_menu::entries(app, &target).into_iter().find(|i| i.id == "ui.relinkSource")
}
fn answer(app: &mut SolveApp, path: Option<String>) {
@@ -393,16 +393,18 @@ mod tests {
let made = app.run("component.create", json!({"name": "Bracket", "grounded": false})).unwrap();
let (component, occurrence) = (made["component"].as_u64().unwrap(), made["occurrence"].as_u64().unwrap());
app.run("solid.box", json!({"length": 10, "width": 20, "height": 30})).unwrap();
- let find = |app: &SolveApp, id: u64| context_menu::items(app, &Target::Component { id }).into_iter().find(|i| i.id == "ui.extractComponent");
+ let find =
+ |app: &SolveApp, id: u64| context_menu::entries(app, &Target::Component { id }).into_iter().find(|i| i.id == "ui.extractComponent");
assert!(find(&app, 0).is_none());
// Not offered while the component can't go: here, moved without Capture Position
app.run("occurrence.move", json!({"occurrence": occurrence, "translate": [5, 0, 0], "capture": false})).unwrap();
assert!(find(&app, component).is_none());
app.run("component.revert_position", json!({})).unwrap();
- // In Relink Source's place, right after Properties
- let ids: Vec<String> = context_menu::items(&app, &Target::Component { id: component }).into_iter().map(|i| i.id).collect();
- let properties = ids.iter().position(|i| i == "ui.properties").unwrap();
- assert_eq!(ids.get(properties + 1).map(String::as_str), Some("ui.extractComponent"));
+ // In Relink Source's place in the Component flyout, right below New Component
+ let rows = context_menu::items(&app, &Target::Component { id: component });
+ let ids: Vec<&str> = rows.iter().find(|i| i.label == "Component").unwrap().children.iter().map(|i| i.id.as_str()).collect();
+ let create = ids.iter().position(|i| *i == "component.create").unwrap();
+ assert_eq!(ids.get(create + 1), Some(&"ui.extractComponent"));
let item = find(&app, component).unwrap();
let chosen = folder.join("bracket").to_string_lossy().into_owned();
app.services.pick_save = Some(Box::new(move |name, extensions| {
diff --git a/crates/ui-egui/src/menu_tests.rs b/crates/ui-egui/src/menu_tests.rs
index 88c09d8aa0..0b9c167549 100644
--- a/crates/ui-egui/src/menu_tests.rs
+++ b/crates/ui-egui/src/menu_tests.rs
@@ -39,9 +39,9 @@ fn find(items: &[Item], label: &str) -> Item {
.unwrap_or_else(|| panic!("no `{label}` in {:?}", items.iter().map(|i| &i.label).collect::<Vec<_>>()))
}
-/// Run the item labelled `label` of the target's menu.
+/// Run the item labelled `label` of the target's menu or one of its flyouts.
fn act(app: &mut SolveApp, t: &Target, label: &str) {
- let item = find(&context_menu::items(app, t), label);
+ let item = find(&context_menu::entries(app, t), label);
context_menu::run_item(app, &item, pos2(0.0, 0.0));
}
@@ -469,6 +469,17 @@ fn component_menu_activates_grounds_and_pastes() {
let t = Target::Component { id: c };
act(&mut app, &t, "Activate");
assert_eq!(app.session.active_component, c);
+ let rows = context_menu::items(&app, &t);
+ let ids: Vec<_> = rows.iter().map(|i| i.id.as_str()).collect();
+ let movement = ids.iter().position(|id| *id == "ui.moveOccurrence").expect("Move/Copy stays on the menu");
+ assert_eq!(ids.get(movement + 1), Some(&"ui.group.placement"), "Placement follows Move/Copy");
+ assert!(find(&rows, "Placement").children.iter().any(|i| i.id == "occurrence.ground"), "Ground sits in the Placement flyout");
+ let own: Vec<_> = find(&rows, "Component").children.iter().map(|i| i.id.clone()).collect();
+ for id in ["ui.rename", "ui.appearance", "ui.material", "component.cycle_color", "component.create", "ui.properties"] {
+ assert!(own.iter().any(|o| o == id) && !ids.contains(&id), "{id} sits in the Component flyout only");
+ }
+ assert!(find(&rows, "Organize").children.iter().any(|i| i.id == "ui.newGroup"), "New Group sits with the browser tree's entries");
+ assert!(ids.contains(&"ui.pasteNew"), "Paste New stays with the clipboard");
// The design's first part comes in grounded (#2804); the menu frees it and grounds it again.
assert!(app.session.doc.occurrence_of(c).unwrap().grounded);
act(&mut app, &t, "Unground");
@@ -484,7 +495,7 @@ fn component_menu_activates_grounds_and_pastes() {
act(&mut app, &placement, "Copy");
assert_eq!(app.copied_placements.len(), 1, "{:?}", app.status);
let design = Target::Component { id: 0 };
- assert!(find(&context_menu::items(&app, &design), "Paste New").enabled);
+ assert!(find(&context_menu::entries(&app, &design), "Paste New").enabled);
act(&mut app, &design, "Paste New");
assert_eq!(app.session.doc.components.len(), 2);
}
@@ -613,7 +624,7 @@ fn expand_and_collapse_all_open_the_browser_tree_from_the_design_menu() {
let mut app = sample_app();
let n = app.session.undo.len();
let root = Target::Component { id: 0 };
- assert!(context_menu::items(&app, &root).iter().any(|i| i.label == "Expand All" && i.id == "browser.expand_all"));
+ assert!(context_menu::entries(&app, &root).iter().any(|i| i.label == "Expand All" && i.id == "browser.expand_all"));
act(&mut app, &root, "Collapse All");
assert!(app.tree.collapsed.contains("c0/bodies"), "{:?}", app.tree.collapsed);
assert!(!app.tree.collapsed.contains("c0"), "the design row stays open: {:?}", app.tree.collapsed);
@@ -1082,7 +1093,7 @@ fn rename_shows_f2_and_f2_with_a_menu_open_renames_what_the_menu_is_for() {
let data = solidcraft_engine::doc::canvas::base64_encode(&png);
let canvas = h.app.run("canvas.insert", json!({"data": data, "plane": "XY", "width": 80})).unwrap()["canvas"].as_u64().unwrap();
let rename_key = |app: &SolveApp, target: &Target| {
- context_menu::items(app, target)
+ context_menu::entries(app, target)
.into_iter()
.find(|i| i.id == "ui.rename")
.map(|i| i.shortcut)
@@ -1817,6 +1828,149 @@ fn only_one_row_is_lit_while_a_flyout_is_closing() {
assert_eq!(lit_rows(&h, &rows), vec![other.label.clone()], "the parent gives up its highlight as soon as the pointer leaves it");
}
+/// A component's menu (its Component flyout holds Appearance, which has a flyout of its own),
+/// open in a harness with the pointer on the menu.
+fn component_menu() -> (crate::scenario::Harness, u64) {
+ let mut h = crate::scenario::Harness::new();
+ h.app = sample_app();
+ let b = body(&h.app);
+ h.app.run("component.from_bodies", json!({"bodies": [b]})).unwrap();
+ let c = h.app.session.doc.components[0].id;
+ h.frames(3);
+ context_menu::open_for(&mut h.app, pos2(300.0, 60.0), Target::Component { id: c });
+ h.frames(2);
+ h.step(&json!({"move":[10, 10]})).unwrap();
+ (h, c)
+}
+
+#[test]
+fn a_flyout_inside_a_flyout_opens_on_hover_and_applies_its_choice() {
+ use crate::scenario::rect_of;
+ let (mut h, c) = component_menu();
+ h.step(&json!({"move":{"handle":"menu:ui.group.component"}})).unwrap();
+ h.frames(2);
+ h.step(&json!({"move":{"handle":"menu:ui.appearance:Appearance"}})).unwrap();
+ h.frames(2);
+ let swatch = "menu:appearance.assign:Aluminum - Satin";
+ assert!(rect_of(swatch).is_some(), "hovering Appearance in the Component flyout opens its quick choices");
+ assert!(rect_of("menu:ui.rename:Rename").is_some(), "the Component flyout stays open");
+ h.step(&json!({"click":{"handle":swatch}})).unwrap();
+ assert!(h.app.session.doc.appearances.components.contains_key(&c), "the choice applies to the component");
+ assert!(h.app.viewport.context_menu.is_none());
+ assert!(h.app.dialog.is_none(), "a quick choice opens no editor");
+}
+
+#[test]
+fn keys_walk_into_nested_flyouts_and_left_steps_back_one_level() {
+ use crate::scenario::rect_of;
+ let (mut h, _) = component_menu();
+ let rows = context_menu::items(&h.app, &h.app.menu.target.clone());
+ h.app.menu.key_row = rows.iter().position(|i| i.id == "ui.group.component");
+ h.step(&json!({"key":"ArrowRight"})).unwrap();
+ assert!(rect_of("menu:ui.rename:Rename").is_some(), "Right opens the Component flyout");
+ let own = &find(&rows, "Component").children;
+ let downs = own.iter().filter(|i| i.enabled && i.id != "-" && !i.id.starts_with('#')).position(|i| i.id == "ui.appearance").unwrap();
+ for _ in 0..downs {
+ h.step(&json!({"key":"ArrowDown"})).unwrap();
+ }
+ h.step(&json!({"key":"ArrowRight"})).unwrap();
+ h.frames(2);
+ assert!(rect_of("menu:appearance.assign:Aluminum - Satin").is_some(), "Right on Appearance opens its quick choices");
+ assert!(h.app.dialog.is_none(), "opening a flyout runs nothing");
+ h.step(&json!({"key":"ArrowLeft"})).unwrap();
+ h.frames(2);
+ assert!(rect_of("menu:appearance.assign:Aluminum - Satin").is_none(), "Left closes the innermost flyout");
+ assert!(rect_of("menu:ui.rename:Rename").is_some(), "and keeps the one it came from");
+ h.step(&json!({"key":"ArrowLeft"})).unwrap();
+ h.frames(2);
+ assert!(rect_of("menu:ui.rename:Rename").is_none(), "Left again closes the Component flyout");
+ assert!(h.app.viewport.context_menu.is_some(), "the menu itself stays open");
+}
+
+/// Resting on another row of a flyout closes only the flyouts further in (#6657).
+#[test]
+fn resting_on_another_row_of_a_flyout_closes_only_the_flyout_beyond_it() {
+ use crate::scenario::rect_of;
+ let (mut h, _) = component_menu();
+ h.step(&json!({"move":{"handle":"menu:ui.group.component"}})).unwrap();
+ h.frames(2);
+ h.step(&json!({"move":{"handle":"menu:ui.appearance:Appearance"}})).unwrap();
+ h.frames(2);
+ h.step(&json!({"move":{"handle":"menu:ui.rename:Rename"}})).unwrap();
+ h.frames(30);
+ assert!(rect_of("menu:appearance.assign:Aluminum - Satin").is_none(), "resting on Rename closes the Appearance flyout");
+ assert!(rect_of("menu:ui.rename:Rename").is_some(), "the Component flyout stays open");
+}
+
+/// Left from a flyout the pointer opened chooses the row that opened it, so Enter never runs a
+/// row the keys chose before.
+#[test]
+fn left_from_a_hovered_flyout_chooses_the_row_that_opened_it() {
+ let (mut h, _) = component_menu();
+ let rows = context_menu::items(&h.app, &h.app.menu.target.clone());
+ h.app.menu.key_row = rows.iter().position(|i| i.id == "ui.copy");
+ h.step(&json!({"move":{"handle":"menu:ui.group.component"}})).unwrap();
+ h.frames(2);
+ h.step(&json!({"key":"ArrowLeft"})).unwrap();
+ assert_eq!(h.app.menu.key_row, rows.iter().position(|i| i.id == "ui.group.component"));
+ assert!(crate::scenario::rect_of("menu:ui.rename:Rename").is_none(), "the flyout closed");
+}
+
+/// Near the right edge a flyout opens to the left, and a flyout inside it opens further left
+/// instead of over the menu.
+#[test]
+fn a_flyout_inside_a_flyout_that_opened_to_the_left_opens_to_the_left() {
+ use crate::scenario::rect_of;
+ let (mut h, c) = component_menu();
+ let right = h.ctx.content_rect().right();
+ context_menu::open_for(&mut h.app, pos2(right - context_menu::LIST_W - 50.0, 60.0), Target::Component { id: c });
+ h.frames(2);
+ h.step(&json!({"move":{"handle":"menu:ui.group.component"}})).unwrap();
+ h.frames(2);
+ h.step(&json!({"move":{"handle":"menu:ui.appearance:Appearance"}})).unwrap();
+ h.frames(2);
+ let menu = rect_of("menu:ui.group.component").unwrap();
+ let own = rect_of("menu:ui.rename:Rename").unwrap();
+ let swatch = rect_of("menu:appearance.assign:Aluminum - Satin").unwrap();
+ assert!(own.right() <= menu.left(), "the Component flyout opens to the left: {own:?} {menu:?}");
+ assert!(swatch.right() <= own.left(), "and the Appearance flyout further left: {swatch:?} {own:?}");
+}
+
+/// `ui.menuPick` reaches the entries of every flyout and refuses a row that only opens one.
+#[test]
+fn menu_pick_runs_flyout_entries_and_refuses_a_row_that_only_opens_one() {
+ let (mut h, _) = component_menu();
+ assert!(context_menu::pick(&mut h.app, "Organize").is_err());
+ assert!(h.app.viewport.context_menu.is_some(), "a refused pick leaves the menu open");
+ assert_eq!(context_menu::pick(&mut h.app, "Collapse All").unwrap()["ran"], "browser.collapse_all");
+}
+
+/// Every flyout is as tall as its entries: one opened after a shorter one used to keep the shorter
+/// one's height and scroll, so its last entries could not be clicked.
+#[test]
+fn a_flyout_opened_after_a_shorter_one_shows_all_its_entries() {
+ let (mut h, _) = component_menu();
+ h.step(&json!({"move":{"handle":"menu:ui.group.organize"}})).unwrap();
+ h.frames(2);
+ h.step(&json!({"move":{"handle":"menu:ui.group.component"}})).unwrap();
+ h.frames(3);
+ h.step(&json!({"click":{"handle":"menu:ui.properties:Properties"}})).unwrap();
+ assert!(h.app.menu.props.is_some(), "the last entry of the Component flyout is reachable");
+}
+
+/// A flyout taller than egui's default area size (the quick choices) is measured whole, so it
+/// moves up to fit and its last entries can be clicked.
+#[test]
+fn a_tall_flyout_moves_up_to_fit_and_its_last_entries_can_be_clicked() {
+ let (mut h, c) = component_menu();
+ h.step(&json!({"move":{"handle":"menu:ui.group.component"}})).unwrap();
+ h.frames(2);
+ h.step(&json!({"move":{"handle":"menu:ui.appearance:Appearance"}})).unwrap();
+ h.frames(3);
+ h.step(&json!({"click":{"handle":"menu:appearance.assign:Glass - Smoked"}})).unwrap();
+ assert!(h.app.session.doc.appearances.components.contains_key(&c), "a late quick choice is reachable");
+}
+
#[test]
fn narrow_overflow_submenu_keeps_opening_click_and_accepts_the_next_click() {
use crate::scenario::Harness;
diff --git a/crates/ui-egui/src/occurrence_ui_tests.rs b/crates/ui-egui/src/occurrence_ui_tests.rs
index 67be957d8a..eb55028c50 100644
--- a/crates/ui-egui/src/occurrence_ui_tests.rs
+++ b/crates/ui-egui/src/occurrence_ui_tests.rs
@@ -157,16 +157,16 @@ fn occurrence_second_row_selects_exact_path_and_menu_actions() {
let bounds = crate::viewport::selection_bounds(&h.app).unwrap();
assert!((bounds.center().x - 55.0).abs() < 1e-8);
let target = Target::Occurrence { path: vec![second] };
- let items = context_menu::items(&h.app, &target);
+ let items = context_menu::entries(&h.app, &target);
// Copy takes this placement (the row right-clicked). Paste New pastes an independent copy of
// it into the design, never into itself: off on its own row, on on the design's.
let copy = items.iter().find(|i| i.id == "ui.copy").unwrap();
assert!(copy.enabled);
context_menu::run_item(&mut h.app, copy, egui::Pos2::ZERO);
assert_eq!(h.app.copied_placements, vec![vec![second]]);
- let own = context_menu::items(&h.app, &target);
+ let own = context_menu::entries(&h.app, &target);
assert!(!own.iter().find(|i| i.id == "ui.pasteNew").unwrap().enabled, "not into itself");
- let design = context_menu::items(&h.app, &Target::Component { id: 0 });
+ let design = context_menu::entries(&h.app, &Target::Component { id: 0 });
let independent = design.iter().find(|i| i.id == "ui.pasteNew").unwrap();
assert!(independent.enabled);
assert_eq!(independent.params.as_ref().unwrap()["component"], 0);
@@ -192,7 +192,7 @@ fn turn_up_axis_follows_the_placement_right_clicked() {
// Whichever placement comes first, a grounded one can't turn and a free one can.
let (mut h, _, first, second) = fixture();
let turns = |h: &Harness, occurrence: u64| {
- let items = context_menu::items(&h.app, &Target::Occurrence { path: vec![occurrence] });
+ let items = context_menu::entries(&h.app, &Target::Occurrence { path: vec![occurrence] });
let turn = items.into_iter().find(|i| i.id == "ui.turnUpAxis").unwrap();
let children: Vec<_> = turn.children.iter().map(|c| (c.enabled, c.params.as_ref().unwrap()["occurrence"].as_u64())).collect();
(turn.enabled, children)
@@ -275,7 +275,7 @@ fn occurrence_delete_targets_second_copy_even_if_first_was_selected() {
fn occurrence_new_component_keeps_inactive_second_parent_authoring_context() {
let (mut h, _, first, second) = fixture();
assert_eq!(h.app.session.active_component, 0);
- let items = context_menu::items(&h.app, &Target::Occurrence { path: vec![second] });
+ let items = context_menu::entries(&h.app, &Target::Occurrence { path: vec![second] });
let create = items.iter().find(|i| i.id == "component.create").unwrap();
assert_eq!(create.params.as_ref().unwrap()["parent_path"], json!([second]));
context_menu::run_item(&mut h.app, create, egui::Pos2::ZERO);
@@ -398,7 +398,7 @@ fn a_copied_component_pastes_into_its_parent_not_into_itself() {
click(&mut h, &[second], "row");
let own = Target::Occurrence { path: vec![second] };
let design = Target::Component { id: 0 };
- let find = |h: &Harness, target: &Target, id: &str| context_menu::items(&h.app, target).into_iter().find(|i| i.id == id).unwrap();
+ let find = |h: &Harness, target: &Target, id: &str| context_menu::entries(&h.app, target).into_iter().find(|i| i.id == id).unwrap();
assert!(!find(&h, &own, "ui.pasteNew").enabled, "nothing copied yet");
let copy = find(&h, &own, "ui.copy");
context_menu::run_item(&mut h.app, &copy, egui::Pos2::ZERO);
@@ -557,17 +557,24 @@ fn find_in_browser_reaches_a_folded_body() {
fn a_folded_folders_menu_items_move_to_the_placements_menu() {
use crate::prefs::BodiesFolders;
let (mut h, component, first, _) = fixture();
+ let target = Target::Occurrence { path: vec![first] };
+ let has = |h: &Harness, id: &str| context_menu::entries(&h.app, &target).iter().any(|i| i.id == id);
+ let items = context_menu::items(&h.app, &target);
+ assert!(!has(&h, "component.from_bodies"), "a component's only body is not offered as a component of its own");
+ assert!(items.last().is_some_and(|i| i.id != "-"), "and leaves no separator behind");
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.newGroup"), "on every component's menu");
+ assert!(!has(&h, "ui.showAll"), "Show All Bodies only while something is hidden");
+ h.app.run("browser.visibility", json!({"items": ["Second"], "visible": false})).unwrap();
+ assert!(has(&h, "ui.showAll"), "a hidden body anywhere brings it back");
+ h.app.run("browser.visibility", json!({"items": ["Second"], "visible": true})).unwrap();
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();
diff --git a/crates/ui-egui/src/timeline.rs b/crates/ui-egui/src/timeline.rs
index 0117193b77..6db319a756 100644
--- a/crates/ui-egui/src/timeline.rs
+++ b/crates/ui-egui/src/timeline.rs
@@ -1368,7 +1368,7 @@ mod tests {
assert!(handle_at("timeline:CopyBox").is_some() && handle_at("timeline:PartBox").is_some(), "both parts' features start in the bar");
// The Browser menu offers to hide the copy's History, and running it leaves its entries out.
let copy = h.app.session.doc.components.iter().find(|c| c.name == "Copy").unwrap().id;
- let menu = context_menu::items(&h.app, &Target::Component { id: copy });
+ let menu = context_menu::entries(&h.app, &Target::Component { id: copy });
let hide = menu.iter().find(|i| i.id == "component.hide_history").expect("the component menu offers Hide its History");
context_menu::run_item(&mut h.app, hide, egui::Pos2::ZERO);
h.frames(4);
@@ -1388,7 +1388,7 @@ mod tests {
h.frames(4);
assert!(handle_at("timeline:CopyBox").is_none(), "and hides them again");
// The component menu now offers to show its History back.
- let menu = context_menu::items(&h.app, &Target::Component { id: copy });
+ let menu = context_menu::entries(&h.app, &Target::Component { id: copy });
assert!(menu.iter().any(|i| i.id == "component.show_history"), "the menu flips to Show its History");
}
diff --git a/crates/ui-egui/src/ui_kit/menu.rs b/crates/ui-egui/src/ui_kit/menu.rs
index 4c18ba2df8..da8ad89a48 100644
--- a/crates/ui-egui/src/ui_kit/menu.rs
+++ b/crates/ui-egui/src/ui_kit/menu.rs
@@ -95,7 +95,7 @@ impl Menu {
let popup = Container::new(ui.ctx(), Surface::Popup).menu(&response).open(open).frame(frame);
// Last pass's size; the first pass assumes the flyout fits on the right.
let size = popup.get_expected_size().unwrap_or(egui::Vec2::ZERO);
- let at = Self::flyout_at(ui.ctx().content_rect(), response.interact_rect, size);
+ let at = Self::flyout_at(ui.ctx().content_rect(), response.interact_rect, size, false);
popup.anchor(at).align(egui::RectAlign::BOTTOM_START).align_alternatives(&[]).gap(0.0).show(content)
} else {
Container::new(ui.ctx(), Surface::Popup).menu(&response).frame(frame).show(content)
@@ -167,12 +167,15 @@ impl Menu {
}
/// Where a flyout of `size` sits beside its `row`: on the right with its first row level with
- /// `row`, on the left only when the right has no room (#8267), and kept on screen.
- pub(crate) fn flyout_at(screen: Rect, row: Rect, size: egui::Vec2) -> egui::Pos2 {
+ /// `row`, on the left only when the right has no room (#8267), and kept on screen. A flyout of
+ /// a flyout that opened to the left (`leftward`) opens to the left too while there is room, so
+ /// it never covers the menu.
+ pub(crate) fn flyout_at(screen: Rect, row: Rect, size: egui::Vec2, leftward: bool) -> egui::Pos2 {
let margin = Self::frame().total_margin();
let gap = margin.right + 2.0;
let right = row.right() + gap;
- let x = if right + size.x <= screen.right() { right } else { (row.left() - gap - size.x).max(screen.left()) };
+ let left = row.left() - gap - size.x;
+ let x = if right + size.x <= screen.right() && !(leftward && left >= screen.left()) { right } else { left.max(screen.left()) };
let y = (row.top() - margin.top).min(screen.bottom() - size.y).max(screen.top());
pos2(x, y)
}
@@ -233,10 +236,27 @@ impl Menu {
}
/// Place a submenu beside its row with [`Self::flyout_at`].
- pub(crate) fn submenu<R>(ctx: &egui::Context, id: egui::Id, row: Rect, height: f32, add: impl FnOnce(&mut Ui) -> R) -> egui::InnerResponse<R> {
+ pub(crate) fn submenu<R>(
+ ctx: &egui::Context,
+ id: egui::Id,
+ row: Rect,
+ height: f32,
+ leftward: bool,
+ add: impl FnOnce(&mut Ui) -> R,
+ ) -> egui::InnerResponse<R> {
let width = crate::context_menu::LIST_W;
- let at = Self::flyout_at(ctx.content_rect(), row, vec2(width, height));
- Container::new(ctx, Surface::Popup).area(id).fixed_pos(at).order(egui::Order::Foreground).show(ctx, |ui| Self::show(ui, width, add))
+ let screen = ctx.content_rect();
+ // The estimate only places the area's first, invisible sizing pass.
+ let height = ctx.memory(|m| m.area_rect(id)).map_or(height, |r| r.height());
+ let at = Self::flyout_at(screen, row, vec2(width, height), leftward);
+ // The sizing pass caps the contents at the default size (egui's is 400 points high), and a
+ // scrolling flyout keeps whatever height it measured there.
+ Container::new(ctx, Surface::Popup)
+ .area(id)
+ .default_size(vec2(width, screen.height()))
+ .fixed_pos(at)
+ .order(egui::Order::Foreground)
+ .show(ctx, |ui| Self::show(ui, width, add))
}
}
@@ -536,16 +556,21 @@ mod tests {
let size = vec2(200.0, 100.0);
let top = Menu::frame().total_margin().top;
let row = Rect::from_min_max(pos2(100.0, 50.0), pos2(400.0, 80.0));
- let at = Menu::flyout_at(screen, row, size);
+ let at = Menu::flyout_at(screen, row, size, false);
assert!(at.x > row.right() && at.x + size.x <= screen.right(), "{at:?}");
assert_eq!(at.y, row.top() - top);
// No room on the right: the flyout sits left of the row, still clear of it.
let edge = row.translate(vec2(500.0, 0.0));
- let at = Menu::flyout_at(screen, edge, size);
+ let at = Menu::flyout_at(screen, edge, size, false);
assert!(at.x + size.x < edge.left() && at.x >= screen.left(), "{at:?}");
// A row near the bottom keeps its flyout on screen.
let low = row.translate(vec2(0.0, 500.0));
- assert_eq!(Menu::flyout_at(screen, low, size).y, screen.bottom() - size.y);
+ assert_eq!(Menu::flyout_at(screen, low, size, false).y, screen.bottom() - size.y);
+ // Leftward keeps to the left while it fits there, and goes right where it does not.
+ let middle = Rect::from_min_max(pos2(300.0, 50.0), pos2(500.0, 80.0));
+ let at = Menu::flyout_at(screen, middle, size, true);
+ assert!(at.x + size.x < middle.left() && at.x >= screen.left(), "{at:?}");
+ assert!(Menu::flyout_at(screen, row, size, true).x > row.right());
}
#[test]
diff --git a/crates/ui-egui/tests/icon_audit.rs b/crates/ui-egui/tests/icon_audit.rs
index a544b7abf2..66fd764c6b 100644
--- a/crates/ui-egui/tests/icon_audit.rs
+++ b/crates/ui-egui/tests/icon_audit.rs
@@ -71,23 +71,27 @@ fn menu(h: &mut Harness, target: Value, surface: &str, requested: &mut BTreeMap<
let intentional = id == "-" || id.starts_with('#') || (id == "ui.workspace" && item["shortcut"] == "coming later");
assert!(!blank || intentional, "{surface}: icon-less menu item {item}");
assert_eq!(item["placeholder"], false, "{surface}: {item}");
- if let Some(children) = item["children"].as_array() {
- for child in children {
- let id = child["id"].as_str().unwrap();
- assert!(!id.is_empty(), "{surface}: child has no identity");
- if id == "-" || id.starts_with('#') {
- continue;
- }
- let icon = child["icon"].as_str().unwrap();
- assert!(!icon.is_empty(), "{surface}: submenu row has no icon: {child}");
- assert!(!solidcraft_ui_egui::icon_svg::resolve(icon).placeholder, "{surface}: submenu placeholder {icon}");
- }
- }
+ flyout_icons(item, surface);
}
collect(h, surface, requested);
escape(h);
}
+/// The rows of an item's flyout, and of the flyouts inside it, all have real icons.
+fn flyout_icons(item: &Value, surface: &str) {
+ for child in item["children"].as_array().into_iter().flatten() {
+ let id = child["id"].as_str().unwrap();
+ assert!(!id.is_empty(), "{surface}: child has no identity");
+ if id == "-" || id.starts_with('#') {
+ continue;
+ }
+ let icon = child["icon"].as_str().unwrap();
+ assert!(!icon.is_empty(), "{surface}: submenu row has no icon: {child}");
+ assert_eq!(child["placeholder"], false, "{surface}: submenu placeholder {icon}");
+ flyout_icons(child, surface);
+ }
+}
+
fn ribbon(h: &mut Harness, requested: &mut BTreeMap<String, bool>) {
for tab in workspace::visible_tabs(&h.app) {
click(h, &format!("tab:{tab}"));
diff --git a/crates/ui-egui/tests/stand_up_offer.rs b/crates/ui-egui/tests/stand_up_offer.rs
index c6fa1cc516..cbe7d92cb6 100644
--- a/crates/ui-egui/tests/stand_up_offer.rs
+++ b/crates/ui-egui/tests/stand_up_offer.rs
@@ -157,7 +157,8 @@ fn turn_up_axis_in_the_component_menu_turns_and_undo_restores() {
let occurrence = h.app.session.doc.occurrences.iter().map(|o| o.id).max().expect("the import's occurrence");
h.app.run("occurrence.ground", json!({"occurrence": occurrence, "grounded": false})).unwrap();
let items = solidcraft_ui_egui::context_menu::items(&h.app, &solidcraft_ui_egui::context_menu::Target::Occurrence { path: vec![occurrence] });
- let turn = items.iter().find(|i| i.id == "ui.turnUpAxis").expect("Turn Up Axis is in the menu");
+ let placement = items.iter().find(|i| i.label == "Placement").expect("the Placement flyout is in the menu");
+ let turn = placement.children.iter().find(|i| i.id == "ui.turnUpAxis").expect("Turn Up Axis is in the Placement flyout");
let labels: Vec<_> = turn.children.iter().map(|c| c.label.as_str()).collect();
assert_eq!(labels, ["Y up \u{2192} Z up", "Z up \u{2192} Y up"]);
let at = egui::pos2(10.0, 10.0);
diff --git a/docs/book/src/guide/assemblies.md b/docs/book/src/guide/assemblies.md
index 2328fb6cc0..e7580a9405 100644
--- a/docs/book/src/guide/assemblies.md
+++ b/docs/book/src/guide/assemblies.md
@@ -20,7 +20,7 @@ A component is placed by its **occurrences**. Paste creates another instance of
component, and **Paste New** creates an independent copy. Move an occurrence with the move
triad, then **Capture Position** to keep it or **Revert** to put it back. SolidCraft asks before
the next command if a move wasn't captured. **Ground** fixes an occurrence in place, and
-**Unground** (the same row of the browser's context menu) frees it again.
+**Unground** (the same row of **Placement** in the browser's context menu) frees it again.
The design's first part is grounded when it is made: the first occurrence placed directly in the
design by **New Component**, **Create Components from Bodies** or an import. Parts made after it,
@@ -73,7 +73,7 @@ user parameters remain shared; retained external links and omitted cross-boundar
records are reported. Unsupported destructive links refuse the entire copy. See
[individual-instance and copy details](https://github.com/tangency-labs/solidcraft/blob/main/docs/occurrence-workflows.md).
-**Extract to File** (`component.extract`, in a component's right-click menu) moves a component
+**Extract to File** (`component.extract`, under **Component** in a component's right-click menu) moves a component
into a design of its own: its sketches, features, bodies, subcomponents and the joints among them
go to the new `.sc` file at its origin, with the parameters they use, and the component
becomes linked to that file, as **Insert Design** makes it. Its placements and the joints to the
@@ -450,7 +450,7 @@ place** (Preferences, Design, `double_click_components`) turns this off: a doubl
Browser then activates every component, and one in the view does nothing.
If a source file moves or is renamed, right-click its linked component or occurrence in the
-Browser and choose **Relink Source (All Instances)…**. Choose the saved `.sc` design
+Browser and choose **Component → Relink Source (All Instances)…**. Choose the saved `.sc` design
to use. Relinking updates that component's stored path and solid bodies for **all its
instances**, keeping their identities and placements. Cancelling or choosing a missing,
invalid, empty or self-referencing design leaves the assembly unchanged. The operation is
@@ -467,7 +467,7 @@ joint still describes the intended connection.
STEP export writes the component tree as an assembly.
-Right-click a component in the Browser and choose **Properties**, or use **Inspect → Measure →
+Right-click a component in the Browser and choose **Component → Properties**, or use **Inspect → Measure →
Properties** for the selected placement or the active component, to inspect material-aware
mass, volume, surface area, centre of mass, first moments, moment of inertia and world bounds.
While the window is open, the view marks the centre of mass with the three principal axes
diff --git a/docs/book/src/guide/files.md b/docs/book/src/guide/files.md
index 1bd2c7ec70..e957a93456 100644
--- a/docs/book/src/guide/files.md
+++ b/docs/book/src/guide/files.md
@@ -22,7 +22,7 @@ Every imported file (STEP, IGES, 3MF, STL, OBJ or glTF) comes in as a new compon
file, so its bodies never mix with yours. A STEP assembly keeps its structure: its parts and
sub-assemblies become nested components, and a part used several times is one component with an
occurrence for each place. The imported assembly is rigid: moving its component moves everything,
-and its parts don't move on their own. Right-click the component and choose **Unlock Contents** to
+and its parts don't move on their own. Right-click the component and choose **Placement → Unlock Contents** to
joint the parts one by one. Undo removes a whole import in one step.
A glTF file (`.glb`, or `.gltf` with the `.bin` files it names in the same folder) comes in the
@@ -209,7 +209,7 @@ The control channel sets the same preference with `ui.prefs {"max_step_file_mb":
## Design properties
**File → Design Properties…** (also under **Document Settings** in the Browser, and on the
-top component's right-click menu) records who made a design and what it is: project, part
+top component's right-click menu, under **Design**) records who made a design and what it is: project, part
number, revision, author, organization, description and licence. **OK** applies the changes as
one undo step. Scripts and agents use the same commands: `document.metadata` reads them,
`document.metadata.set` (`key` and `value`, or `values: {key: value, …}`) and
diff --git a/docs/book/src/guide/ui-tour.md b/docs/book/src/guide/ui-tour.md
index 39ecb9c798..b95471963f 100644
--- a/docs/book/src/guide/ui-tour.md
+++ b/docs/book/src/guide/ui-tour.md
@@ -38,8 +38,8 @@ view.
origin, bodies, sketches, construction planes, canvases, joints and components. The eye at the
row's right end shows or hides an item (**Preferences › Interface › Eye next to the fold arrow**
puts it back beside the fold arrow; press an eye and drag up or down over other eyes to show or hide them all at once, as one undo step), 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
+ and right-clicking any row gives that item's menu. Right-click the design or a component and choose
+ **Organize → 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). Components start closed, so a large assembly opens as a
short list; open one with its fold arrow, or use **Find in Browser** on a body to open the rows
down to it (**Preferences › Interface › Components start open** opens every component from the
diff --git a/docs/control-protocol.md b/docs/control-protocol.md
index 899e7a3ffb..efdfdc223f 100644
--- a/docs/control-protocol.md
+++ b/docs/control-protocol.md
@@ -619,9 +619,9 @@ no box selection.
| `ui.click` | `x`, `y` (screen points), `button?`: left/right/middle, `shift?`, `ctrl?`, `double?` | real pointer input |
| `ui.move` | `x`, `y`, `shift?`, `alt?`, `ctrl?`, `cmd?` | pointer movement without a button; modifiers apply until the next synthetic move/click; a move with omitted modifiers releases them. With `nav: "touchpad"`, Shift pans and Alt/Option orbits. |
| `ui.drag` | `x0`, `y0`, `x1`, `y1`, `via?`, `button?`, `shift?`, `ctrl?`, `steps?`, `hold?`, `hold_end?` | press, move, release; `via` is a list of `[x, y]` points passed through on the way (`steps` moves to each); a left drag on the model is a box selection (left to right: window, right to left: crossing), or with `lassoSelect` on (`ui.set`, the SELECT panel's Lasso) a freehand lasso that takes what is wholly inside it; with OpenSCAD navigation, plain left-drag on empty space orbits, Shift+left-drag box-selects, and drags starting on sketch geometry edit it; `hold` keeps the button down that many frames first (a right press-and-hold opens the marking menu, releasing over a direction picks it), `hold_end` that many frames at the end (a sketch drag shows its snap) |
-| `ui.menu` | `x?`, `y?`, `target?`, `close?` | with a point: open a context menu there as a right-click would (the viewport's marking menu, or a browser menu with `target: {"type": "body", "name"} \| {"type": "sketch", "id"} \| {"type": "component", "id"}`); without: the open menu (`radial` and `items`: id, label, shortcut, enabled, icon, placeholder; blank icons on headings/separators have `placeholder: false`) |
+| `ui.menu` | `x?`, `y?`, `target?`, `close?` | with a point: open a context menu there as a right-click would (the viewport's marking menu, or a browser menu with `target: {"type": "body", "name"} \| {"type": "sketch", "id"} \| {"type": "component", "id"}`); without: the open menu (`radial` and `items`: id, label, shortcut, enabled, icon, placeholder, and `children` for a row that opens a flyout; blank icons on headings/separators have `placeholder: false`) |
| `ui.icon_audit` | `reset?`, `stop?` | `reset: true` enables collection on the UI thread and clears previous requests; returns `{requested: [{name, master, placeholder}]}` sorted by requested id. Each read drains names collected since the previous read/reset. Collection stays enabled until `stop: true` (which returns pending names before disabling it). Includes aliases, variable/table ids and cached paints. |
-| `ui.menuPick` | `item`: id or label | runs an item of the open menu, as clicking it does |
+| `ui.menuPick` | `item`: id or label | runs an item of the open menu or of any of its flyouts, as clicking it does; a row that only opens a flyout is refused |
| `ui.selectOther` | `x?`, `y?`, `pick?`, `add?`, `hover?`, `close?` | Select Other: with a point, list compatible hidden and visible geometry near the pointer by default (as holding the left button does; disable `select_other_hidden` for the original visible-only list); the popup fits the available window space and scrolls only for overflow; `pick`: select row `pick` (`add`: as Shift-click; with a dialog open, into its active input); `hover`: light a row up; without: the open list (`open`, `at`, `total`: everything under the cursor, `rows`: label, icon, sel, at most 20 per kind, nearest first) |
| `ui.rename` | `text?`, `commit?` (default true) | finishes the rename box a Rename item opened |
| `ui.selection` | | the selection, the open dialog's inputs, the hovered item, and the active sketch's drawn dimensions (`dimensions`: id and text centre, `dimension_selected`, `dimension_editing`), and finished sketches' dimensions shown in the model view (`shown_dimensions`: sketch, id and text centre; a double-click there edits the value) |
diff --git a/docs/step-import.md b/docs/step-import.md
index 62e361116a..e9f75a25b9 100644
--- a/docs/step-import.md
+++ b/docs/step-import.md
@@ -45,7 +45,7 @@ the supporting ellipse in the middle.
Files from different systems differ in which way is up and in what they call their solids. `doc.open`, `file.insert_step` and the MCP `open` tool take two options for STEP and IGES files; without them a file comes in as written.
-- **`up`**: `"z"` (the default) keeps the file's axes. Many systems write Y up, so such a part lies on its back in SolidCraft's Z-up space. `"up": "y"` turns the import's component a quarter turn about X (+90°: Y becomes Z), as the window's "Stand it up" offer does, so an assembly's parts and instances turn together. The import and the turn are one undo step, the reply names the turned occurrence as `stand_up`, and only the file's component turns, not what is already in the design. The window offers to stand a part up after a STEP file opens unless the call said which way is up (`up: "z"` as well as `"y"`) or the file came from SolidCraft, which already writes Z up. A STEP reply's `system` is the originating system the file's header names (`SolidCraft` for SolidCraft's own exports). A header that names SolidWorks (in FILE_NAME's originating system or preprocessor version, or in FILE_DESCRIPTION; for IGES, the start of the global section's native system ID, which becomes the originating system) says the file has Y up: the reply carries `exporter` (`SolidWorks`) and `exporter_up` (`y`), and the window asks in the "Stand this part up?" dialog, which says so ("Exported by SolidWorks, which usually saves Y up"). A file is never turned without asking, because the exporter may have saved it Z up; a component's right-click menu has Turn Up Axis (Y up → Z up, Z up → Y up: a quarter turn about X, one undo step) for fixing it any time. SolidCraft's own files say `z` and are left alone. Any other exporter is unknown, and such files are often upright already, so by default the window first looks at how the bodies rest: a part rests on its flat faces, so the flat area facing down Z is weighed against the larger flat area facing down or up Y (faces within 10° of the direction; one side must have at least 1.5 times the other's, else the thinner of the box's Y and Z sizes decides). Unless the file clearly stands upright, the window shows a small note over the view ("Did this part open the wrong way up?" with Stand it up and Close) that goes by itself after 10 seconds and never blocks input; a file that clearly stands upright gets nothing, and an unclear shape still gets the note. A SolidWorks file whose bodies clearly stand on Z already gets the note instead of the dialog, since it may have been saved Z up. Preferences › Design › "For files from unknown programs" picks the dialog for every file from another program, SolidWorks too, without looking at how it rests (Ask in a dialog, as before) or no offer (Don't offer) instead. The dialog and the note say "assembly" when the file brought more than one body or a component tree.
+- **`up`**: `"z"` (the default) keeps the file's axes. Many systems write Y up, so such a part lies on its back in SolidCraft's Z-up space. `"up": "y"` turns the import's component a quarter turn about X (+90°: Y becomes Z), as the window's "Stand it up" offer does, so an assembly's parts and instances turn together. The import and the turn are one undo step, the reply names the turned occurrence as `stand_up`, and only the file's component turns, not what is already in the design. The window offers to stand a part up after a STEP file opens unless the call said which way is up (`up: "z"` as well as `"y"`) or the file came from SolidCraft, which already writes Z up. A STEP reply's `system` is the originating system the file's header names (`SolidCraft` for SolidCraft's own exports). A header that names SolidWorks (in FILE_NAME's originating system or preprocessor version, or in FILE_DESCRIPTION; for IGES, the start of the global section's native system ID, which becomes the originating system) says the file has Y up: the reply carries `exporter` (`SolidWorks`) and `exporter_up` (`y`), and the window asks in the "Stand this part up?" dialog, which says so ("Exported by SolidWorks, which usually saves Y up"). A file is never turned without asking, because the exporter may have saved it Z up; a component's right-click menu has Placement → Turn Up Axis (Y up → Z up, Z up → Y up: a quarter turn about X, one undo step) for fixing it any time. SolidCraft's own files say `z` and are left alone. Any other exporter is unknown, and such files are often upright already, so by default the window first looks at how the bodies rest: a part rests on its flat faces, so the flat area facing down Z is weighed against the larger flat area facing down or up Y (faces within 10° of the direction; one side must have at least 1.5 times the other's, else the thinner of the box's Y and Z sizes decides). Unless the file clearly stands upright, the window shows a small note over the view ("Did this part open the wrong way up?" with Stand it up and Close) that goes by itself after 10 seconds and never blocks input; a file that clearly stands upright gets nothing, and an unclear shape still gets the note. A SolidWorks file whose bodies clearly stand on Z already gets the note instead of the dialog, since it may have been saved Z up. Preferences › Design › "For files from unknown programs" picks the dialog for every file from another program, SolidWorks too, without looking at how it rests (Ask in a dialog, as before) or no offer (Don't offer) instead. The dialog and the note say "assembly" when the file brought more than one body or a component tree.
- **`names`**: `"auto"` (the default) keeps meaningful solid names and replaces placeholders such as `Body1` or `Body 2 (3)` with the nearest named product, then the occurrence name if no product is named. `"solid"` keeps the solid's name; `"product"` chooses the part's name; `"instance"` chooses the assembly occurrence (`Post-2`), falling back to the product. If the chosen name is missing, the solid's name remains. Repeated names are numbered (`Post`, `Post (2)`). Names are stored with the Import feature and survive reopening the design. Files without names or assembly metadata retain generated body names and a flat structure.
- **Vertices off their curves**: some systems write an edge's vertex a little beside the end of its curve, often further off than the accuracy the file declares (`UNCERTAINTY_MEASURE_WITH_UNIT`). A vertex up to the file's own tolerance off, or up to 1/1000 of the model's size (never more than 1 mm), is read as that end of the edge: the curve's end is moved onto the vertex. A vertex further off leaves its face out, with a warning that says how far off it is.