From 2396b6be057984d724f7ffca515a0c68d3843ff8 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 4 Nov 2026 21:55:30 +0000 Subject: [PATCH] Hole: the drag handle looks like the Rest, Boss and Snap Fit handles (#6818) (#6819) * claim: #6818 Co-Authored-By: Claude Fable 5.1 * Hole: the handle drawn with the shared marker (#6818) A Single hole's drag handle (Move holes by clicking or dragging) is drawn with the placement marker from place_gizmo/look.rs instead of its own ring and cross, so a hole and a Rest on the same model show one language for the same action. place_gizmo::marker is the one crate-visible door: it runs the marker's hover and drag motions under the handle's id and draws the crosshair, never dimmed. Hole keeps its snapping, the click that takes a hole out, its handle names and its hover text. Co-Authored-By: Claude Fable 5.1 * Hole: hole_handle removed (#6818) The shared marker draws the handle now; nothing else used it. Co-Authored-By: Claude Fable 5.1 * Hole: the marker takes no colours it does not use (#6818) place_gizmo::marker took a &Tokens only to hand it to crosshair, which reads its colours itself, so the hole's show fetched tokens nothing read. The argument and that fetch go. Co-Authored-By: Claude Opus 5.5 * Hole: a test sees the handle drawn as the shared marker (#6818) The hole tests found the handle by its published position, which the look does not change. This one reads what the frame paints round it: the white dot and four dashed arms at rest, no ring round the centre, arrowheads when pointed at, solid shafts while it drags. It fails with the old ring and cross back on the call line. Co-Authored-By: Claude Opus 5.5 * Place handles: marker hover eases in 120 ms, drag in 220 ms (Refs #6818) The marker answered the pointer in 220 ms and a drag in 360 ms, which felt slow on review. Both stay in look.rs as the one place a later preference can read them. Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Fable 5.1 --- assets/icons/ui/source/markers.rs | 11 ---- crates/ui-egui/src/hole_place.rs | 3 +- crates/ui-egui/src/hole_place_ui_tests.rs | 77 +++++++++++++++++++++++ crates/ui-egui/src/place_gizmo.rs | 13 ++++ crates/ui-egui/src/place_gizmo/look.rs | 4 +- 5 files changed, 93 insertions(+), 15 deletions(-) diff --git a/assets/icons/ui/source/markers.rs b/assets/icons/ui/source/markers.rs index c49869c76..2c932b28d 100644 --- a/assets/icons/ui/source/markers.rs +++ b/assets/icons/ui/source/markers.rs @@ -79,17 +79,6 @@ pub(crate) fn snap_hint(painter: &egui::Painter, c: Pos2, kind: SnapKind, col: C painter.circle_filled(c, 1.3, col); } -/// A placed hole's drag handle: a ring round the hole's centre with a cross through it, filled -/// while it is hovered or dragged. -pub(crate) fn hole_handle(painter: &egui::Painter, c: Pos2, col: Color32, hot: bool) { - let ic = Tokens::get().icons; - let r = 6.0; - painter.circle_filled(c, r + 3.5, ic.marker_halo); - painter.circle(c, r, if hot { col } else { col.gamma_multiply(0.35) }, Stroke::new(1.6, col)); - let ink = Stroke::new(1.3, if hot { ic.highlight } else { col }); - painter.line_segment([c - vec2(r + 3.0, 0.0), c + vec2(r + 3.0, 0.0)], ink); - painter.line_segment([c - vec2(0.0, r + 3.0), c + vec2(0.0, r + 3.0)], ink); -} pub(crate) fn glyph_icon(name: &str) -> Option<&'static str> { Some(match name { "Coincident" => "c_coincident", diff --git a/crates/ui-egui/src/hole_place.rs b/crates/ui-egui/src/hole_place.rs index ecdeae02b..d89a20b29 100644 --- a/crates/ui-egui/src/hole_place.rs +++ b/crates/ui-egui/src/hole_place.rs @@ -269,7 +269,6 @@ pub(crate) fn show(app: &mut SolveApp, ui: &mut egui::Ui, painter: &egui::Painte if !matches!(&d.kind, Kind::Hole { opts, .. } if !opts.multiple) || app.applying.is_some() { return; } - let t = Tokens::get(); marks(app, painter, proj); if !app.preferences.hole_moves { return; @@ -303,7 +302,7 @@ pub(crate) fn show(app: &mut SolveApp, ui: &mut egui::Ui, painter: &egui::Painte if hot { ui.ctx().set_cursor_icon(if r.dragged() { egui::CursorIcon::Grabbing } else { egui::CursorIcon::Grab }); } - crate::icons::markers::hole_handle(painter, c, if hot { t.accent } else { t.manipulator }, hot); + crate::place_gizmo::marker(ui, painter, id, c, r.hovered(), r.dragged()); crate::scenario::publish_handle(&format!("hole:{n}"), c); if !r.dragged() { r.backing_on_hover_text(crate::i18n::tr_label("Drag to move the hole; click to remove it")); diff --git a/crates/ui-egui/src/hole_place_ui_tests.rs b/crates/ui-egui/src/hole_place_ui_tests.rs index c6c2ca7a7..890728a3c 100644 --- a/crates/ui-egui/src/hole_place_ui_tests.rs +++ b/crates/ui-egui/src/hole_place_ui_tests.rs @@ -170,6 +170,83 @@ fn the_handle_drags_a_placed_hole_and_snaps() { assert!(position.dist(free) < 0.2, "{position:?}"); } +/// What the last frame painted in the handles' white core round `c`: the dot's radius, each +/// line's ends and each filled shape's farthest point, as distances from `c`, and how many +/// circles of any colour are centred there (the dot and its casing, nothing else). +struct Painted { + dots: Vec, + lines: Vec<(f32, f32)>, + tips: Vec, + circles: usize, +} + +fn painted(h: &Harness, c: egui::Pos2) -> Painted { + use egui::epaint::{ColorMode, Shape}; + let core = crate::theme::Tokens::get().icons.highlight; + let mut p = Painted { dots: Vec::new(), lines: Vec::new(), tips: Vec::new(), circles: 0 }; + for clipped in &h.shapes { + crate::test_support::each_shape(&clipped.shape, &mut |s| match s { + Shape::Circle(o) if o.center.distance(c) < 0.5 => { + p.circles += 1; + if o.fill == core { + p.dots.push(o.radius); + } + } + Shape::Path(path) if path.points.iter().all(|q| q.distance(c) < 30.0) => { + let far = path.points.iter().map(|q| q.distance(c)).fold(0.0, f32::max); + if path.closed && path.fill == core { + p.tips.push(far); + } else if !path.closed + && matches!(path.stroke.color, ColorMode::Solid(col) if col == core) + && let [a, b] = path.points.as_slice() + { + p.lines.push((a.distance(c), b.distance(c))); + } + } + _ => {} + }); + } + p +} + +#[test] +fn a_placed_hole_s_handle_is_the_shared_move_marker() { + // The move marker Rest, Boss and Snap Fit use (#6818): a white dot with four dashed arms at + // rest, arrowheads when pointed at, solid shafts while it drags; no ring round the centre. + let mut h = block(); + h.step(&json!({"start": "solid.hole"})).unwrap(); + let at = screen(&mut h, Vec3::new(30.0, 8.0, 20.0)); + h.step(&json!({"click": at})).unwrap(); + let away = off(&mut h, Vec3::new(30.0, 8.0, 20.0), 60.0, 40.0); + h.step(&json!({"move": away})).unwrap(); + h.frames(30); + let c = handle_at("hole:0").expect("the placed hole has a handle"); + let close = |got: &[f32], want: f32| got.len() == 4 && got.iter().all(|d| (d - want).abs() < 0.3); + let rest = painted(&h, c); + assert_eq!(rest.dots, vec![3.9], "one white dot"); + assert_eq!(rest.circles, 2, "the dot and its casing, no ring"); + let inner: Vec = rest.lines.iter().map(|l| l.1).collect(); + assert!(rest.lines.iter().all(|l| (l.0 - 6.0).abs() < 0.3) && close(&inner, 11.5), "four inner dashes: {:?}", rest.lines); + assert!(close(&rest.tips, 19.3), "four outer dashes: {:?}", rest.tips); + // Pointed at: the outer dashes grow into arrowheads. + h.step(&json!({"move": [c.x, c.y]})).unwrap(); + h.frames(30); + let hot = painted(&h, c); + assert!(close(&hot.tips, 22.5), "four arrowheads: {:?}", hot.tips); + assert_eq!(hot.circles, 2, "still no ring"); + // Dragged: the inner dashes run on into the heads. + h.frame_with(crate::test_support::pointer(c, true)); + for k in 1..=30 { + h.frame_with(vec![egui::Event::PointerMoved(c + egui::vec2(k as f32, 0.0))]); + } + let c = handle_at("hole:0").expect("the dragged hole keeps its handle"); + let drag = painted(&h, c); + let shafts: Vec = drag.lines.iter().map(|l| l.1).collect(); + assert!(close(&shafts, 13.8), "four solid shafts: {:?}", drag.lines); + assert!(close(&drag.tips, 22.5), "{:?}", drag.tips); + h.frame_with(crate::test_support::pointer(c, false)); +} + #[test] fn a_second_pick_on_the_face_moves_the_hole_and_a_pick_on_it_takes_it_out() { let mut h = block(); diff --git a/crates/ui-egui/src/place_gizmo.rs b/crates/ui-egui/src/place_gizmo.rs index e4535c9c1..3c3d5ea19 100644 --- a/crates/ui-egui/src/place_gizmo.rs +++ b/crates/ui-egui/src/place_gizmo.rs @@ -221,6 +221,19 @@ fn on_plane(proj: &Proj, pos: Pos2, base: Vec3, n: Vec3) -> Option { crate::gizmo::on_plane(proj, pos, base, n).filter(|p| p.is_finite()) } +/// The move marker alone, for a handle another module owns (a Single hole's, #6818): drawn as +/// [`show`] draws its own, from the handle's hovered and dragged state, so a hole and a Rest on +/// the same model show one language for the same action. `id` is the handle's; the motions keep +/// their state under it. Nothing to step back for, so it is never dimmed. +pub(crate) fn marker(ui: &egui::Ui, painter: &egui::Painter, id: egui::Id, c: Pos2, hovered: bool, dragging: bool) { + let style = CrossStyle { + hot: MARKER_HOT.run(ui.ctx(), id.with("hot"), hovered || dragging).t, + active: MARKER_ACTIVE.run(ui.ctx(), id.with("active"), dragging).t, + alpha: 1.0, + }; + crosshair(painter, c, &style, &Tokens::get()); +} + /// Draw the handles and take their drags (after the dialog's own arrow, so the marker wins /// the pointer near the base). pub(crate) fn show(app: &mut SolveApp, ui: &mut egui::Ui, painter: &egui::Painter, proj: &Proj, d: &mut Dialog) { diff --git a/crates/ui-egui/src/place_gizmo/look.rs b/crates/ui-egui/src/place_gizmo/look.rs index 6e836683e..7c9d90c8c 100644 --- a/crates/ui-egui/src/place_gizmo/look.rs +++ b/crates/ui-egui/src/place_gizmo/look.rs @@ -55,8 +55,8 @@ pub(super) const DIM: f32 = 0.25; pub(super) const DIM_S: f32 = 0.16; /// The marker answering the pointer arriving or leaving, and switching into and out of a drag. -pub(super) const MARKER_HOT: Transition = Transition::symmetric(0.22); -pub(super) const MARKER_ACTIVE: Transition = Transition::symmetric(0.36); +pub(super) const MARKER_HOT: Transition = Transition::symmetric(0.12); +pub(super) const MARKER_ACTIVE: Transition = Transition::symmetric(0.22); /// The marker's line width (a dash's and the shaft's). const LINE: f32 = 2.0; /// The dot's radius.