Place no point on the release of a realtime PAN or ZOOM drag

A primary drag that moved the view is marked while it lasts; its release reaches no point prompt, also when Enter ended the transparent PAN or ZOOM mid-drag and handed the prompt back to the drawing command.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mattlafy
2026-10-29 15:46:01 -04:00
co-authored by Claude Opus 5.5
parent a9294b5151
commit b2ebb3958d
3 changed files with 88 additions and 1 deletions
+10 -1
View File
@@ -149,6 +149,9 @@ pub struct CanvasState {
pub param: crate::parametric::Cache,
/// A selection window opened by a press-and-drag, to close where the button is let go.
drag_window: bool,
/// The primary drag in progress moved the view (realtime PAN or ZOOM): its release is no
/// point, even once the command has ended.
nav_drag: bool,
/// The right-click that opened the shortcut menu held Shift or Ctrl: it is the object snap
/// menu ([`crate::context_menu`]).
pub snap_menu: bool,
@@ -252,10 +255,12 @@ fn navigate_canvas(app: &mut CadApp, ui: &mut egui::Ui, nav: &Navigation<'_>) ->
handle_scroll_zoom(app, ui, nav, inside);
handle_button_navigation(app, nav, inside);
if nav.response.dragged_by(egui::PointerButton::Primary) && app.session.realtime_zoom_active() {
app.canvas.nav_drag = true;
let _ = app.session.realtime_zoom(f64::from(nav.response.drag_delta().y));
}
// PAN (realtime): the drawing follows a left-button drag.
if nav.response.dragged_by(egui::PointerButton::Primary) && app.session.realtime_pan_active() {
app.canvas.nav_drag = true;
let d = nav.response.drag_delta();
let _ = app.session.realtime_pan(f64::from(d.x), f64::from(d.y));
}
@@ -695,7 +700,11 @@ fn collect_prompt_clicks(app: &mut CadApp, ui: &egui::Ui, context: PromptClickCo
&& app.session.pending_window.is_none()
&& !app.session.realtime_zoom_active()
&& !app.session.realtime_pan_active();
let pressed_primary = context.primary_clicked || (point_prompt && context.response.drag_stopped_by(egui::PointerButton::Primary));
let drag_stopped = context.response.drag_stopped_by(egui::PointerButton::Primary);
// The release of a drag that panned or zoomed (Enter can end the command mid-drag) places
// nothing in the command it returns to.
let nav_release = drag_stopped && std::mem::take(&mut app.canvas.nav_drag);
let pressed_primary = context.primary_clicked || (point_prompt && drag_stopped && !nav_release);
if point_prompt && context.inside && pressed_primary && !context.middle_down && app.cmd.options.is_none() && app.cmd.buffer.is_empty() {
let releases: Vec<egui::Pos2> = ui.input(|i| {
i.events
+1
View File
@@ -26,6 +26,7 @@ mod parameters_rename;
mod pickdrag;
mod properties_units;
mod rapid_clicks;
mod realtime_nav_release;
mod selection_cycling;
mod shared_controls;
mod shortcut_menus;
@@ -0,0 +1,77 @@
//! A drag that pans in realtime places no point when it is let go, even after Enter ended the
//! transparent PAN mid-drag and handed the prompt back to the drawing command.
use cadcraft_engine::Session;
use cadcraft_engine::doc::{Drawing, EntityKind, Space};
use cadcraft_engine::geom::Vec2;
use cadcraft_ui_egui::{CadApp, Services};
use egui::{Event, Modifiers, PointerButton, Pos2, vec2};
use egui_kittest::Harness;
use serde_json::json;
fn harness() -> Harness<'static, CadApp> {
let mut session = Session::empty();
session.open_drawing(Drawing::new_imperial(), "Realtime release", None);
session.execute("view.set", &json!({"center":[50,50],"height":100})).unwrap();
session.settings.osmode = 0;
session.settings.snapmode = false;
session.settings.orthomode = false;
let mut app = CadApp::new(session, Services::default());
app.canvas.zoom_pending = false;
let mut h = Harness::builder().with_size(vec2(1600.0, 1000.0)).build_ui_state(
|ui, app: &mut CadApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
h.run_steps(5);
h
}
fn screen(h: &Harness<'_, CadApp>, p: Vec2) -> Pos2 {
h.state().canvas.xf.unwrap().to_screen(p)
}
fn button(h: &mut Harness<'_, CadApp>, pos: Pos2, pressed: bool) {
h.event(Event::PointerMoved(pos));
h.event(Event::PointerButton { pos, button: PointerButton::Primary, pressed, modifiers: Modifiers::NONE });
h.run_steps(1);
}
fn lines(h: &Harness<'_, CadApp>) -> usize {
let st = h.state().session.state().unwrap();
st.doc.space(&Space::Model).unwrap().iter().filter(|e| matches!(e.kind, EntityKind::Line(_))).count()
}
#[test]
fn enter_mid_drag_ends_pan_and_the_release_places_no_point() {
let mut h = harness();
h.state_mut().start("line");
h.run_steps(2);
let first = screen(&h, Vec2::new(10.0, 10.0));
button(&mut h, first, true);
button(&mut h, first, false);
h.run_steps(2);
h.state_mut().session.cmdline("'PAN").unwrap();
h.run_steps(1);
assert!(h.state().session.realtime_pan_active());
let (a, b) = (screen(&h, Vec2::new(40.0, 40.0)), screen(&h, Vec2::new(60.0, 30.0)));
button(&mut h, a, true);
for i in 1..=4 {
h.event(Event::PointerMoved(a + (b - a) * (i as f32 / 4.0)));
h.run_steps(1);
}
h.state_mut().session.cmdline("").unwrap();
h.run_steps(1);
assert_eq!(h.state().session.running.as_ref().map(|r| r.id.as_str()), Some("line"));
button(&mut h, b, false);
h.run_steps(2);
assert_eq!(lines(&h), 0, "the release of the pan drag placed a point");
assert_eq!(h.state().session.running.as_ref().map(|r| r.id.as_str()), Some("line"));
// A click after it still places the next point.
button(&mut h, b, true);
button(&mut h, b, false);
h.run_steps(2);
assert_eq!(lines(&h), 1);
}