From e77c55549f96e806ca206945efb5f4afcf61cd14 Mon Sep 17 00:00:00 2001 From: Dahak Builds Date: Sun, 1 Nov 2026 13:31:14 +0000 Subject: [PATCH] Sketch: a value box must not swallow a click on the reference line's endpoint (#10600) (#10639) * claim: #10600 * Sketch: a value box must not swallow a click that lands on a sketch point (#10600) The construction line tools' Length box waits beside the pointer. When the pointer reaches the reference line's own endpoint it can land under that box (the box is anchored to the tool hover, which freezes while the pointer rests on the box), and the box's text edit takes the click, so the tool never sees it. A release over the tool's own value box or construction/normal switch that lands on a snapped sketch point now goes to the tool; a click on the box away from any sketch point still edits the box. --------- Co-authored-by: Dahak Builds --- .../ui-egui/src/sketch_construction_tests.rs | 22 +++++++++++++++++++ crates/ui-egui/src/sketch_dims.rs | 9 ++++++++ crates/ui-egui/src/viewport.rs | 19 ++++++++++++++++ 3 files changed, 50 insertions(+) diff --git a/crates/ui-egui/src/sketch_construction_tests.rs b/crates/ui-egui/src/sketch_construction_tests.rs index 404a500e2..8154f61c1 100644 --- a/crates/ui-egui/src/sketch_construction_tests.rs +++ b/crates/ui-egui/src/sketch_construction_tests.rs @@ -269,3 +269,25 @@ fn the_normal_switch_needs_a_length_and_draws_a_normal_line() { let curve = sk.curves.last().unwrap(); assert!(curve.construction && curve.infinite, "{curve:?}"); } + +#[test] +fn perpendicular_click_on_reference_endpoint_places_line() { + // #10600: after picking the reference line, a click exactly on that line's own endpoint + // must reach the tool and place the perpendicular through the endpoint. The Length box + // waits beside the pointer there, and its click must not swallow the endpoint's. + let mut h = sketch(); + let sid = h.app.session.active_sketch.unwrap(); + let before = h.app.session.doc.sketch(sid).unwrap().curves.len(); + steps(&mut h, "sketch.construction_line.perpendicular", &[[10., 0.], [20., 0.]]); + let sk = h.app.session.doc.sketch(sid).unwrap(); + assert_eq!(sk.curves.len(), before + 1, "endpoint click swallowed: tool={:?} status={:?}", h.app.tool, h.app.status); + let curve = sk.curves.last().unwrap(); + assert!(curve.infinite && curve.construction, "{curve:?}"); + let CurveKind::Line { a, b } = curve.kind else { panic!("a line") }; + let (p, q) = (sk.point(a).unwrap(), sk.point(b).unwrap()); + let d = q - p; + let end = sk.resolve_point("a.end").and_then(|i| sk.point(i)).unwrap(); + // Through a.end (20, 0) and perpendicular to a, which runs along the sketch x axis. + assert!((end - p).x.abs() < 1e-6, "not through a.end: {p:?} {q:?}"); + assert!(d.x.abs() < 1e-6, "not perpendicular to a: {d:?}"); +} diff --git a/crates/ui-egui/src/sketch_dims.rs b/crates/ui-egui/src/sketch_dims.rs index a846e5014..bd549c233 100644 --- a/crates/ui-egui/src/sketch_dims.rs +++ b/crates/ui-egui/src/sketch_dims.rs @@ -718,6 +718,15 @@ fn polygon_input_positions(bounds: egui::Rect, sizes: &[egui::Vec2], view: Optio /// About the size of a value box, for keeping it in view. pub(crate) const BOX: egui::Vec2 = egui::vec2(76.0, 24.0); +/// Whether `p` is over the active tool's own floating boxes: a value box or the construction +/// line's construction/normal switch. #10600: these must not swallow a click that lands on a +/// sketch point, so the viewport asks before letting one take the click. +pub(crate) fn over_tool_boxes(app: &SolveApp, ctx: &egui::Context, p: egui::Pos2) -> bool { + let Some(t) = app.tool.as_ref() else { return false }; + (0..t.dims.len()).any(|i| ctx.memory(|m| m.area_rect(egui::Id::new(("sc_dim_area", i)))).is_some_and(|r| r.contains(p))) + || ctx.memory(|m| m.area_rect(egui::Id::new("sc_construction_switch"))).is_some_and(|r| r.contains(p)) +} + /// Where a value box whose top left would be `pos` goes so it stays in the drawing area `view`: /// as it is when it fits; else mirrored through the pointer (a box set off the cursor, past the /// view's edge, goes to the cursor's other side, still clear of it, #2201); else pushed inside. diff --git a/crates/ui-egui/src/viewport.rs b/crates/ui-egui/src/viewport.rs index 95a77fa87..b33f196da 100644 --- a/crates/ui-egui/src/viewport.rs +++ b/crates/ui-egui/src/viewport.rs @@ -4546,6 +4546,25 @@ pub fn show(app: &mut SolveApp, ui: &mut egui::Ui) { && app.viewport.draw_drag.is_none(); let resting = hover.filter(|p| free_pointer && rect.contains(*p) && !axes.contains(*p) && !crate::shell::covered(app, *p)); crate::sketch_line_arc::follow_pointer(app, ui.ctx(), &proj, resting); + // #10600: a running tool's own floating value box (or its construction/normal switch) must + // not swallow a click that lands on a sketch point: the click places the point there, and + // the box keeps the keyboard for typed values. A click on the box away from any sketch point + // still edits the box. The box is anchored to the tool's hover, which freezes while the + // pointer rests on the box, so a point the pointer reaches from the box's side can sit under + // it; the snap identifies the intended point even there. + if !inside + && app.tool.is_some() + && !held + && primary_nav.is_none() + && mode.is_none() + && ui.input(|i| i.pointer.button_released(egui::PointerButton::Primary)) + && let Some(p) = hover.filter(|p| rect.contains(*p)) + && crate::sketch_dims::over_tool_boxes(app, ui.ctx(), p) + && sketch_point_at(app, &proj, p).is_some_and(|(_, id)| id.is_some()) + { + crate::tools::on_hover(app, &proj, p, mods.shift); + crate::tools::on_click(app, &proj, p, mods.shift); + } if let Some(p) = hover.filter(|_| inside) { if app.tool.is_some() { crate::tools::on_hover(app, &proj, p, mods.shift);