diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index a18faa8f5..48aea5488 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -526,6 +526,11 @@ pub struct Dialog { pub(crate) chain_applied: bool, /// A pattern's objects of the Object Type not shown now, restored when it is chosen again. pub(crate) other_objects: Vec, + /// The multi-pick input whose picked items are listed under it, each removable (#3683). + pub(crate) listed: Option, + /// The listed item (and its input) whose row is under the pointer: the view lights it as a + /// hover (`viewport::list_hover`). + pub(crate) list_hover: Option<(usize, Sel)>, /// Shell feedback is derived from the picks, never saved as additional face references. shell_chain: std::cell::RefCell>, /// An extrude Press Pull opened with nothing selected: its first pick may be a curved face or @@ -793,6 +798,8 @@ impl Dialog { picked_edges: Vec::new(), chain_applied, other_objects: Vec::new(), + listed: None, + list_hover: None, shell_chain: Default::default(), press_pull: false, op_auto: Default::default(), @@ -1858,6 +1865,80 @@ impl Dialog { inp.items = items; self.error = None; } + + /// What input `i`'s list of picked items shows, one row each (#3683): what its chip counts. + /// A rim or a surface split into pieces is one row, as it is one pick; a Shell with Tangent + /// Chain lists every face it opens. + pub(crate) fn listed_items(&self, s: &Session, i: usize) -> Vec { + if i == 0 + && let Some(faces) = self.shell_faces(s) + { + return faces; + } + let mut rows: Vec = Vec::new(); + let mut shown: Vec = Vec::new(); + for item in self.inputs.get(i).map(|inp| inp.items.as_slice()).unwrap_or_default() { + if shown.iter().any(|x| selection::same_item(x, item)) { + continue; + } + shown.extend(crate::viewport::grouped_selection(s, item)); + rows.push(item.clone()); + } + rows + } + + /// Remove a listed row's item from input `i`, as picking it again toggles it off: the + /// pieces of its rim or surface go with it, and the hand-picked edges and the explicit + /// profile choice follow. A face a Shell's tangent chain opens goes with the picks whose + /// chain holds it. + pub(crate) fn remove_listed(&mut self, s: &Session, i: usize, item: &Sel) { + let shell_chain = i == 0 && self.shell_faces(s).is_some(); + // A Fillet or Chamfer row its Tangent Chain brought goes with the picks whose chain holds + // it, as picking it again would; else ticking Tangent Chain again brings it back. + let fillet_chain = i == 0 && matches!(self.kind, Kind::Fillet { chain: true, .. }) && self.chain_applied; + let state = s.world_state().ok(); + let mut gone = if shell_chain { Vec::new() } else { crate::viewport::grouped_selection(s, item) }; + gone.push(item.clone()); + if fillet_chain { + let seeds: Vec = self + .picked_edges + .iter() + .filter(|seed| fillet_edges(s, seed, true).iter().any(|x| gone.iter().any(|g| selection::same_item(x, g)))) + .cloned() + .collect(); + for seed in &seeds { + gone.extend(fillet_edges(s, seed, true)); + } + gone.extend(seeds); + } + let Some(inp) = self.inputs.get_mut(i) else { return }; + match (shell_chain, item, state.as_ref()) { + (true, Sel::Face { body, index, .. }, Some(st)) => { + let model = st.body(body); + inp.items.retain(|pick| { + let Sel::Face { body: b, point, .. } = pick else { return true }; + b != body || !model.is_some_and(|m| solidcraft_engine::doc::tangent_face_chain(m, &[*point]).iter().any(|(f, _)| f == index)) + }); + } + // Without the model to find the chain in, the row goes on its own. + _ => { + inp.items.retain(|x| !gone.iter().any(|g| selection::same_item(x, g))); + if i == 0 { + self.picked_edges.retain(|x| !gone.iter().any(|g| selection::same_item(x, g))); + } + } + } + let empty = inp.items.is_empty(); + if empty && self.listed == Some(i) { + self.listed = None; + } + if i == 0 && matches!(self.kind, Kind::Extrude { .. } | Kind::Revolve { .. } | Kind::Emboss { .. }) { + self.profile_selection_changed = true; + } + self.list_hover = None; + self.error = None; + self.sync_thread(s); + } } /// The edges a Fillet or Chamfer pick stands for: its tangent chain when `chain` is on, else @@ -2850,6 +2931,8 @@ pub(crate) fn input_rows_range(d: &mut Dialog, ui: &mut egui::Ui, s: &Session, n // Only one field may look active at a time (#10066): while a text editor holds the keyboard, // no pick field draws its accent ring, and clicking a pick field takes the keyboard back. let text_focus = crate::ui_kit::editor_has_focus(ui.ctx()); + let mut toggle_list: Option = None; + let mut hovered: Option<(usize, Sel)> = None; let shell_count = d.shell_faces(s).map(|faces| faces.len()); for (i, inp) in d.inputs.iter().enumerate().skip(range.start).take(range.end.saturating_sub(range.start)) { let stored_reference = stored_input_reference_key(d, i).and_then(|key| d.extra.get(key)).filter(|_| inp.items.is_empty()); @@ -2919,22 +3002,51 @@ pub(crate) fn input_rows_range(d: &mut Dialog, ui: &mut egui::Ui, s: &Session, n clear = Some(i); surrender_keyboard_focus(ui); } + // Several picks: an arrow beside the clear button lists them, each with its + // own remove button (#3683). Drawn straight into the row, which is this field's + // own: a scope around it would take room and widen the dialog. + if inp.multi { + let open = d.listed == Some(i); + let at = rect.translate(vec2(-t.space_24, 0.0)); + let label = crate::i18n::tr_label(if open { "Hide the picked items" } else { "Show the picked items" }); + let arrow = crate::ui_kit::disclosure_button_at(ui, at, open, label); + crate::scenario::publish_handle(&format!("dialog:list_toggle:{}", inp.label), arrow.rect.center()); + if arrow.clicked() { + toggle_list = Some(i); + } + } } }); }); - if matches!(d.kind, Kind::SketchModify(_)) && inp.multi { - for (index, item) in inp.items.iter().enumerate() { - if crate::ui_kit::list_row(ui, &format!("{}:{index}", inp.label), &selection_label(s, names, d, inp, item)).clicked() { - remove = Some((i, index)); + if inp.multi && d.listed == Some(i) && !inp.items.is_empty() { + let rows = d.listed_items(s, i); + egui::ScrollArea::vertical().id_salt(("picked_items", i)).max_height(t.control_height * 6.5).show(ui, |ui| { + for (index, item) in rows.into_iter().enumerate() { + let row = crate::ui_kit::list_row(ui, &format!("{}:{index}", inp.label), &selection_label(s, names, d, inp, &item)); + if row.hovered() { + hovered = Some((i, item.clone())); + } + if row.clicked() { + remove = Some((i, item)); + } } - } + }); } } - if let Some((input, index)) = remove - && let Some(input) = d.inputs.get_mut(input) - && index < input.items.len() - { - input.items.remove(index); + // The row under the pointer lights its item in the view; rows of inputs drawn elsewhere + // keep theirs. + let ours = |h: &Option<(usize, Sel)>| h.as_ref().is_some_and(|(i, _)| range.contains(i)); + if hovered.is_some() || ours(&d.list_hover) { + if d.list_hover != hovered { + ui.ctx().request_repaint(); + } + d.list_hover = hovered; + } + if let Some(i) = toggle_list { + d.listed = if d.listed == Some(i) { None } else { Some(i) }; + } + if let Some((input, item)) = remove { + d.remove_listed(s, input, &item); } if let Some(i) = activate { d.active = i; @@ -2947,6 +3059,10 @@ pub(crate) fn input_rows_range(d: &mut Dialog, ui: &mut egui::Ui, s: &Session, n if let Some(key) = stored_input_reference_key(d, i) { d.extra.remove(key); } + if d.listed == Some(i) { + d.listed = None; + d.list_hover = None; + } let Some(inp) = d.inputs.get_mut(i) else { return }; inp.items.clear(); if i == 0 { diff --git a/crates/ui-egui/src/dialogs_all_tests.rs b/crates/ui-egui/src/dialogs_all_tests.rs index 5f7cfbd35..e2ca53e73 100644 --- a/crates/ui-egui/src/dialogs_all_tests.rs +++ b/crates/ui-egui/src/dialogs_all_tests.rs @@ -1468,6 +1468,12 @@ fn dialog_profile_labels_name_the_sketch_in_coil_and_mirror() { h.app.start(command); h.app.dialog.as_mut().unwrap().preview_enabled = false; h.frames(3); + // A field that takes several picks lists them, labels and all, behind its arrow (#3683). + let (multi, label) = h.app.dialog.as_ref().map(|d| (d.inputs[0].multi, d.inputs[0].label)).unwrap(); + if multi { + h.step(&json!({"click": {"handle": format!("dialog:list_toggle:{label}")}})).unwrap(); + h.frames(2); + } let d = h.app.dialog.as_ref().unwrap(); let input = &d.inputs[0]; assert_eq!(input.items, vec![Sel::Profile { sketch, index: 0 }]); diff --git a/crates/ui-egui/src/dialogs_sketch_tests.rs b/crates/ui-egui/src/dialogs_sketch_tests.rs index 19fc84d8f..453740073 100644 --- a/crates/ui-egui/src/dialogs_sketch_tests.rs +++ b/crates/ui-egui/src/dialogs_sketch_tests.rs @@ -406,6 +406,14 @@ fn picked_list_removes_one_item_and_field_still_activates_input() { d.inputs[0].items.push(Sel::SketchCurve { id: second.clone(), sketch: None }); h.app.dialog = Some(d); h.frames(4); + assert!(crate::scenario::handle_at("dialog:list:Entities:0:remove").is_none(), "the list starts folded, as in every dialog"); + h.step(&json!({"click":{"handle":"dialog:list_toggle:Entities"}})).unwrap(); + h.frames(2); + // Hovering a row lights its curve in the sketch. + let row = crate::scenario::handle_at("dialog:list:Entities:1:remove").unwrap(); + h.call("ui.move", json!({"x": row.x, "y": row.y})); + h.frames(2); + assert!(matches!(&h.app.viewport.hover, Some(crate::viewport::Hit::SketchCurve { id, .. }) if *id == second), "{:?}", h.app.viewport.hover); h.step(&json!({"click":{"handle":"dialog:list:Entities:0:remove"}})).unwrap(); assert_eq!(h.app.dialog.as_ref().unwrap().inputs[0].items, vec![Sel::SketchCurve { id: second, sketch: None }]); h.step(&json!({"click":{"handle":"dialog:Base point"}})).unwrap(); diff --git a/crates/ui-egui/src/preselect_tests.rs b/crates/ui-egui/src/preselect_tests.rs index 6b4bd8254..2c8c11808 100644 --- a/crates/ui-egui/src/preselect_tests.rs +++ b/crates/ui-egui/src/preselect_tests.rs @@ -3270,3 +3270,337 @@ fn coincident_takes_a_selected_line_midpoint() { } } } + +/// #3683: a multi-pick field lists its picked items on request, and one of them can be removed +/// from the dialog without clearing the others. +#[test] +fn one_picked_edge_is_removed_from_the_dialog_list() { + let mut h = crate::scenario::Harness::new(); + h.app.run("solid.box", json!({"length": 40, "width": 30, "height": 20})).unwrap(); + h.frames(2); + let edge = |h: &crate::scenario::Harness, p: Vec3| { + let st = h.app.session.world_state().unwrap(); + let m = st.body("Body1").unwrap().mesh(); + let i = m.edges.iter().position(|e| e.windows(2).any(|w| p.dist_to_segment(w[0], w[1]) < 1e-9)).expect("an edge there"); + Sel::Edge { body: "Body1".into(), index: i, point: p } + }; + let picks = [Vec3::new(20.0, 0.0, 20.0), Vec3::new(40.0, 15.0, 20.0), Vec3::new(20.0, 30.0, 20.0)].map(|p| edge(&h, p)); + h.app.session.selection = picks.to_vec(); + h.app.start("solid.fillet"); + h.frames(3); + let items = |h: &crate::scenario::Harness| h.app.dialog.as_ref().map(|d| d.inputs[0].items.clone()).unwrap_or_default(); + assert_eq!(items(&h).len(), 3); + let label = h.app.dialog.as_ref().unwrap().inputs[0].label; + assert!(crate::scenario::handle_at(&format!("dialog:list:{label}:1:remove")).is_none(), "the list starts folded"); + + h.step(&json!({"click": {"handle": format!("dialog:list_toggle:{label}")}})).unwrap(); + h.frames(2); + assert!(crate::scenario::handle_at(&format!("dialog:list:{label}:2:remove")).is_some(), "every pick is listed"); + h.step(&json!({"click": {"handle": format!("dialog:list:{label}:1:remove")}})).unwrap(); + h.frames(2); + let left = items(&h); + assert_eq!(left.len(), 2, "{left:?}"); + assert!( + crate::selection::same_item(&left[0], &picks[0]) && crate::selection::same_item(&left[1], &picks[2]), + "only the second edge went: {left:?}" + ); + + // The clear button still clears them all, and folds the list. + h.step(&json!({"click": {"handle": format!("dialog:clear:{label}")}})).unwrap(); + h.frames(2); + assert!(items(&h).is_empty()); + assert_eq!(h.app.dialog.as_ref().unwrap().listed, None); +} + +/// #3683: with Tangent Chain on, removing a row the chain brought takes out the pick that +/// brought it and its whole chain, as picking that edge again would; ticking Tangent Chain off +/// and on does not bring it back. +#[test] +fn removing_a_tangent_chain_row_removes_its_seed() { + let mut h = crate::scenario::Harness::new(); + h.app.run("solid.box", json!({"length": 40, "width": 30, "height": 20})).unwrap(); + // Round the four upright edges: the top rim is then one tangent loop of lines and arcs. + h.app.run("solid.fillet", json!({"edges": [[0, 0, 10], [40, 0, 10], [40, 30, 10], [0, 30, 10]], "radius": 5})).unwrap(); + h.frames(2); + let rim = crate::dialogs::edge_sel(&h.app.session, Vec3::new(20.0, 0.0, 20.0)).unwrap(); + let other = crate::dialogs::edge_sel(&h.app.session, Vec3::new(20.0, 0.0, 0.0)).unwrap(); + h.app.session.selection = vec![rim.clone(), other.clone()]; + h.app.start("solid.fillet"); + h.frames(3); + if let Some(Kind::Fillet { chain, .. }) = h.app.dialog.as_mut().map(|d| &mut d.kind) { + *chain = true; + } + h.frames(2); + let items = |h: &crate::scenario::Harness| h.app.dialog.as_ref().map(|d| d.inputs[0].items.clone()).unwrap_or_default(); + let has = |h: &crate::scenario::Harness, x: &Sel| items(h).iter().any(|y| crate::selection::same_item(x, y)); + assert!(items(&h).len() > 4 && has(&h, &rim) && has(&h, &other), "the rim's chain and the bottom loop's: {:?}", items(&h)); + // A row of the rim's chain that is not the rim edge picked by hand. + let row = { + let d = h.app.dialog.as_ref().unwrap(); + let rows = d.listed_items(&h.app.session, 0); + rows.iter() + .position(|x| { + let Sel::Edge { point, .. } = x else { return false }; + (point.z - 20.0).abs() < 1e-6 && !crate::selection::same_item(x, &rim) + }) + .expect("a chain row on the rim") + }; + let label = open_list(&mut h, 0); + h.step(&json!({"click": {"handle": format!("dialog:list:{label}:{row}:remove")}})).unwrap(); + h.frames(2); + let on_rim = + |h: &crate::scenario::Harness| items(h).iter().filter(|x| matches!(x, Sel::Edge { point, .. } if (point.z - 20.0).abs() < 1e-6)).count(); + assert_eq!(on_rim(&h), 0, "the rim's whole chain went: {:?}", items(&h)); + assert!(has(&h, &other), "the other pick's chain stays"); + for on in [false, true] { + if let Some(Kind::Fillet { chain, .. }) = h.app.dialog.as_mut().map(|d| &mut d.kind) { + *chain = on; + } + h.frames(2); + assert_eq!(on_rim(&h), 0, "Tangent Chain {on} does not bring the rim back: {:?}", items(&h)); + } +} + +/// Open input `i`'s list of picked items in the open dialog (#3683). +fn open_list(h: &mut crate::scenario::Harness, i: usize) -> &'static str { + let label = h.app.dialog.as_ref().unwrap().inputs[i].label; + h.step(&json!({"click": {"handle": format!("dialog:list_toggle:{label}")}})).unwrap(); + h.frames(2); + label +} + +/// Move the pointer to a published handle of the dialog. +fn hover_handle(h: &mut crate::scenario::Harness, handle: &str) { + let p = crate::scenario::handle_at(handle).unwrap_or_else(|| panic!("no {handle}")); + h.call("ui.move", json!({"x": p.x, "y": p.y})); + h.frames(2); +} + +/// #3683: hovering a picked item's row, or its remove button, lights that item in the view as +/// hovering it there does (and not as picked); leaving the row puts the view back. +#[test] +fn hovering_a_picked_row_lights_that_item_in_the_view() { + let mut h = crate::scenario::Harness::new(); + h.app.run("solid.box", json!({"length": 40, "width": 30, "height": 20})).unwrap(); + h.frames(2); + let picks = [Vec3::new(20.0, 0.0, 20.0), Vec3::new(40.0, 15.0, 20.0)].map(|p| crate::dialogs::edge_sel(&h.app.session, p).unwrap()); + h.app.session.selection = picks.to_vec(); + h.app.start("solid.fillet"); + h.frames(3); + let label = open_list(&mut h, 0); + let lit = |h: &crate::scenario::Harness| h.app.dialog.as_ref().unwrap().list_hover.clone(); + for handle in [format!("dialog:list:{label}:1"), format!("dialog:list:{label}:1:remove")] { + let at = crate::scenario::rect_of(&handle).map(|r| r.left_center() + egui::vec2(8.0, 0.0)); + let p = at.or_else(|| crate::scenario::handle_at(&handle)).unwrap(); + h.call("ui.move", json!({"x": p.x, "y": p.y})); + h.frames(2); + let Sel::Edge { body, index, point } = &picks[1] else { panic!("{:?}", picks[1]) }; + assert_eq!(lit(&h), Some((0, picks[1].clone())), "{handle}"); + assert_eq!( + h.app.viewport.hover, + Some(crate::viewport::Hit::Edge { body: body.clone(), index: *index, mid: *point, point: *point }), + "{handle}" + ); + // Lit as a hover: the picked shading gives way to the hover colour on that edge, which a + // hover in the view leaves as picked. + let lines = |h: &crate::scenario::Harness| crate::viewport::build_highlight(&h.app).merged().lines; + let hl = lines(&h); + h.app.dialog.as_mut().unwrap().list_hover = None; + let picked = lines(&h); + h.app.dialog.as_mut().unwrap().list_hover = Some((0, picks[1].clone())); + assert_ne!(hl, picked, "{handle}: the row's edge is drawn as hovered"); + } + // Off the rows: nothing in the dialog's list is lit any more. + let chip = crate::scenario::handle_at(&format!("dialog:clear:{label}")).unwrap(); + h.call("ui.move", json!({"x": chip.x - 60.0, "y": chip.y})); + h.frames(2); + assert_eq!(lit(&h), None); + assert_eq!(h.app.viewport.hover, None); +} + +/// #3683: a body or feature row lights what the Browser and timeline rows light: the body, or +/// the feature's geometry; leaving it puts the view back. +#[test] +fn hovering_a_body_or_feature_row_lights_it_as_the_browser_does() { + let lit = |h: &crate::scenario::Harness| crate::viewport::build_highlight(&h.app).merged().tris; + let mut h = crate::scenario::Harness::new(); + for (name, x) in [("Block", 0), ("Cutter", 10), ("Other", 20)] { + h.app.run("solid.box", json!({"corner": [x, x, x], "length": 20, "width": 20, "height": 20, "body_name": name})).unwrap(); + } + h.app.session.selection.clear(); + h.app.start("solid.combine"); + h.frames(2); + let d = h.app.dialog.as_mut().unwrap(); + d.inputs[0].items = vec![Sel::Body { name: "Block".into() }]; + d.inputs[1].items = vec![Sel::Body { name: "Cutter".into() }, Sel::Body { name: "Other".into() }]; + h.frames(2); + let label = open_list(&mut h, 1); + let unlit = lit(&h); + hover_handle(&mut h, &format!("dialog:list:{label}:1:remove")); + assert_eq!(h.app.dialog.as_ref().unwrap().list_hover, Some((1, Sel::Body { name: "Other".into() }))); + assert_ne!(lit(&h), unlit, "the body lights up"); + hover_handle(&mut h, &format!("dialog:clear:{label}")); + assert_eq!(h.app.dialog.as_ref().unwrap().list_hover, None); + assert_eq!(lit(&h), unlit); + + let mut h = crate::scenario::Harness::new(); + h.app.run("solid.box", json!({"length": 60, "width": 40, "height": 10})).unwrap(); + h.app.run("solid.hole", json!({"position": [10, 10, 10], "diameter": 5})).unwrap(); + h.app.run("solid.hole", json!({"position": [30, 10, 10], "diameter": 5})).unwrap(); + let holes: Vec = h.app.session.doc.features.iter().rev().take(2).map(|f| f.id).collect(); + h.app.session.selection = holes.iter().rev().map(|&id| Sel::Feature { id }).collect(); + h.app.start("solid.pattern.rectangular"); + h.frames(3); + let label = open_list(&mut h, 0); + let unlit = lit(&h); + hover_handle(&mut h, &format!("dialog:list:{label}:1:remove")); + assert_eq!(h.app.dialog.as_ref().unwrap().list_hover, Some((0, Sel::Feature { id: holes[0] })), "the second hole"); + assert_ne!(lit(&h), unlit, "the hole's faces light up"); +} + +/// #3683: removing a row of any multi-pick field changes what the dialog makes, and its +/// preview, exactly as taking that item out of the field does: Combine's tool bodies, a Loft's +/// rails, Sweep's path, Blend Surface's To edges, a rigid group's components and a pattern's +/// features. +#[test] +fn removing_a_row_updates_the_preview_of_every_multi_pick_field() { + #[allow(clippy::type_complexity)] + let cases: Vec<(&str, Box, usize)> = vec![ + ( + "solid.combine", + Box::new(|h| { + for (name, x) in [("Block", 0), ("Cutter", 10), ("Other", 20)] { + h.app.run("solid.box", json!({"corner": [x, x, x], "length": 20, "width": 20, "height": 20, "body_name": name})).unwrap(); + } + h.app.session.selection.clear(); + h.app.start("solid.combine"); + let d = h.app.dialog.as_mut().unwrap(); + d.inputs[0].items = vec![Sel::Body { name: "Block".into() }]; + d.inputs[1].items = vec![Sel::Body { name: "Cutter".into() }, Sel::Body { name: "Other".into() }]; + }), + 1, + ), + ( + "solid.loft", + Box::new(|h| { + for (name, z) in [("Base", 0), ("Top", 40)] { + h.app + .run("sketch.create", json!({"name": name, "plane": {"origin": [0, 0, z], "x_dir": [1, 0, 0], "y_dir": [0, 1, 0]}})) + .unwrap(); + h.app.run("sketch.circle.center", json!({"center": [0, 0], "radius": 10})).unwrap(); + h.app.run("sketch.finish", json!({})).unwrap(); + } + h.app.run("sketch.create", json!({"plane": "XZ", "name": "R"})).unwrap(); + h.app.run("sketch.arc.three_point", json!({"start": [10, 0], "end": [10, -40], "through": [15, -20], "id": "out"})).unwrap(); + h.app.run("sketch.arc.three_point", json!({"start": [-10, 0], "end": [-10, -40], "through": [-15, -20], "id": "back"})).unwrap(); + h.app.run("sketch.finish", json!({})).unwrap(); + let id = |h: &crate::scenario::Harness, n: &str| h.app.session.doc.find_feature(n).unwrap().id; + let (base, top, rails) = (id(h, "Base"), id(h, "Top"), id(h, "R")); + h.app.start("solid.loft"); + let d = h.app.dialog.as_mut().unwrap(); + d.inputs[0].items = vec![Sel::Profile { sketch: base, index: 0 }, Sel::Profile { sketch: top, index: 0 }]; + d.inputs[1].items = ["out", "back"].map(|c| Sel::SketchCurve { id: c.into(), sketch: Some(rails) }).to_vec(); + }), + 1, + ), + ( + "solid.sweep", + Box::new(|h| { + h.app.run("sketch.create", json!({"plane": "XY", "name": "P"})).unwrap(); + h.app.run("sketch.circle.center", json!({"center": [0, 0], "radius": 2})).unwrap(); + h.app.run("sketch.finish", json!({})).unwrap(); + h.app.run("sketch.create", json!({"plane": "XZ", "name": "Path"})).unwrap(); + h.app.run("sketch.line", json!({"points": [[0, 0], [0, -20], [10, -30]], "ids": ["up", "over"]})).unwrap(); + h.app.run("sketch.finish", json!({})).unwrap(); + let id = |h: &crate::scenario::Harness, n: &str| h.app.session.doc.find_feature(n).unwrap().id; + let (profile, path) = (id(h, "P"), id(h, "Path")); + h.app.session.selection.clear(); + h.app.start("solid.sweep"); + let d = h.app.dialog.as_mut().unwrap(); + d.inputs[0].items = vec![Sel::Profile { sketch: profile, index: 0 }]; + d.inputs[1].items = ["up", "over"].map(|c| Sel::SketchCurve { id: c.into(), sketch: Some(path) }).to_vec(); + }), + 1, + ), + ( + "surface.blend", + Box::new(|h| { + h.app.run("solid.box", json!({"length": 40, "width": 10, "height": 10, "corner": [0, 0, 0], "body_name": "A"})).unwrap(); + h.app.run("solid.box", json!({"length": 40, "width": 10, "height": 10, "corner": [0, 20, 5], "body_name": "B"})).unwrap(); + let e = |h: &crate::scenario::Harness, p: Vec3| crate::dialogs::edge_sel(&h.app.session, p).unwrap(); + let (from, to, to2) = (e(h, Vec3::new(20.0, 10.0, 10.0)), e(h, Vec3::new(20.0, 20.0, 15.0)), e(h, Vec3::new(20.0, 20.0, 5.0))); + h.app.session.selection.clear(); + h.app.start("surface.blend"); + let d = h.app.dialog.as_mut().unwrap(); + d.inputs[0].items = vec![from]; + d.inputs[1].items = vec![to, to2]; + }), + 1, + ), + ( + "joint.rigid_group", + Box::new(|h| { + let s = &mut h.app.session; + crate::test_support::grounded_boxes(&[("A", 0), ("B", 30), ("C", 60)], |id, p| s.execute(id, &p).unwrap()); + h.app.session.selection = ["Body1", "Body2", "Body3"].map(|name| Sel::Body { name: name.into() }).to_vec(); + h.app.start("joint.rigid_group"); + }), + 0, + ), + ( + "solid.pattern.rectangular", + Box::new(|h| { + h.app.run("solid.box", json!({"length": 60, "width": 40, "height": 10})).unwrap(); + h.app.run("solid.hole", json!({"position": [10, 10, 10], "diameter": 5})).unwrap(); + h.app.run("solid.hole", json!({"position": [30, 10, 10], "diameter": 5})).unwrap(); + h.app.session.selection = h.app.session.doc.features.iter().rev().take(2).map(|f| Sel::Feature { id: f.id }).collect(); + h.app.start("solid.pattern.rectangular"); + h.app.dialog.as_mut().unwrap().inputs[1].items = vec![Sel::Axis { name: "X".into() }]; + }), + 0, + ), + ]; + for (command, setup, input) in cases { + let mut h = crate::scenario::Harness::new(); + setup(&mut h); + h.frames(3); + let d = h.app.dialog.clone().unwrap_or_else(|| panic!("{command}: no dialog")); + let before = crate::dialogs::preview_commands(&h.app, &d); + assert!(before.as_ref().is_ok_and(|c| !c.is_empty()), "{command}: {before:?} {:?}", d.inputs); + let mut want = d.clone(); + let gone = want.inputs[input].items.remove(0); + let want = crate::dialogs::preview_commands(&h.app, &want); + assert_ne!(before, want, "{command}: the first item counts"); + + let label = open_list(&mut h, input); + h.step(&json!({"click": {"handle": format!("dialog:list:{label}:0:remove")}})).unwrap(); + h.frames(2); + let d = h.app.dialog.as_ref().unwrap(); + assert!(!d.inputs[input].items.iter().any(|x| crate::selection::same_item(x, &gone)), "{command}: {:?}", d.inputs[input].items); + assert_eq!(crate::dialogs::preview_commands(&h.app, d), want, "{command}"); + } +} + +/// #3683: with Tangent Chain on, Shell's list shows every face it opens, as its chip counts +/// them; removing a face the chain brought takes out the pick whose chain holds it. +#[test] +fn shell_lists_the_faces_its_chip_counts() { + let mut h = crate::scenario::Harness::new(); + h.app.run("solid.box", json!({"length":40,"width":30,"height":20})).unwrap(); + h.app.run("solid.fillet", json!({"edges":[[20,0,20]],"radius":4})).unwrap(); + let top = face(&h.app, Vec3::new(20.0, 17.0, 20.0)); + let back = face(&h.app, Vec3::new(20.0, 30.0, 10.0)); + start(&mut h.app, vec![top.clone(), back.clone()], "solid.shell"); + h.frames(3); + assert!(h.widget("4 selected").is_some(), "the top's chain of three and the back"); + let label = open_list(&mut h, 0); + let rows = (0..8).take_while(|i| crate::scenario::handle_at(&format!("dialog:list:{label}:{i}:remove")).is_some()).count(); + assert_eq!(rows, 4, "a row for each face the chip counts"); + let d = h.app.dialog.as_ref().unwrap(); + let listed = d.listed_items(&h.app.session, 0); + let round = listed.iter().position(|x| !crate::selection::same_item(x, &top) && !crate::selection::same_item(x, &back)).unwrap(); + h.step(&json!({"click": {"handle": format!("dialog:list:{label}:{round}:remove")}})).unwrap(); + h.frames(2); + assert_eq!(h.app.dialog.as_ref().unwrap().inputs[0].items, vec![back]); + assert!(h.widget("1 selected").is_some()); +} diff --git a/crates/ui-egui/src/ui_kit/layout.rs b/crates/ui-egui/src/ui_kit/layout.rs index 6413ca478..11d136acf 100644 --- a/crates/ui-egui/src/ui_kit/layout.rs +++ b/crates/ui-egui/src/ui_kit/layout.rs @@ -701,19 +701,20 @@ pub(crate) fn search_fold(ui: &mut Ui, title: &str, count: usize, add: impl F }) } -/// Picked-item list entry with a remove action. Returns that action's Response. +/// Picked-item list entry with a remove action. Returns that action's Response, hovered while +/// the pointer is anywhere on the row (its item lights up in the view, #3683). /// Tokens: control_height, space_8, font_label, text and icon-button tokens. /// Picked-item row with a remove action. Tokens: `control_height, space_8, font_label, text; icon-button tokens`. pub(crate) fn list_row(ui: &mut Ui, key: &str, text: &str) -> Response { let t = Tokens::get(); - let (rect, _) = ui.allocate_exact_size(vec2(dimension(ui.available_width()), row_height()), egui::Sense::hover()); + let (rect, row) = ui.allocate_exact_size(vec2(dimension(ui.available_width()), row_height()), egui::Sense::hover()); let remove = egui::Rect::from_min_max(egui::pos2((rect.right() - row_height()).max(rect.left()), rect.top()), rect.max); let label = egui::Rect::from_min_max(rect.min, egui::pos2((remove.left() - t.space_8).max(rect.left()), rect.bottom())); paint_text(ui, label, text, egui::FontId::proportional(t.font_label), t.form_ink, false); let response = ui.push_id(key, |ui| super::icon_button_at(ui, remove, "close", "Remove")).inner; scenario::publish_rect(&format!("dialog:list:{key}"), rect); scenario::publish_handle(&format!("dialog:list:{key}:remove"), remove.center()); - response + response.union(row) } /// Full-width rule; Tokens: dialog_rule. Use between groups without extra padding. diff --git a/crates/ui-egui/src/viewport.rs b/crates/ui-egui/src/viewport.rs index bdfc587af..0d8917d62 100644 --- a/crates/ui-egui/src/viewport.rs +++ b/crates/ui-egui/src/viewport.rs @@ -3221,6 +3221,61 @@ pub fn hit_sel(h: &Hit) -> Option { }) } +/// The item as a hit: what lights up when it is hovered. `None` for bodies, features and +/// components, which light up whole instead, and for constraints. +pub(crate) fn sel_hit(app: &SolveApp, sel: &Sel) -> Option { + let st = app.session.world_state().ok()?; + let active = app.session.active_sketch; + let point = |sketch: u64, id: &str| { + let sk = &st.sketch(sketch)?.sketch; + sk.resolve_point(id).and_then(|i| sk.point(i)) + }; + let curve = |sketch: u64, id: &str| { + let ss = st.sketch(sketch)?; + let sk = &ss.sketch; + let c = sk.curves.get(sk.curve_index(id)?)?; + // Its start is where an orbit from the hover would turn about. + let point = c.kind.ends().and_then(|(a, _)| sk.point(a)).map_or(Vec3::ZERO, |at| ss.plane.to_world(at)); + Some(Hit::SketchCurve { sketch, id: id.to_string(), straight: matches!(c.kind, CurveKind::Line { .. }), point }) + }; + Some(match sel { + Sel::Edge { body, index, point } => Hit::Edge { body: body.clone(), index: *index, mid: *point, point: *point }, + Sel::Face { body, index, point } => Hit::Face { body: body.clone(), index: *index, point: *point }, + Sel::Vertex { body, point } => Hit::Vertex { body: body.clone(), point: *point }, + Sel::Profile { sketch, index } => Hit::Profile { sketch: *sketch, index: *index }, + Sel::Plane { name } => Hit::Plane { name: name.clone(), point: Vec3::ZERO }, + Sel::Axis { name } => Hit::Axis { name: name.clone() }, + Sel::ConstructionPoint { name } => Hit::ConstructionPoint { name: name.clone() }, + Sel::SketchCurve { id, sketch } => curve((*sketch).or(active)?, id)?, + Sel::ExternalSketchCurve { sketch, id } => curve(*sketch, id)?, + Sel::ExternalSketchPoint { sketch, id } => Hit::SketchPoint { sketch: *sketch, id: id.clone(), at: point(*sketch, id)? }, + // A point of another sketch is picked as `sketch:id`. + Sel::SketchPoint { id } => { + let (sketch, id) = match id.split_once(':').and_then(|(s, p)| Some((s.parse().ok()?, p))) { + Some(other) => other, + None => (active?, id.as_str()), + }; + Hit::SketchPoint { sketch, id: id.to_string(), at: point(sketch, id)? } + } + Sel::SketchMidpoint { id } => { + let sketch = active?; + let sk = &st.sketch(sketch)?.sketch; + let at = crate::selection::line_midpoint(sk, sk.curve_index(id)?)?; + Hit::SketchMidpoint { sketch, id: id.clone(), at } + } + Sel::Body { .. } | Sel::Feature { .. } | Sel::Occurrence { .. } | Sel::SketchConstraint { .. } => return None, + }) +} + +/// A dialog's picked-items row under the pointer (#3683) is the hover, as the item would be +/// under the pointer in the view. Bodies, components and features light up as their Browser +/// and timeline rows do instead (`build_highlight`). +fn list_hover(app: &mut SolveApp) { + if let Some((_, item)) = app.dialog.as_ref().and_then(|d| d.list_hover.as_ref()) { + app.viewport.hover = sel_hit(app, item); + } +} + /// What lights up under the pointer while a tool runs: the nearest hit its click takes. fn tool_hover(app: &SolveApp, hits: &[Hit]) -> Option { let cmd = app.tool.as_ref()?.cmd; @@ -3575,6 +3630,7 @@ fn highlight_geometry_key(app: &SolveApp) -> u64 { app.viewport.hover_feature.hash(&mut h); app.viewport.hover_bodies.hash(&mut h); app.viewport.hover_plane.hash(&mut h); + app.dialog.as_ref().and_then(|d| d.list_hover.as_ref()).map(|(_, item)| format!("{item:?}")).hash(&mut h); // Which mesh lights a face follows how the model draws its body (see `shown_mesh`), and at // which display quality its plan and edges are made. solidcraft_engine::doc::display_quality::current().hash(&mut h); @@ -3877,6 +3933,11 @@ pub(crate) fn build_highlight(app: &SolveApp) -> GpuScene { } } } + // A picked item whose dialog row is under the pointer shows as hovered, not as picked. + if let Some((_, item)) = app.dialog.as_ref().and_then(|d| d.list_hover.as_ref()) { + let lit = displayed_selection(app, item); + sel.retain(|x| !lit.iter().any(|y| crate::selection::same_item(x, y))); + } // Component hover expands through the same occurrence selection as a Browser row. let component_hover = crate::render_workspace::assign::hover(app).map(|sel| displayed_selection(app, sel)).or_else(|| { app.viewport @@ -4144,6 +4205,11 @@ pub(crate) fn build_highlight(app: &SolveApp) -> GpuScene { hovered.extend(component_hover.into_iter().flatten()); let body_hover = hovered_body(app); hovered.extend(body_hover.iter().map(|name| Sel::Body { name: name.clone() })); + if let Some((_, item @ (Sel::Body { .. } | Sel::Occurrence { .. } | Sel::Feature { .. }))) = + app.dialog.as_ref().and_then(|d| d.list_hover.as_ref()) + { + hovered.extend(displayed_selection(app, item)); + } // By name, once: a whole assembly holds thousands of bodies, and scanning the list for // each of them is quadratic (as is a body lookup by name in the world). let hovered_whole: std::collections::HashSet<&str> = @@ -4497,6 +4563,7 @@ pub fn show(app: &mut SolveApp, ui: &mut egui::Ui) { let navigating_from_press = mode.is_some() || app.viewport.primary_nav.is_some() || joint_handle_pointer; let held = crate::select_other::track_hold(app, ui.ctx(), &proj, inside, primary_pressed, primary_down, hover, navigating_from_press); crate::select_other::hover_override(app); + list_hover(app); let painter = ui.painter_at(rect); crate::gpu::paint_background(&painter, rect, &t);