From c0b0369aa27ffdb5e60fa8aa14428772540eb61f Mon Sep 17 00:00:00 2001 From: ReDead <104050379+ReDead@users.noreply.github.com> Date: Fri, 30 Oct 2026 13:31:09 +0000 Subject: [PATCH] Sketch: hide constraint glyphs when zoomed out (#8980) (#9023) * claim: #8980 Hide constraint glyphs when zoomed out (claim). Co-authored-by: ReDead * Sketch: hide constraint glyphs when zoomed out (#8980) Fixed-size constraint glyphs stayed visible at every zoom and cluttered the view when far out. Hide them below a sketch-plane scale threshold, with the old always-on behaviour behind hide_constraint_glyphs_zoomed_out. Co-authored-by: ReDead * i18n: complete-catalog strings for zoom-hide preference (#8980) Add ar/he/vi translations for prefs.hide_constraint_glyphs_zoomed_out (and its note) so cargo xtask i18n --check no longer reports 6 gaps in complete catalogs. Co-authored-by: ReDead --------- Co-authored-by: Cursor Agent Co-authored-by: ReDead --- .../hide-constraint-glyphs-zoomed-out.json | 34 +++++++++++++ crates/ui-egui/src/prefs.rs | 5 ++ crates/ui-egui/src/prefs/sketch.rs | 3 ++ crates/ui-egui/src/sketch_tools.rs | 49 ++++++++++++++++++- ...onstraint_glyphs_hide_when_zoomed_out.json | 16 ++++++ 5 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 assets/locales/pending/hide-constraint-glyphs-zoomed-out.json create mode 100644 crates/ui-egui/tests/scenarios/constraint_glyphs_hide_when_zoomed_out.json diff --git a/assets/locales/pending/hide-constraint-glyphs-zoomed-out.json b/assets/locales/pending/hide-constraint-glyphs-zoomed-out.json new file mode 100644 index 000000000..355896e59 --- /dev/null +++ b/assets/locales/pending/hide-constraint-glyphs-zoomed-out.json @@ -0,0 +1,34 @@ +{ + "en": { + "prefs.hide_constraint_glyphs_zoomed_out": "Hide constraint glyphs when zoomed out", + "prefs.hide_constraint_glyphs_zoomed_out_note": "Constraint glyphs leave the view when the sketch is zoomed out far enough that they would clutter it. Off: they stay at a fixed screen size at every zoom." + }, + "ar": { + "prefs.hide_constraint_glyphs_zoomed_out": "إخفاء رموز القيود عند التصغير", + "prefs.hide_constraint_glyphs_zoomed_out_note": "تختفي رموز القيود عندما تُصغَّر المسودة بما يكفي حتى لا تزحم العرض. معطّل: تبقى بحجم شاشة ثابت عند أي تكبير." + }, + "de": { + "prefs.hide_constraint_glyphs_zoomed_out": "Bindungssymbole bei starkem Herauszoomen ausblenden", + "prefs.hide_constraint_glyphs_zoomed_out_note": "Bindungssymbole verschwinden, wenn die Skizze so weit herausgezoomt ist, dass sie sie überladen würden. Aus: sie behalten bei jedem Zoom eine feste Bildschirmgröße." + }, + "he": { + "prefs.hide_constraint_glyphs_zoomed_out": "הסתרת סמלי אילוצים בהקטנה", + "prefs.hide_constraint_glyphs_zoomed_out_note": "סמלי האילוצים נעלמים כשהשרטוט מוקטן מספיק כדי שלא יעמיסו על התצוגה. כבוי: הם נשארים בגודל מסך קבוע בכל זום." + }, + "ja": { + "prefs.hide_constraint_glyphs_zoomed_out": "ズームアウト時に拘束グリフを隠す", + "prefs.hide_constraint_glyphs_zoomed_out_note": "スケッチを十分にズームアウトすると、拘束グリフは表示されず画面を散らかしません。オフ: ズームに関係なく固定の画面サイズのままです。" + }, + "ko": { + "prefs.hide_constraint_glyphs_zoomed_out": "축소 시 구속 조건 기호 숨기기", + "prefs.hide_constraint_glyphs_zoomed_out_note": "스케치를 충분히 축소하면 구속 조건 기호가 가려지지 않도록 숨깁니다. 끄기: 확대/축소와 관계없이 고정된 화면 크기를 유지합니다." + }, + "vi": { + "prefs.hide_constraint_glyphs_zoomed_out": "Ẩn biểu tượng ràng buộc khi thu nhỏ", + "prefs.hide_constraint_glyphs_zoomed_out_note": "Biểu tượng ràng buộc biến mất khi bản phác được thu nhỏ đủ xa để không làm rối khung nhìn. Tắt: chúng giữ kích thước màn hình cố định ở mọi mức thu phóng." + }, + "zh": { + "prefs.hide_constraint_glyphs_zoomed_out": "缩小时隐藏约束符号", + "prefs.hide_constraint_glyphs_zoomed_out_note": "草图缩小到一定程度时隐藏约束符号,以免遮挡草图。关闭:任意缩放比例下符号仍保持固定屏幕大小。" + } +} diff --git a/crates/ui-egui/src/prefs.rs b/crates/ui-egui/src/prefs.rs index 819f32897..0963d2757 100644 --- a/crates/ui-egui/src/prefs.rs +++ b/crates/ui-egui/src/prefs.rs @@ -1350,6 +1350,10 @@ preference_settings! { /// holds, and its glyph or dimension, are drawn in `sketch_conflict` (#7244). Off: only the /// glyphs and dimensions are red, in `error`, as before. sketch_conflict_colour: bool = true, PAGE_SKETCH => check_id("prefs.sketch_conflict_colour"); + /// Hide constraint glyphs when the sketch is zoomed out so far that a millimetre of the plane + /// is smaller than `sketch_tools::MIN_GLYPH_PX_PER_MM` on screen (#8980). Off: glyphs stay at a + /// fixed screen size at every zoom, as before. + hide_constraint_glyphs_zoomed_out: bool = true, PAGE_SKETCH => check_id("prefs.hide_constraint_glyphs_zoomed_out"); /// Drive Joints shows the moved parts' old place as a ghost (its Show ghost box, #5905). drive_joints_ghost: bool = true, PAGE_DESIGN; /// Plugin ids turned off (Preferences › Plugins). An installed plugin whose id is absent is on. @@ -5037,6 +5041,7 @@ mod tests { ("selection_shift_add_only", json!(true), PAGE_SKETCH), ("select_other_hidden", json!(false), PAGE_SKETCH), ("sketch_conflict_colour", json!(false), PAGE_SKETCH), + ("hide_constraint_glyphs_zoomed_out", json!(false), PAGE_SKETCH), ("suppress_sketch_snap", json!(ModifierCombo::NONE), PAGE_SKETCH), ("sketch_state_icons", json!(false), PAGE_SKETCH), ("sketch_tracking_guides", json!(false), PAGE_SKETCH), diff --git a/crates/ui-egui/src/prefs/sketch.rs b/crates/ui-egui/src/prefs/sketch.rs index 46f3755ed..2cd6c76dd 100644 --- a/crates/ui-egui/src/prefs/sketch.rs +++ b/crates/ui-egui/src/prefs/sketch.rs @@ -76,6 +76,9 @@ pub(super) fn show(app: &mut SolveApp, ui: &mut egui::Ui) { // Conflicting curves and points in the conflict colour (#7244). let check = setting::sketch_conflict_colour(app, ui).on_hover_text(app.tr("prefs.sketch_conflict_colour_note")); crate::scenario::publish_target("prefs:sketch_conflict_colour", check.rect); + // Constraint glyphs hide when zoomed out (#8980). + let check = setting::hide_constraint_glyphs_zoomed_out(app, ui).on_hover_text(app.tr("prefs.hide_constraint_glyphs_zoomed_out_note")); + crate::scenario::publish_target("prefs:hide_constraint_glyphs_zoomed_out", check.rect); }); ui_kit::settings_section(ui, "selection", app.tr("prefs.selecting"), |ui| { ui_kit::checkbox(ui, crate::i18n::tr_label("Click selects whole bodies"), &mut app.ui.pick_bodies); diff --git a/crates/ui-egui/src/sketch_tools.rs b/crates/ui-egui/src/sketch_tools.rs index b1ac1975f..870102fc9 100644 --- a/crates/ui-egui/src/sketch_tools.rs +++ b/crates/ui-egui/src/sketch_tools.rs @@ -9,7 +9,7 @@ use std::cell::{Cell, RefCell}; use egui::{Pos2, Stroke}; use serde_json::{Value, json}; -use solidcraft_engine::geom::{Vec2, Vec3}; +use solidcraft_engine::geom::{Plane, Vec2, Vec3}; use crate::SolveApp; use crate::tool_modifiers::{Audit, Binding, Match, ModAction, ModifierCombo, Scope, ToolModifiers, Trigger}; @@ -1515,6 +1515,23 @@ pub fn preview(app: &SolveApp, t: &Tool, painter: &egui::Painter, proj: &Proj) { /// Glyph size and spacing (screen pixels). const GLYPH: f32 = 15.0; +/// Screen pixels per millimetre of the sketch plane below which constraint glyphs hide when the +/// `hide_constraint_glyphs_zoomed_out` preference is on (#8980). About two pixels per millimetre: +/// a 10 mm feature is then smaller than a glyph. +pub const MIN_GLYPH_PX_PER_MM: f32 = 2.0; + +/// Whether constraint glyphs should draw at this sketch-plane scale (#8980). +pub fn constraint_glyphs_visible_at_scale(px_per_mm: f32, hide_when_zoomed_out: bool) -> bool { + !hide_when_zoomed_out || px_per_mm >= MIN_GLYPH_PX_PER_MM +} + +/// Pixels on screen for one millimetre along the sketch plane's U axis, near the plane origin. +fn sketch_px_per_mm(plane: &Plane, proj: &Proj) -> Option { + let a = proj.to_screen(plane.to_world(Vec2::ZERO))?; + let b = proj.to_screen(plane.to_world(Vec2::new(1.0, 0.0)))?; + Some(a.distance(b)) +} + fn glyphs(app: &SolveApp, painter: &egui::Painter, proj: &Proj, hover: Option) { let Some(sid) = active_sketch(app) else { return }; let st = app.session.world_state(); @@ -1523,6 +1540,13 @@ fn glyphs(app: &SolveApp, painter: &egui::Painter, proj: &Proj, hover: Option