Navigation: wheel and trackpad gestures go on under a value box (#10061) (#10073)

* Navigation: wheel and trackpad gestures go on under a value box (#10061)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Navigation: wheel and trackpad gestures go on under a value box (#10061)

Any area above the model took navigation's wheel input, so a two-finger
pan, orbit or zoom stopped as the pointer crossed a floating value box
(Extrude's distance), and none could start over one. Model-anchored
canvas areas (Surface::Canvas: value boxes, a dimension's editor,
readouts) scroll nothing: navigation's wheel, trackpad pan and orbit and
pinch now go on under them. Their clicks stay theirs, and with value
stepping on the wheel stays with the value under the pointer.

Container::area records the canvas areas it builds; navigation asks
whether the top layer under the pointer is one (container::is_canvas).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
austin62jakeandClaude Opus 5.5 authored and GitHub committed 2026-10-31 14:01:05 +00:00
1 parent f30fce0fc1
commit 2b1ca94e2d
3 files changed
+82 -4

No files matched your search

+17 -4
View File
@@ -574,6 +574,19 @@ pub(crate) fn handle(app: &mut SolveApp, ui: &mut egui::Ui, rect: Rect, resp: &e
&& resp.contains_pointer()
&& ui.rect_contains_pointer(rect)
&& hover.is_some_and(|p| !axes.contains(p) && !readout.is_some_and(|r| r.contains(p)));
// The wheel and trackpad gestures go on under a box anchored to the model (a value box such
// as Extrude's distance, a dimension's editor): it scrolls nothing, and a pan, orbit or zoom
// stopped as it crossed one (#10061). Its clicks stay its own. Not while the wheel steps the
// value under the pointer (Preferences › Design, value stepping).
let wheel_inside = inside
|| (ui.is_enabled()
&& !crate::value_step::enabled(ui.ctx())
&& hover.is_some_and(|p| {
rect.contains(p)
&& !axes.contains(p)
&& !readout.is_some_and(|r| r.contains(p))
&& ui.ctx().layer_id_at(p).is_some_and(crate::ui_kit::container::is_canvas)
}));
app.viewport.mouse = hover.filter(|_| inside);
// Sketch snap suppression is set once in `viewport::show` from preferences.
middle_double_click(app, ui, inside);
@@ -621,7 +634,7 @@ pub(crate) fn handle(app: &mut SolveApp, ui: &mut egui::Ui, rect: Rect, resp: &e
// Pinch-to-zoom (trackpad): direct manipulation, never smoothed.
let pinch = ui.input(|i| pinch_factor(i, options, page_height, zoom_modifier));
let h = rect.height().max(1.0) as f64;
if inside && pinch != 1.0 {
if wheel_inside && pinch != 1.0 {
app.viewport.orbit_free = None;
// Spread zooms in: the camera distance shrinks by the pinch factor.
let f = f64::from(pinch).powf(-crate::prefs::zoom_sign(app));
@@ -637,7 +650,7 @@ pub(crate) fn handle(app: &mut SolveApp, ui: &mut egui::Ui, rect: Rect, resp: &e
app.cam.zoom_at(f, anchor);
}
}
if inside && scroll.is_finite() && scroll != 0.0 {
if wheel_inside && scroll.is_finite() && scroll != 0.0 {
app.viewport.orbit_free = None;
let f = (-scroll as f64 * 0.0015 * f64::from(app.preferences.wheel_zoom_speed) * crate::prefs::zoom_sign(app)).exp();
let anchor = zoom_anchor(app, rect, hover, caps.orbit);
@@ -653,7 +666,7 @@ pub(crate) fn handle(app: &mut SolveApp, ui: &mut egui::Ui, rect: Rect, resp: &e
}
}
// Two-finger scroll pans the model with the fingers.
if inside && pan.is_finite() && pan != egui::Vec2::ZERO {
if wheel_inside && pan.is_finite() && pan != egui::Vec2::ZERO {
app.viewport.orbit_free = None;
if app.preferences.nav == crate::prefs::TOUCHPAD_NAV {
camera_motion(app, rect, json!({"motion":"pan","delta":[pan.x,pan.y]}));
@@ -662,7 +675,7 @@ pub(crate) fn handle(app: &mut SolveApp, ui: &mut egui::Ui, rect: Rect, resp: &e
app.cam.pan(f64::from(pan.x), f64::from(pan.y), h);
}
}
if inside && caps.orbit && trackpad_orbit && raw.shift_pan != egui::Vec2::ZERO {
if wheel_inside && caps.orbit && trackpad_orbit && raw.shift_pan != egui::Vec2::ZERO {
app.cancel_view_animation();
app.viewport.orbit_free = None;
let sign = crate::prefs::orbit_sign(app);
+14
View File
@@ -58,6 +58,17 @@ impl DockEdges {
pub const ALL: Self = Self { left: true, right: true, top: true, bottom: true };
}
thread_local! {
/// The areas built as [`Surface::Canvas`]: a value box, a dimension's editor, a readout.
static CANVAS_AREAS: std::cell::RefCell<std::collections::HashSet<Id>> = std::cell::RefCell::default();
}
/// Is `layer` a model-anchored editor or readout ([`Surface::Canvas`])? Such an area sits on the
/// model and scrolls nothing, so the model's wheel and trackpad navigation go on under it (#10061).
pub(crate) fn is_canvas(layer: egui::LayerId) -> bool {
CANVAS_AREAS.with(|areas| areas.borrow().contains(&layer.id))
}
/// Universal outer host and surface policy. Both host geometry and frame construction must go
/// through this API, including code in nested modules and platform apps.
#[derive(Clone, Copy)]
@@ -310,6 +321,9 @@ impl Container {
}
pub fn area(self, id: Id) -> egui::Area {
if self.surface == Surface::Canvas {
CANVAS_AREAS.with(|areas| areas.borrow_mut().insert(id));
}
// Workspace cards and viewport status stay below tool/system windows even when
// clicked. Other areas keep the normal window layer; popups choose their order.
let order = if matches!(self.surface, Surface::Panel | Surface::ViewportStatus) { egui::Order::Background } else { egui::Order::Middle };
+51
View File
@@ -10234,6 +10234,57 @@ mod tests {
assert_eq!(h.app.cam, stopped, "noise must leave the camera still");
}
/// A two-finger pan, a pinch and the wheel over a value box anchored to the model (Extrude's
/// distance) move the view as they do beside it (#10061): the box scrolls nothing, and a
/// gesture crossing it stopped. The box keeps its value. Dialogs keep theirs (below).
#[test]
fn trackpad_gestures_and_the_wheel_over_a_value_box_move_the_view() {
let mut h = crate::scenario::Harness::new();
h.app.run("sketch.create", json!({"plane": "XY"})).unwrap();
h.app.run("sketch.rectangle.two_point", json!({"p0": [0, 0], "p1": [40, 30]})).unwrap();
h.app.run("sketch.finish", json!({})).unwrap();
let sketch = h.app.session.doc.features[0].id;
h.app.session.selection = vec![Sel::Profile { sketch, index: 0 }];
h.step(&json!({"start": "solid.extrude"})).unwrap();
h.frames(6);
let over =
|h: &crate::scenario::Harness| h.ctx.read_response(egui::Id::new("sc_canvas_value")).expect("Extrude's distance box").rect.center();
let distance = |h: &crate::scenario::Harness| format!("{:?}", h.app.dialog.as_ref().map(|d| &d.kind));
let typed = distance(&h);
let at = over(&h);
h.call("ui.move", json!({"x": at.x, "y": at.y}));
h.frames(2);
assert!(h.ctx.layer_id_at(at).is_some_and(crate::ui_kit::container::is_canvas), "the pointer is on the box");
let gesture =
|phase| egui::Event::MouseWheel { unit: egui::MouseWheelUnit::Point, delta: vec2(30.0, -20.0), modifiers: egui::Modifiers::NONE, phase };
let before = h.app.cam;
h.app.synthetic.push(gesture(egui::TouchPhase::Start));
h.frame();
h.app.synthetic.push(gesture(egui::TouchPhase::Move));
h.frame();
assert_ne!(h.app.cam.target, before.target, "a two-finger pan over the box pans");
assert_eq!(h.app.cam.half_height(), before.half_height());
h.app.synthetic.push(gesture(egui::TouchPhase::End));
h.frames(30);
let at = over(&h);
h.call("ui.move", json!({"x": at.x, "y": at.y}));
h.frames(2);
let panned = h.app.cam;
h.app.synthetic.push(egui::Event::Zoom(1.2));
h.frame();
assert!(h.app.cam.half_height() < panned.half_height(), "a pinch over the box zooms");
let at = over(&h);
h.call("ui.move", json!({"x": at.x, "y": at.y}));
h.frames(2);
let pinched = h.app.cam;
h.app.preferences.smooth_wheel_zoom = false;
h.call("ui.scroll", json!({"x": at.x, "y": at.y, "delta": 120.0}));
h.frames(2);
assert_ne!(h.app.cam.half_height(), pinched.half_height(), "the wheel over the box zooms");
assert_eq!(distance(&h), typed, "the box kept its value");
assert!(h.app.dialog.is_some());
}
#[test]
fn trackpad_gestures_over_dialogs_do_not_move_the_view() {
let ctx = crate::fonts::test_context();