diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index dc6ecbc1..2a40f6e0 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -976,6 +976,12 @@ impl SolveApp { self.dialog.as_ref().is_some_and(|d| matches!(d.kind, dialogs::Kind::Sketch)) } + /// Is the view drawn in perspective? The perspective preference, except while a sketch is + /// open: a sketch is drawn and measured on its plane, so the view is parallel (no foreshortening). + pub fn perspective_view(&self) -> bool { + self.ui.perspective && self.session.active_sketch.is_none() + } + pub fn set_status(&mut self, s: impl Into, error: bool) { self.status = Some((s.into(), now_ms(), error)); } @@ -1077,7 +1083,7 @@ impl SolveApp { fn fitted_bounds(&self, mut cam: Camera, bounds: &solidcraft_engine::geom::Aabb3) -> Camera { if let Some(layout) = &self.viewport.layout { - return viewport_layout::fit_bounds(cam, bounds, layout, self.ui.perspective).unwrap_or(cam); + return viewport_layout::fit_bounds(cam, bounds, layout, self.perspective_view()).unwrap_or(cam); } let previous = cam; cam.fit(bounds); diff --git a/crates/ui-egui/src/viewport.rs b/crates/ui-egui/src/viewport.rs index cd0b69db..7256d223 100644 --- a/crates/ui-egui/src/viewport.rs +++ b/crates/ui-egui/src/viewport.rs @@ -267,7 +267,7 @@ pub fn scene_radius(app: &SolveApp) -> f64 { pub fn projection(app: &SolveApp, rect: Rect) -> Proj { let mut cam = app.cam; - cam.fov = if app.ui.perspective { 0.6 } else { 0.0 }; + cam.fov = if app.perspective_view() { 0.6 } else { 0.0 }; let aspect = rect.width() as f64 / rect.height().max(1.0) as f64; Proj { cam, vp: cam.view_proj(aspect, scene_radius(app)), rect } } @@ -1102,7 +1102,7 @@ pub(crate) fn pick_cached(app: &mut SolveApp, proj: &Proj, pos: Pos2) -> Vec 0.0); + app.run("sketch.create", json!({"plane": "XZ"})).unwrap(); + assert!(!app.perspective_view()); + assert_eq!(projection(&app, rect).cam.fov, 0.0); + app.finish_sketch(); + assert!(app.ui.perspective, "the preference is left alone"); + assert!(projection(&app, rect).cam.fov > 0.0); + } + /// Create Sketch shows the Origin even when the browser hides it, and draws its planes /// through the model so a plane inside a body can be seen and picked; closing it restores /// the hidden, depth-tested Origin.