diff --git a/assets/locales/ar.json b/assets/locales/ar.json index 632aee7bd..a31597829 100644 --- a/assets/locales/ar.json +++ b/assets/locales/ar.json @@ -5081,12 +5081,15 @@ "ui.view_angles": "زوايا العرض", "ui.view_angles_convention": "درجات حول المحور العلوي. الانعراج 0° هو العرض الأمامي، و90° الأيسر، و−90° الأيمن، و180° الخلفي؛ الانحدار 90° هو العرض العلوي؛ والدوران الموجب يدير النموذج على الشاشة باتجاه عقارب الساعة.", "ui.view_angles_help": "يعرض زوايا الانحدار والانعراج والدوران للعرض بالدرجات ونوع الإسقاط أسفل أداة الاتجاه. انقر على القراءة لكتابة زوايا دقيقة.", + "ui.view_angles_lock": "قفل {axis}", "ui.view_angles_ortho": "متعامد", "ui.view_angles_persp": "منظور", "ui.view_angles_pitch": "الانحدار", "ui.view_angles_readout": "الانحدار {pitch} · الانعراج {yaw} · الدوران {roll}", "ui.view_angles_roll": "الدوران", + "ui.view_angles_unlock": "إلغاء قفل {axis}", "ui.view_angles_yaw": "الانعراج", + "ui.view_angles_zero": "تعيين {axis} إلى 0°", "ui.view_centre": "مركز العرض", "ui.viewport_status_clear": "إيقاف {name}", "ui.viewport_status_clear_hint": "إيقاف {name} · Esc", diff --git a/assets/locales/en.json b/assets/locales/en.json index aba26bdbc..891a97c37 100644 --- a/assets/locales/en.json +++ b/assets/locales/en.json @@ -5081,12 +5081,15 @@ "ui.view_angles": "View angles", "ui.view_angles_convention": "Degrees about the up axis. Yaw 0° is the Front view, 90° Left, −90° Right, 180° Back; pitch 90° is the Top view; a positive roll turns the model clockwise.", "ui.view_angles_help": "Shows the view's pitch, yaw and roll in degrees and its projection under the orientation gizmo. Click the readout to type exact angles.", + "ui.view_angles_lock": "Lock {axis}", "ui.view_angles_ortho": "Ortho", "ui.view_angles_persp": "Persp", "ui.view_angles_pitch": "Pitch", "ui.view_angles_readout": "Pitch {pitch} · Yaw {yaw} · Roll {roll}", "ui.view_angles_roll": "Roll", + "ui.view_angles_unlock": "Unlock {axis}", "ui.view_angles_yaw": "Yaw", + "ui.view_angles_zero": "Set {axis} to 0°", "ui.view_centre": "View center", "ui.viewport_status_clear": "Turn off {name}", "ui.viewport_status_clear_hint": "Turn off {name} · Esc", diff --git a/assets/locales/he.json b/assets/locales/he.json index 20cbac55a..9e490941a 100644 --- a/assets/locales/he.json +++ b/assets/locales/he.json @@ -5081,12 +5081,15 @@ "ui.view_angles": "זוויות תצוגה", "ui.view_angles_convention": "מעלות סביב הציר העליון. סבסוב 0° הוא התצוגה הקדמית, 90° שמאלית, −90° ימנית, 180° אחורית; עלרוד 90° הוא התצוגה העליונה; גלגול חיובי מסובב את המודל על המסך עם כיוון השעון.", "ui.view_angles_help": "מציג מתחת לגיזמו הכיוון את זוויות העלרוד, הסבסוב והגלגול של התצוגה במעלות ואת סוג ההטלה. לחצו על התצוגה כדי להקליד זוויות מדויקות.", + "ui.view_angles_lock": "נעל את {axis}", "ui.view_angles_ortho": "אורתוגרפי", "ui.view_angles_persp": "פרספקטיבה", "ui.view_angles_pitch": "עלרוד", "ui.view_angles_readout": "עלרוד {pitch} · סבסוב {yaw} · גלגול {roll}", "ui.view_angles_roll": "גלגול", + "ui.view_angles_unlock": "בטל נעילת {axis}", "ui.view_angles_yaw": "סבסוב", + "ui.view_angles_zero": "הגדר את {axis} ל-0°", "ui.view_centre": "מרכז המבט", "ui.viewport_status_clear": "כיבוי {name}", "ui.viewport_status_clear_hint": "כיבוי {name} · Esc", diff --git a/assets/locales/ja.json b/assets/locales/ja.json index 0a9b32d71..e4ca956d4 100644 --- a/assets/locales/ja.json +++ b/assets/locales/ja.json @@ -5081,12 +5081,15 @@ "ui.view_angles": "ビュー角度", "ui.view_angles_convention": "上方向の軸まわりの角度(度)。ヨー 0° が正面ビュー、90° が左、−90° が右、180° が背面です。ピッチ 90° が上面ビューです。ロールが正のとき、モデルは画面上で時計回りに回ります。", "ui.view_angles_help": "方向ギズモの下に、ビューのピッチ、ヨー、ロール(度)と投影法を表示します。表示をクリックすると正確な角度を入力できます。", + "ui.view_angles_lock": "{axis}をロック", "ui.view_angles_ortho": "平行投影", "ui.view_angles_persp": "透視投影", "ui.view_angles_pitch": "ピッチ", "ui.view_angles_readout": "ピッチ {pitch} · ヨー {yaw} · ロール {roll}", "ui.view_angles_roll": "ロール", + "ui.view_angles_unlock": "{axis}のロックを解除", "ui.view_angles_yaw": "ヨー", + "ui.view_angles_zero": "{axis}を0°に設定", "ui.view_centre": "ビュー中心", "ui.viewport_status_clear": "{name}をオフにする", "ui.viewport_status_clear_hint": "{name}をオフにする · Esc", diff --git a/assets/locales/vi.json b/assets/locales/vi.json index 363bd8245..2f13099bb 100644 --- a/assets/locales/vi.json +++ b/assets/locales/vi.json @@ -5081,12 +5081,15 @@ "ui.view_angles": "Góc hướng nhìn", "ui.view_angles_convention": "Độ quanh trục hướng lên. Lệch 0° là góc nhìn phía trước, 90° bên trái, −90° bên phải, 180° phía sau; chúc 90° là góc nhìn từ trên; nghiêng dương xoay mô hình trên màn hình theo chiều kim đồng hồ.", "ui.view_angles_help": "Hiển thị góc chúc, góc lệch và góc nghiêng của góc nhìn theo độ cùng kiểu chiếu, bên dưới gizmo định hướng. Bấm vào phần hiển thị để nhập góc chính xác.", + "ui.view_angles_lock": "Khóa {axis}", "ui.view_angles_ortho": "Trực giao", "ui.view_angles_persp": "Phối cảnh", "ui.view_angles_pitch": "Chúc", "ui.view_angles_readout": "Chúc {pitch} · Lệch {yaw} · Nghiêng {roll}", "ui.view_angles_roll": "Nghiêng", + "ui.view_angles_unlock": "Mở khóa {axis}", "ui.view_angles_yaw": "Lệch", + "ui.view_angles_zero": "Đặt {axis} về 0°", "ui.view_centre": "Tâm góc nhìn", "ui.viewport_status_clear": "Tắt {name}", "ui.viewport_status_clear_hint": "Tắt {name} · Esc", diff --git a/assets/locales/zh.json b/assets/locales/zh.json index d7d30878f..f45b6ef00 100644 --- a/assets/locales/zh.json +++ b/assets/locales/zh.json @@ -5081,12 +5081,15 @@ "ui.view_angles": "视图角度", "ui.view_angles_convention": "绕向上轴的角度(度)。偏航 0° 为前视图,90° 为左视图,−90° 为右视图,180° 为后视图;俯仰 90° 为俯视图;滚转为正时,模型在屏幕上顺时针旋转。", "ui.view_angles_help": "在方向小部件下方显示视图的俯仰、偏航和滚转角(度)以及投影方式。单击读数可输入精确角度。", + "ui.view_angles_lock": "锁定{axis}", "ui.view_angles_ortho": "正交", "ui.view_angles_persp": "透视", "ui.view_angles_pitch": "俯仰", "ui.view_angles_readout": "俯仰 {pitch} · 偏航 {yaw} · 滚转 {roll}", "ui.view_angles_roll": "滚转", + "ui.view_angles_unlock": "解锁{axis}", "ui.view_angles_yaw": "偏航", + "ui.view_angles_zero": "将{axis}设为 0°", "ui.view_centre": "视图中心", "ui.viewport_status_clear": "关闭{name}", "ui.viewport_status_clear_hint": "关闭{name} · Esc", diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index c3288e0b7..18426501b 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -351,6 +351,11 @@ pub struct UiState { /// Perspective while orbiting, orthographic when the camera faces a standard axis view /// (#2682). Off by default; when on it decides the projection instead of `perspective`. pub auto_ortho_faces: bool, + /// View angles card locks (#4581): a locked angle stays put while orbiting, turning with the + /// arrow keys or using a 3D mouse, and its field and zero button in the card go inert. + pub view_angles_lock_yaw: bool, + pub view_angles_lock_pitch: bool, + pub view_angles_lock_roll: bool, pub palette_open: bool, /// Dark theme (the default); a preference kept between runs. pub dark: bool, @@ -403,6 +408,9 @@ impl Default for UiState { show_navigation_bar: true, perspective: false, auto_ortho_faces: false, + view_angles_lock_yaw: false, + view_angles_lock_pitch: false, + view_angles_lock_roll: false, palette_open: false, dark: true, pick_off: Vec::new(), @@ -1371,6 +1379,8 @@ impl SolveApp { } if id == "view.navigate" { let to: Camera = serde_json::from_value(v.get("camera").cloned().unwrap_or_default()).map_err(|e| e.to_string())?; + // A locked view angle (#4581) never moves with the mouse or the arrow keys. + let to = crate::view_angles::keep_locked(self, self.cam, to); if v.get("continuous").and_then(Value::as_bool).unwrap_or(false) { self.cancel_view_animation(); self.cam = to; diff --git a/crates/ui-egui/src/navigation.rs b/crates/ui-egui/src/navigation.rs index e0105ed92..31d013891 100644 --- a/crates/ui-egui/src/navigation.rs +++ b/crates/ui-egui/src/navigation.rs @@ -503,7 +503,7 @@ pub(crate) fn step_key_hold(app: &mut SolveApp, ctx: &egui::Context) { { app.cancel_view_animation(); app.viewport.orbit_free = None; - app.cam = cam; + app.cam = crate::view_angles::keep_locked(app, app.cam, cam); } } @@ -909,11 +909,15 @@ pub(crate) fn device(app: &mut SolveApp, rect: Rect, caps: NavCaps) { } }); if let Some(queued) = app.viewport.device_motion.take() { + let before = app.cam; device_camera(&mut app.cam, queued.motion, queued.seconds, height, turn, app.preferences.free_orbit, anchor, pivot); + app.cam = crate::view_angles::keep_locked(app, before, app.cam); } // A device app's motion (the navigation bridge), on the same terms. if let Some(queued) = app.viewport.bridge_motion.take() { + let before = app.cam; bridge_camera(&mut app.cam, queued, height, turn, app.preferences.zoom_reverse, app.preferences.free_orbit, anchor, pivot); + app.cam = crate::view_angles::keep_locked(app, before, app.cam); } } diff --git a/crates/ui-egui/src/view_angles.rs b/crates/ui-egui/src/view_angles.rs index aa15f2e02..35fd8dc45 100644 --- a/crates/ui-egui/src/view_angles.rs +++ b/crates/ui-egui/src/view_angles.rs @@ -2,13 +2,17 @@ //! degrees and its projection, shown while View ▸ View angles is on (`view.angle_readout`). A //! click on it opens a small card to type exact angles; its Apply runs `view.apply`. //! +//! Each axis in the card also has a zero button that turns that angle to 0° at once, and a lock +//! (#4581): a locked angle stays put while orbiting, turning with the arrow keys or using a 3D +//! mouse, so a symmetrical view can hold its yaw and roll at 0° while only the pitch is adjusted. +//! //! The angles are the camera's own (`Camera::view_angles`), about the up axis: yaw is the heading //! of the line of sight (Front 0°, Left 90°, Right −90°, Back 180°), pitch the eye's elevation //! (Top 90°, Bottom −90°), and a positive roll turns the model clockwise on screen. use egui::{Align2, FontId, Rect, Sense, pos2, vec2}; use serde_json::json; -use solidcraft_engine::render::ViewAngles; +use solidcraft_engine::render::{Camera, ViewAngles}; use crate::SolveApp; use crate::fonts::RichTextExt as _; @@ -56,8 +60,56 @@ pub(crate) fn lines(app: &SolveApp) -> (String, String) { (angles, crate::i18n::tr(projection).to_string()) } +/// Whether the angle of `axis` (`"yaw"`, `"pitch"` or `"roll"`) is locked in the card (#4581). +pub(crate) fn locked_angle(app: &SolveApp, axis: &str) -> bool { + match axis { + "yaw" => app.ui.view_angles_lock_yaw, + "pitch" => app.ui.view_angles_lock_pitch, + _ => app.ui.view_angles_lock_roll, + } +} + +fn set_lock(app: &mut SolveApp, axis: &str, locked: bool) { + match axis { + "yaw" => app.ui.view_angles_lock_yaw = locked, + "pitch" => app.ui.view_angles_lock_pitch = locked, + _ => app.ui.view_angles_lock_roll = locked, + } +} + +/// A camera `to` that a mouse or key motion just produced, with every locked angle kept at its +/// value on `from`: orbiting, arrow turns and 3D-mouse motion never move a locked axis (#4581). +pub(crate) fn keep_locked(app: &SolveApp, from: Camera, to: Camera) -> Camera { + if !(locked_angle(app, "yaw") || locked_angle(app, "pitch") || locked_angle(app, "roll")) { + return to; + } + let mut angles = to.view_angles(); + let held = from.view_angles(); + if locked_angle(app, "yaw") { + angles.yaw = held.yaw; + } + if locked_angle(app, "pitch") { + angles.pitch = held.pitch; + } + if locked_angle(app, "roll") { + angles.roll = held.roll; + } + to.with_view_angles(angles).unwrap_or(to) +} + /// Turn the view to typed angles through `view.apply`, keeping its target, distance and projection. -pub(crate) fn apply(app: &mut SolveApp, angles: ViewAngles) { +/// A locked axis keeps the angle the view has now, whatever the card holds for it. +pub(crate) fn apply(app: &mut SolveApp, mut angles: ViewAngles) { + let held = app.cam.view_angles(); + if locked_angle(app, "yaw") { + angles.yaw = held.yaw; + } + if locked_angle(app, "pitch") { + angles.pitch = held.pitch; + } + if locked_angle(app, "roll") { + angles.roll = held.roll; + } let Some(cam) = app.cam.with_view_angles(angles) else { return }; let camera = json!({"target": cam.target, "yaw": cam.yaw, "pitch": cam.pitch, "roll": cam.roll, "distance": cam.distance, "fov": cam.fov}); if app.run("view.apply", json!({ "camera": camera })).is_ok() { @@ -116,12 +168,45 @@ pub(crate) fn show(app: &mut SolveApp, ui: &mut egui::Ui, rect: Rect) { let mut applied = false; let card = area.show(ui.ctx(), |ui| { Container::popup_frame(ui.style()).show(ui, |ui| { - ui.set_width(200.0); + ui.set_width(260.0); ui.label(egui::RichText::new(crate::i18n::tr("ui.view_angles")).semibold().color(t.text).size(t.font_caption)); - for (id, value) in - [("ui.view_angles_pitch", &mut typed.pitch), ("ui.view_angles_yaw", &mut typed.yaw), ("ui.view_angles_roll", &mut typed.roll)] - { - ui_kit::row(ui, crate::i18n::tr(id), |ui| ui_kit::angle_field(ui, value)); + for (id, axis) in [("ui.view_angles_pitch", "pitch"), ("ui.view_angles_yaw", "yaw"), ("ui.view_angles_roll", "roll")] { + let locked = locked_angle(app, axis); + let axis_name = crate::i18n::tr(id); + let mut value = match axis { + "pitch" => typed.pitch, + "yaw" => typed.yaw, + _ => typed.roll, + }; + let zeroed = ui_kit::row(ui, axis_name, |ui| { + let mut zeroed = false; + ui.horizontal(|ui| { + ui.add_enabled_ui(!locked, |ui| ui_kit::angle_field(ui, &mut value)); + let zero = ui_kit::button(ui, "0°", ui_kit::Button::Enabled(!locked)) + .on_hover_text(crate::i18n::format("ui.view_angles_zero", &[("axis", axis_name)])); + zeroed = zero.clicked(); + crate::scenario::publish_target(&format!("view_angles:zero:{axis}"), zero.rect); + let mut lock = locked; + let help = if locked { "ui.view_angles_unlock" } else { "ui.view_angles_lock" }; + let checkbox = ui_kit::checkbox(ui, "", &mut lock).on_hover_text(crate::i18n::format(help, &[("axis", axis_name)])); + crate::scenario::publish_target(&format!("view_angles:lock:{axis}"), checkbox.rect); + if lock != locked { + set_lock(app, axis, lock); + } + }); + zeroed + }); + if zeroed { + value = 0.0; + } + match axis { + "pitch" => typed.pitch = value, + "yaw" => typed.yaw = value, + _ => typed.roll = value, + } + if zeroed { + apply(app, typed); + } } ui_kit::text(ui, crate::i18n::tr("ui.view_angles_convention"), ui_kit::Text::Hint("view_angles")); applied = ui_kit::primary_button(ui, "Apply").clicked(); diff --git a/crates/ui-egui/src/viewport_overlays_tests.rs b/crates/ui-egui/src/viewport_overlays_tests.rs index d3aa419da..09412ffa3 100644 --- a/crates/ui-egui/src/viewport_overlays_tests.rs +++ b/crates/ui-egui/src/viewport_overlays_tests.rs @@ -1304,6 +1304,63 @@ fn view_angles_readout_shows_only_when_on_and_applies_typed_angles() { } } +/// The card's zero buttons and per-axis locks (#4581): zero turns one angle to 0° at once, and a +/// locked angle stays put through orbit turns and Apply, so a symmetrical view can hold its yaw +/// while only the pitch is adjusted. +#[test] +fn view_angles_card_zero_buttons_and_axis_locks() { + use solidcraft_engine::render::ViewAngles; + let mut h = Harness::new(); + h.app.preferences.look_at_anim = false; + h.call("engine.execute", json!({"command": "view.angle_readout", "params": {"enabled": true}})); + h.call("ui.view", json!({"view": "iso"})); + h.settle(); + let readout = crate::scenario::rect_of("view_angles:readout").expect("the readout shows once it is on"); + h.call("ui.click", json!({"x": readout.center().x, "y": readout.center().y})); + assert!(crate::scenario::rect_of("view_angles:card").is_some()); + // The iso view has a non-zero yaw; its zero button turns it to the front view at once. + let before = h.app.cam.view_angles(); + assert!(before.yaw.abs() > 1.0, "{before:?}"); + let zero = crate::scenario::handle_at("view_angles:zero:yaw").expect("a zero button per axis"); + h.call("ui.click", json!({"x": zero.x, "y": zero.y})); + h.settle(); + let after = h.app.cam.view_angles(); + assert!(after.yaw.abs() < 1e-6, "{after:?}"); + assert!((after.pitch - before.pitch).abs() < 1e-6, "only yaw zeroed: {after:?}"); + // Lock yaw: an orbit turn moves the pitch but never the locked yaw, and the locked axis's + // zero button goes inert. + let lock = crate::scenario::handle_at("view_angles:lock:yaw").expect("a lock per axis"); + h.call("ui.click", json!({"x": lock.x, "y": lock.y})); + assert!(h.app.ui.view_angles_lock_yaw); + let yaw = h.app.cam.view_angles().yaw; + h.app.run("view.navigate", json!({"camera": h.app.cam, "action": "up", "degrees": 20.0})).unwrap(); + let turned = h.app.cam.view_angles(); + assert!((turned.yaw - yaw).abs() < 1e-6, "a locked yaw survives an orbit turn: {turned:?}"); + assert!(turned.pitch > before.pitch + 10.0, "the turn moved the pitch: {turned:?}"); + let zero = crate::scenario::handle_at("view_angles:zero:yaw").unwrap(); + h.call("ui.click", json!({"x": zero.x, "y": zero.y})); + h.settle(); + assert!((h.app.cam.view_angles().yaw - yaw).abs() < 1e-6, "the locked axis's zero button is inert"); + // Apply keeps the locked angle whatever the card holds for it. + h.ctx.data_mut(|d| d.insert_temp(crate::view_angles::draft_id(), ViewAngles { yaw: 40.0, pitch: 20.0, roll: 0.0 })); + h.frame(); + let apply = crate::scenario::handle_at("dialog:button:Apply").unwrap(); + h.call("ui.click", json!({"x": apply.x, "y": apply.y})); + h.settle(); + let applied = h.app.cam.view_angles(); + assert!((applied.yaw - yaw).abs() < 1e-6, "Apply keeps the locked yaw: {applied:?}"); + assert!((applied.pitch - 20.0).abs() < 1e-6, "{applied:?}"); + // Unlocking lets the zero button work again. + let lock = crate::scenario::handle_at("view_angles:lock:yaw").unwrap(); + h.call("ui.click", json!({"x": lock.x, "y": lock.y})); + assert!(!h.app.ui.view_angles_lock_yaw); + let zero = crate::scenario::handle_at("view_angles:zero:yaw").unwrap(); + h.call("ui.click", json!({"x": zero.x, "y": zero.y})); + h.settle(); + assert!(h.app.cam.view_angles().yaw.abs() < 1e-6); + assert!(h.app.session.undo.is_empty(), "view angles never touch the design"); +} + /// In the corner (#7893) the buttons sit as in the dialogs: right-aligned, dismissals first and the /// main action right-most; when they wrap, the row with the main action is the bottom one. #[test]