Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion crates/ui-egui/src/context_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,8 @@ fn occurrence_items(app: &SolveApp, path: &[u64]) -> Vec<Item> {
entries.insert(0, Item::heading("Shared child: edits affect all copies of its parent"));
}
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" => {
Expand All @@ -846,11 +848,13 @@ fn occurrence_items(app: &SolveApp, path: &[u64]) -> Vec<Item> {
}
"ui.moveOccurrence" => {
item.params = Some(json!({"occurrence": placement.occurrence, "path": path}));
item.enabled = !placement.grounded && app.session.held_by_rigid_group(placement.occurrence).is_none();
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);
}
Expand Down
18 changes: 18 additions & 0 deletions crates/ui-egui/src/occurrence_ui_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,24 @@ fn occurrence_second_row_selects_exact_path_and_menu_actions() {
assert_eq!(h.app.session.active_occurrence_path, Some(vec![second]));
}

#[test]
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 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)
};
for (grounded, free) in [(first, second), (second, first)] {
h.app.run("occurrence.ground", json!({"occurrence": grounded, "grounded": true})).unwrap();
h.app.run("occurrence.ground", json!({"occurrence": free, "grounded": false})).unwrap();
assert_eq!(turns(&h, free), (true, vec![(true, Some(free)); 2]), "free placement {free}");
assert_eq!(turns(&h, grounded), (false, vec![(false, Some(grounded)); 2]), "grounded placement {grounded}");
}
}

#[test]
fn occurrence_eye_and_fold_are_independent_and_survive_rename() {
let (mut h, component, first, second) = fixture();
Expand Down
Loading