From f92e16fa25b23baaebfc6e07324f405c45210028 Mon Sep 17 00:00:00 2001 From: Dahak Builds Date: Wed, 4 Nov 2026 17:16:33 +0000 Subject: [PATCH] Keep orbit gizmo drag tracking past the window edge (#9943) (#9978) * Claim #9943: keep orbit gizmo drag tracking past the window edge * Warp the orbit gizmo drag back to the window centre at the edge (#9943) --------- Co-authored-by: Dahak Builds --- crates/ui-egui/src/viewport.rs | 31 ++++++++++++- crates/ui-egui/src/viewport_layout_tests.rs | 48 +++++++++++++++++++++ 2 files changed, 78 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/viewport.rs b/crates/ui-egui/src/viewport.rs index a1105d5af..e8e22c89d 100644 --- a/crates/ui-egui/src/viewport.rs +++ b/crates/ui-egui/src/viewport.rs @@ -210,6 +210,9 @@ pub struct ViewportState { pub(crate) trackpad_coast: crate::navigation::TrackpadCoast, /// A primary press on the axis gizmo: the pointer position used by its last orbit step. pub axis_drag: Option, + /// The centre the gizmo drag last warped the cursor to, until the pointer next lands near + /// it (steps measured before that echo would jump the view by the whole warp distance). + pub(crate) axis_warp: Option, /// Unsnapped camera while Shift-orbit previews a standard or diagonal view. pub orbit_free: Option, pub build_ms: f64, @@ -6871,19 +6874,45 @@ fn axis_view_orbit(app: &mut SolveApp, ui: &mut egui::Ui, rect: Rect) -> bool { navigation_cube::drag_origin(app, axis_center(app, rect), *p, axis_rect(app, rect).width() / navigation_cube::DESIGN_SIZE) } }); + app.viewport.axis_warp = None; if app.viewport.axis_drag.is_some() { app.viewport.orbit_free = None; } } if !down && app.viewport.axis_drag.take().is_some() { + app.viewport.axis_warp = None; app.viewport.orbit_free = None; } let Some(last) = app.viewport.axis_drag.filter(|_| decided) else { return false }; ui.ctx().set_cursor_icon(egui::CursorIcon::Grabbing); if let Some(p) = pos { app.cancel_view_animation(); - orbit_drag(app, rect, f64::from(p.x - last.x), f64::from(p.y - last.y), None, shift, false); + // While a warp is pending the pointer may still sit at the edge it hit (the OS has not + // echoed the warp, or cannot), have landed at the centre (the echo), or have moved past + // it (the echo plus a fast flick): measure each step from whichever reference the + // pointer is nearer to, so the view never jumps by the warp distance and a platform + // that ignores warps keeps orbiting from the real pointer instead of freezing. + let from = match app.viewport.axis_warp { + Some(w) if p.distance(w) <= p.distance(last) => { + app.viewport.axis_warp = None; + w + } + _ => last, + }; + orbit_drag(app, rect, f64::from(p.x - from.x), f64::from(p.y - from.y), None, shift, false); app.viewport.axis_drag = Some(p); + // The OS stops feeding movement once the cursor is pinned at the screen edge, so an + // orbit toward that edge would stall: warp the cursor back to the window centre and + // measure the next steps from there, keeping the orbit tracking while the button is held (#9943). + let screen = ui.ctx().viewport_rect(); + let edge = 6.0; + if app.viewport.axis_warp.is_none() + && (p.x <= screen.min.x + edge || p.x >= screen.max.x - edge || p.y <= screen.min.y + edge || p.y >= screen.max.y - edge) + { + let home = screen.center(); + app.viewport.axis_warp = Some(home); + ui.ctx().send_viewport_cmd(egui::ViewportCommand::CursorPosition(home)); + } ui.ctx().request_repaint(); } true diff --git a/crates/ui-egui/src/viewport_layout_tests.rs b/crates/ui-egui/src/viewport_layout_tests.rs index d9b4dbc8b..f7444107d 100644 --- a/crates/ui-egui/src/viewport_layout_tests.rs +++ b/crates/ui-egui/src/viewport_layout_tests.rs @@ -600,3 +600,51 @@ fn a_fit_centres_the_model_in_the_view_and_is_moved_only_by_panels() { assert!(roomy.distance <= cam.distance + 1e-9, "{style:?}: controls must not make the model larger"); } } + +/// #9943: dragging the orbit gizmo toward the window edge must not stall once the cursor hits +/// that edge: the drag warps the cursor back to the window centre and keeps orbiting while the +/// button is held. +#[test] +fn gizmo_orbit_keeps_tracking_after_the_cursor_hits_the_window_edge() { + let mut h = Harness::new(); + h.call("ui.view", json!({"view": "front"})); + h.settle(); + let outer = crate::scenario::rect_of("axis_view:outer").unwrap(); + let c = outer.center(); + let home = h.ctx.viewport_rect().center(); + let edge = h.ctx.viewport_rect().max.x - 2.0; + assert!(c.x < edge - 20.0 && home.x < edge - 20.0, "the gizmo and the centre sit clear of the edge"); + let press = |pressed: bool, at: egui::Pos2| egui::Event::PointerButton { + pos: at, + button: egui::PointerButton::Primary, + pressed, + modifiers: egui::Modifiers::NONE, + }; + h.app.synthetic.push(egui::Event::PointerMoved(c)); + h.app.synthetic.push(press(true, c)); + // Drag right until the cursor reaches the window's right edge. + for k in 1..=3 { + h.app.synthetic.push(egui::Event::PointerMoved(pos2((c.x + 40.0 * k as f32).min(edge), c.y))); + } + h.frames(8); + assert!(h.app.viewport.axis_drag.is_some(), "the drag is still held"); + assert_eq!(h.app.viewport.axis_warp, Some(home), "the cursor was warped back to the window centre"); + // The OS echoes the warp: the pointer reappears at the centre without moving the view. + let before = h.app.cam; + h.app.synthetic.push(egui::Event::PointerMoved(home)); + h.frames(4); + assert_eq!(h.app.cam, before, "the warp echo must not jump the view"); + assert!(h.app.viewport.axis_warp.is_none(), "the echo clears the pending warp"); + // The user keeps dragging right from the centre: the orbit keeps tracking past the edge. + let yaw = h.app.cam.yaw; + for k in 1..=5 { + h.app.synthetic.push(egui::Event::PointerMoved(pos2(home.x + 30.0 * k as f32, home.y))); + } + h.frames(8); + assert!((h.app.cam.yaw - yaw - 150.0 * 0.008).abs() < 1e-3, "the orbit kept tracking past the edge: {:?}", h.app.cam); + // Releasing ends the drag cleanly. + h.app.synthetic.push(press(false, pos2(home.x + 150.0, home.y))); + h.frames(4); + assert!(h.app.viewport.axis_drag.is_none()); + assert!(h.app.viewport.axis_warp.is_none()); +}