SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Browser: a click just past a feature's name selects it instead of opening its sketch (#10079) (#10213)
kaltenbrunnermarkus05f30c167403
diff --git a/crates/ui-egui/src/browser/features.rs b/crates/ui-egui/src/browser/features.rsindex a4d269c769..145bf4316c 100644--- a/crates/ui-egui/src/browser/features.rs+++ b/crates/ui-egui/src/browser/features.rs@@ -826,6 +826,58 @@ mod tests {assert!(labels.contains(&block_name), "a rolled-back feature stays listed: {labels:?}");}+ /// #10079: three extrusions of one visible sketch, the first renamed. A click just past the end+ /// of a feature's name, or a press on the name that slips a few points before its release,+ /// selects the feature; only the sketch button itself opens the sketch.+ #[test]+ fn clicking_just_past_a_feature_name_selects_it_without_opening_its_sketch() {+ let mut h = Harness::new();+ let sketch = h.app.run("sketch.create", json!({"plane":"XY","name":"Sketch1"})).unwrap()["sketch"].as_u64().unwrap();+ for (p0, p1) in [([0, 0], [10, 10]), ([20, 0], [30, 10]), ([40, 0], [50, 10])] {+ h.app.run("sketch.rectangle.two_point", json!({"p0":p0,"p1":p1})).unwrap();+ }+ h.app.run("sketch.finish", json!({})).unwrap();+ let mut ids = Vec::new();+ for profile in 0..3 {+ let made = h.app.run("solid.extrude", json!({"sketch":sketch,"profiles":[profile],"distance":5})).unwrap();+ ids.push(made["feature"].as_u64().unwrap());+ if profile == 0 {+ h.app.run("timeline.rename", json!({"feature":ids[0],"name":"Lid"})).unwrap();+ }+ }+ // The sketch stays shown, as in the report.+ crate::browser::set_sketch_visible(&mut h.app, sketch, true);+ h.app.tree.expanded.insert("c0/features".into());+ h.settle();+ assert!(crate::browser::sketch_visible(&h.app, sketch));+ let press = |h: &mut Harness, at: Pos2, pressed: bool| {+ h.frame_with(vec![egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() }]);+ };+ // A press at `from` released at `to`, then long enough that the next click is not a double.+ let click = |h: &mut Harness, from: Pos2, to: Pos2| {+ h.frame_with(vec![egui::Event::PointerMoved(from)]);+ press(h, from, true);+ h.frame_with(vec![egui::Event::PointerMoved(to)]);+ press(h, to, false);+ h.frames(30);+ };+ for (round, id) in ids.iter().chain(&ids).enumerate() {+ let name = h.app.session.doc.feature(*id).unwrap().name.clone();+ for (from, to) in [(1.0, 1.0), (5.0, 5.0), (-2.0, 4.0)] {+ // Selected rows draw their name in semibold, wider: measure it each time.+ let label = crate::scenario::rect_of(&format!("row_label:{name}")).unwrap();+ let at = |dx: f32| pos2(label.right() + dx, label.center().y);+ click(&mut h, at(from), at(to));+ assert_eq!(h.app.session.active_sketch, None, "round {round}: {name} clicked {from}..{to} points past its name opened the sketch");+ assert!(h.app.dialog.is_none(), "round {round}: {name} opened a dialog");+ assert_eq!(h.app.session.selection, [Sel::Feature { id: *id }], "round {round}: {name} {from}..{to}");+ }+ }+ h.step(&json!({"click": {"handle": "action:Extrude1"}})).unwrap();+ h.frames(2);+ assert_eq!(h.app.session.active_sketch, Some(sketch), "the sketch button still opens the sketch");+ }+fn settle_heavy(h: &mut Harness) {for _ in 0..500 {if h.app.deferred.is_none() && h.app.deferred_queue.is_empty() {diff --git a/crates/ui-egui/src/ui_kit/tree.rs b/crates/ui-egui/src/ui_kit/tree.rsindex 781d499ba1..76af5eee42 100644--- a/crates/ui-egui/src/ui_kit/tree.rs+++ b/crates/ui-egui/src/ui_kit/tree.rs@@ -225,7 +225,8 @@ pub(crate) fn tree_row(ui: &mut egui::Ui, id: egui::Id, row: &Row) -> RowResp {let radio_x = x + 14.0 + slot + 6.0;let radio_r = Rect::from_center_size(pos2(radio_x, cy), vec2(t.space_12 + t.space_3, r.height()));// The button right after the name takes room from the label; it is placed once the label is laid out.- let name_action_width = if row.action.is_some() { 22.0 } else { 0.0 };+ let (name_action_gap, name_action_size) = (t.space_8, t.space_16 + t.space_4);+ let name_action_width = if row.action.is_some() { name_action_gap + name_action_size } else { 0.0 };let at = |p: Pos2| -> u8 {if !row.actions.is_empty() && p.x >= action_left {4@@ -380,7 +381,10 @@ pub(crate) fn tree_row(ui: &mut egui::Ui, id: egui::Id, row: &Row) -> RowResp {bx += 15.0;}// The name's action button sits right after the label; a press on it is not a press on the row.- let action_r = Rect::from_min_size(pos2(x + lw + 2.0, r.top()), vec2(t.space_16 + t.space_4, r.height()));+ // The gap before it belongs to the row: a click that lands just past the end of the name, or+ // a press on the name that slips a few points before its release, selects the row instead of+ // opening the feature's sketch (#10079). The gap is wider than egui's click slop (6 points).+ let action_r = Rect::from_min_size(pos2(x + lw + name_action_gap, r.top()), vec2(name_action_size, r.height()));let over_action = |p: Option<Pos2>| row.action.is_some() && p.is_some_and(|p| action_r.contains(p));let action_hover = over_action(resp.hover_pos());let action_click = over_action(resp.interact_pointer_pos());