Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions assets/locales/pending/fade-other-component-sketches.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"en": {
"prefs.fade_other_component_sketches": "Fade sketches of other components",
"prefs.fade_other_component_sketches_help": "With a component active, draw sketches that belong to other components greyed out, like their bodies"
},
"de": {
"prefs.fade_other_component_sketches": "Skizzen anderer Komponenten abblenden",
"prefs.fade_other_component_sketches_help": "Bei aktiver Komponente Skizzen anderer Komponenten ausgegraut zeichnen, wie ihre Körper"
},
"nl": {
"prefs.fade_other_component_sketches": "Schetsen van andere componenten vervagen",
"prefs.fade_other_component_sketches_help": "Teken schetsen van andere componenten grijs wanneer een component actief is, net als hun lichamen"
},
"ja": {
"prefs.fade_other_component_sketches": "他のコンポーネントのスケッチを淡色表示",
"prefs.fade_other_component_sketches_help": "コンポーネントがアクティブなとき、他のコンポーネントのスケッチをボディと同様にグレーで表示します"
},
"zh": {
"prefs.fade_other_component_sketches": "淡化其他组件的草图",
"prefs.fade_other_component_sketches_help": "组件处于活动状态时,将属于其他组件的草图以灰色绘制,与其实体相同"
},
"ko": {
"prefs.fade_other_component_sketches": "다른 구성요소의 스케치 흐리게 표시",
"prefs.fade_other_component_sketches_help": "구성요소가 활성화되면 다른 구성요소에 속한 스케치를 바디처럼 회색으로 그립니다"
},
"vi": {
"prefs.fade_other_component_sketches": "Làm mờ phác thảo của các thành phần khác",
"prefs.fade_other_component_sketches_help": "Khi một thành phần đang hoạt động, vẽ các phác thảo thuộc thành phần khác bằng màu xám, giống như các khối của chúng"
},
"ar": {
"prefs.fade_other_component_sketches": "تعتيم رسومات المكونات الأخرى",
"prefs.fade_other_component_sketches_help": "عند تنشيط مكوّن، ارسم الرسومات التابعة للمكونات الأخرى باللون الرمادي، مثل أجسامها"
},
"he": {
"prefs.fade_other_component_sketches": "עמעום סקיצות של רכיבים אחרים",
"prefs.fade_other_component_sketches_help": "כאשר רכיב פעיל, ציור סקיצות השייכות לרכיבים אחרים באפור, כמו הגופים שלהם"
}
}
3 changes: 3 additions & 0 deletions crates/ui-egui/src/prefs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1207,6 +1207,9 @@ preference_settings! {
frame_rate_details: bool = false, PAGE_GRAPHICS;
/// Draw a wider rim under finished sketch curves to improve contrast on shaded faces.
sketch_halo: bool = false, PAGE_GRAPHICS => check("Halo under sketch curves");
/// With a component active, sketches of other components are drawn greyed out and faint, as
/// their bodies are. Off: every sketch is drawn in full colour whatever is active, as before.
fade_other_component_sketches: bool = true, PAGE_GRAPHICS => check_id("prefs.fade_other_component_sketches");
/// Show the view's pitch, yaw and roll and its projection under the orientation gizmo (#6032).
/// Off by default; View ▸ View angles and `view.angle_readout` turn it on.
show_view_angles: bool = false, PAGE_GRAPHICS;
Expand Down
2 changes: 2 additions & 0 deletions crates/ui-egui/src/prefs/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ pub(super) fn show(app: &mut SolveApp, ui: &mut egui::Ui) {
.backing_on_hover_text(app.tr("ui.cosmetic_thread_markings_help"));
crate::scenario::publish_target("prefs:cosmetic_threads", response.rect);
setting::sketch_halo(app, ui);
let fade = setting::fade_other_component_sketches(app, ui).backing_on_hover_text(app.tr("prefs.fade_other_component_sketches_help"));
crate::scenario::publish_target("prefs:fade_other_component_sketches", fade.rect);
ui_kit::row(ui, app.tr("prefs.section_hatch"), |ui| {
let styles = [crate::prefs::SectionHatch::One, crate::prefs::SectionHatch::ByPart];
let mut selected = styles.iter().position(|s| *s == app.preferences.section_hatch).unwrap_or(1);
Expand Down
69 changes: 65 additions & 4 deletions crates/ui-egui/src/viewport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,8 @@ fn sketch_scene_key(app: &SolveApp, proj: &Proj) -> u64 {
// Finished sketches are drawn over the bodies when the preference says so.
app.preferences.reference_geometry_through_bodies.hash(&mut h);
app.preferences.sketch_halo.hash(&mut h);
// Sketches of other components than the active one are greyed out when the preference says so.
app.preferences.fade_other_component_sketches.hash(&mut h);
// The grid previews the plane Create Sketch would take (#6975).
previewed_sketch_plane(app).map(|p| [p.origin, p.x, p.y].map(|v| [v.x, v.y, v.z].map(f64::to_bits))).hash(&mut h);
// Conflicting curves in their own colour, or as before (#7244).
Expand Down Expand Up @@ -726,6 +728,43 @@ fn sketch_color(t: &Tokens, c: Rgb) -> [u8; 4] {
}
}

/// With a component active, a finished sketch that belongs to another component (one that is not
/// the active component or inside it) is drawn greyed out and faint, as its bodies are. The sketch
/// being edited never is. Off with the `fade_other_component_sketches` preference.
pub(crate) fn sketch_faded(app: &SolveApp, sid: u64) -> bool {
let s = &app.session;
app.preferences.fade_other_component_sketches
&& s.active_sketch != Some(sid)
&& s.active_component != 0
&& s.doc.feature(sid).is_some_and(|f| !s.doc.component_within(f.component, s.active_component))
}

/// How faint a sketch of another component is drawn (its colour's share of its alpha).
const FADED_SKETCH_ALPHA: f64 = 0.4;

/// A sketch colour greyed out for a sketch of another component: its own lightness with no hue,
/// at [`FADED_SKETCH_ALPHA`] of its alpha. Derived from the theme's colour, so every theme and
/// colour-vision mode keeps its contrast.
fn faded_sketch_colour(c: [u8; 4]) -> [u8; 4] {
let [r, g, b, a] = c.map(f64::from);
let grey = (0.299 * r + 0.587 * g + 0.114 * b).round().clamp(0.0, 255.0) as u8;
[grey, grey, grey, (a * FADED_SKETCH_ALPHA).round().clamp(0.0, 255.0) as u8]
}

/// How strongly a hovered sketch of another component draws its outline (its hover colour's
/// share of its alpha): softer than its fill's brightening would suggest.
const FADED_HOVER_EDGE_ALPHA: f32 = 0.5;

/// Hover feedback for a sketch of another component: a light neutral grey in place of the
/// theme's hover hue, near white, so the hovered area brightens a little instead of lighting up
/// in colour. Keeps `c`'s alpha times `alpha`, so it is as subtle as the theme's own hover.
fn faded_hover_colour(c: Color32, alpha: f32) -> Color32 {
let [r, g, b, a] = c.to_srgba_unmultiplied().map(f32::from);
let lightness = 0.299 * r + 0.587 * g + 0.114 * b;
let grey = (255.0 - (255.0 - lightness) / 6.0).round().clamp(0.0, 255.0) as u8;
Color32::from_rgba_unmultiplied(grey, grey, grey, (a * alpha).round().clamp(0.0, 255.0) as u8)
}

pub(crate) type ActiveBodyNames = std::sync::Arc<std::collections::HashSet<String>>;

struct ActiveBodies {
Expand Down Expand Up @@ -2025,6 +2064,9 @@ pub(crate) fn build_sketch_scene(app: &SolveApp, proj: &Proj) -> GpuScene {
let active = s.active_sketch == Some(sid);
let typed = typed.as_ref().filter(|_| active);
let Some(ss) = typed.unwrap_or(&st).sketch(sid) else { continue };
// A sketch of another component than the active one is greyed out and faint, like that
// component's bodies, so the active component's own sketches stand out.
let faded = sketch_faded(app, sid);
// Its curves are sampled before its profiles, which share their budget: past it a fill
// goes missing rather than a curve.
let mut typed_curves: std::collections::HashMap<usize, Vec<Vec<Vec3>>> = match typed {
Expand All @@ -2037,7 +2079,7 @@ pub(crate) fn build_sketch_scene(app: &SolveApp, proj: &Proj) -> GpuScene {
// Closed profiles are shaded (lifted off a face they may lie on).
let lift = ss.plane.normal() * 0.01;
let profiles = if app.session.visibility.hidden_profiles.contains(&sid) || ss.sketch.view.hide_profile { &[][..] } else { &ss.profiles[..] };
let profile_fill = sc.color(c4(tk.profile_fill));
let profile_fill = sc.color(if faded { faded_sketch_colour(c4(tk.profile_fill)) } else { c4(tk.profile_fill) });
for (index, profile) in profiles.iter().enumerate() {
let (sampled, cached);
let display = if typed.is_some() {
Expand Down Expand Up @@ -2075,8 +2117,9 @@ pub(crate) fn build_sketch_scene(app: &SolveApp, proj: &Proj) -> GpuScene {
for (k, (pts, col, cons)) in lines.into_iter().enumerate() {
let conflicting = owners.get(k).is_some_and(|&curve| conflict.curve(curve));
let segs = sketch_segments(&pts, sketch_line_mode(col, cons), unit);
let haloed = app.preferences.sketch_halo && !active && col != colors::SKETCH_PROJECTED && col != colors::SKETCH_LOST;
let haloed = app.preferences.sketch_halo && !active && !faded && col != colors::SKETCH_PROJECTED && col != colors::SKETCH_LOST;
let colour = if conflicting { c4(tk.sketch_conflict) } else { sketch_color(&tk, col) };
let colour = if faded { faded_sketch_colour(colour) } else { colour };
strokes.push((segs, sc.color(colour), if cons { 1.2 } else { 2.0 }, haloed));
}
// Active sketches retain their existing through-body display. Inactive sketches
Expand Down Expand Up @@ -3984,6 +4027,8 @@ fn highlight_geometry_key(app: &SolveApp) -> u64 {
app.viewport.gpu.is_some_and(|g| g.tess).hash(&mut h);
app.session.active_component.hash(&mut h);
app.session.active_occurrence_path.hash(&mut h);
// A hovered sketch of another component lights grey when the preference greys it.
app.preferences.fade_other_component_sketches.hash(&mut h);
app.ui.visual_style.hash(&mut h);
crate::render_workspace::assign::preview_key(app).hash(&mut h);
app.ui.pick_bodies.hash(&mut h);
Expand Down Expand Up @@ -4696,7 +4741,14 @@ pub(crate) fn build_highlight(app: &SolveApp) -> GpuScene {
if !sel.iter().any(|x| matches!(x, Sel::Profile { sketch: s2, index: i2 } if s2 == sketch && i2 == index))
&& crate::dim_view::previewed_sketch(app) != Some(*sketch) =>
{
profile_fill(&mut feedback, app, *sketch, *index, t.hover_profile, t.hover_profile_edge);
// A sketch of another component only brightens a little: a light neutral fill, no
// hover hue.
let (fill, edge) = if sketch_faded(app, *sketch) {
(faded_hover_colour(t.hover_profile, 1.0), faded_hover_colour(t.hover_profile_edge, FADED_HOVER_EDGE_ALPHA))
} else {
(t.hover_profile, t.hover_profile_edge)
};
profile_fill(&mut feedback, app, *sketch, *index, fill, edge);
}
_ => {}
}
Expand Down Expand Up @@ -6864,11 +6916,20 @@ fn hover_highlight(app: &SolveApp, painter: &egui::Painter, proj: &Proj) {
// the design: a highlight there would trace a curve where none is drawn. Other sketches are
// drawn where they are.
let previewed = crate::dim_view::previewed_sketch(app);
let col = Tokens::get().hover_profile_edge;
let st = crate::open_meshing::shown_world(app);
let hover = app.viewport.hover.as_ref().filter(|h| {
!matches!(h, Hit::SketchCurve { sketch, .. } | Hit::SketchMidpoint { sketch, .. } | Hit::SketchPoint { sketch, .. } if previewed == Some(*sketch))
});
// A sketch of another component lights a soft grey, not the hover hue, as its fill does.
let edge = Tokens::get().hover_profile_edge;
let col = match hover {
Some(Hit::SketchCurve { sketch, .. } | Hit::SketchMidpoint { sketch, .. } | Hit::SketchPoint { sketch, .. })
if sketch_faded(app, *sketch) =>
{
faded_hover_colour(edge, FADED_HOVER_EDGE_ALPHA)
}
_ => edge,
};
match hover {
// Trim shows the piece it would take away instead (`sketch_tools::preview`, #3052).
Some(Hit::SketchCurve { sketch, id, .. }) if crate::sketch_tools::trim_hover_piece(app, *sketch, id).is_some() => {}
Expand Down
53 changes: 53 additions & 0 deletions crates/ui-egui/src/viewport_appearance_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,59 @@ fn a_finished_sketch_on_a_face_draws_a_halo_under_its_own_curves_only() {
theme::set_vision(original_vision);
}

/// With a component active, a finished sketch of another component is drawn greyed out and faint,
/// as that component's bodies are; the active component's own sketch keeps its colour. With the
/// design itself active, or with the preference off (the old look), nothing is greyed.
#[test]
fn sketches_of_other_components_are_greyed_out_while_a_component_is_active() {
let mut app = SolveApp::new(Session::default(), Services::default());
app.ui.ground_shadow = false;
app.set_origin_shown(false);
let a = app.run("component.create", json!({"name": "A"})).unwrap()["component"].as_u64().unwrap();
let sketch_a = app.run("sketch.create", json!({"plane": "XY", "name": "In A"})).unwrap()["sketch"].as_u64().unwrap();
app.run("sketch.line", json!({"points": [[0, 0], [10, 0]]})).unwrap();
app.run("sketch.finish", json!({})).unwrap();
app.run("component.activate", json!({"component": 0})).unwrap();
let b = app.run("component.create", json!({"name": "B"})).unwrap()["component"].as_u64().unwrap();
let sketch_b = app.run("sketch.create", json!({"plane": "XY", "name": "In B"})).unwrap()["sketch"].as_u64().unwrap();
app.run("sketch.line", json!({"points": [[0, 20], [10, 20]]})).unwrap();
app.run("sketch.finish", json!({})).unwrap();
assert_eq!(app.session.active_component, b);
assert!(app.preferences.fade_other_component_sketches, "on by default");

let rect = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(800.0, 600.0));
let finished = super::c4(crate::theme::Tokens::get().sketch_fixed);
let greyed = super::faded_sketch_colour(finished);
assert!(greyed[0] == greyed[1] && greyed[1] == greyed[2], "greyed out: no hue");
assert!(greyed[3] < finished[3], "and faint");
// Lines in the finished colour and in the greyed one.
let counts = |app: &SolveApp| {
let scene = super::build_sketch_scene(app, &super::projection(app, rect));
let (lines, _) = scene.lines.as_chunks::<{ crate::gpu::LINE_SIZE }>();
let count = |c: [u8; 4]| lines.iter().filter(|line| line_color(&scene, *line) == c).count();
(count(finished), count(greyed))
};

assert!(super::sketch_faded(&app, sketch_a) && !super::sketch_faded(&app, sketch_b));
let (full, faint) = counts(&app);
assert!(full > 0 && faint > 0, "B's sketch in its colour, A's greyed: {full} and {faint}");

let projection = super::projection(&app, rect);
let key = super::sketch_scene_key(&app, &projection);
crate::prefs::set(&mut app, &json!({"fade_other_component_sketches": false})).unwrap();
assert_ne!(super::sketch_scene_key(&app, &projection), key, "changing the preference rebuilds the sketch scene");
assert!(!super::sketch_faded(&app, sketch_a));
assert_eq!(counts(&app), (full + faint, 0), "off: every sketch in its own colour, as before");
crate::prefs::set(&mut app, &json!({"fade_other_component_sketches": true})).unwrap();

app.run("component.activate", json!({"component": a})).unwrap();
assert!(!super::sketch_faded(&app, sketch_a) && super::sketch_faded(&app, sketch_b), "the fade follows the active component");

app.run("component.activate", json!({"component": 0})).unwrap();
assert!(!super::sketch_faded(&app, sketch_a) && !super::sketch_faded(&app, sketch_b));
assert_eq!(counts(&app), (full + faint, 0), "with the design itself active nothing is greyed");
}

#[test]
fn placed_step_body_uses_imported_opacity_until_a_design_look_overrides_it() {
let body = kernel::box_solid(Vec3::ZERO, Vec3::new(10.0, 10.0, 10.0))
Expand Down
1 change: 1 addition & 0 deletions docs/design/preferences/pages/graphics.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Four toggle tiles, then a chip row.
|---|---|---|---|---|---|---|
| Cosmetic thread markings | Checkbox | `Prefs.cosmetic_threads` | `false` | none | none | |
| Halo under sketch curves | Checkbox | `Prefs.sketch_halo` | `false` | none | none | |
| Fade sketches of other components | Checkbox | `Prefs.fade_other_component_sketches` | `true` | none | none | |
| Reference geometry through bodies | Checkbox | `Prefs.reference_geometry_through_bodies` | `false` | none | none | |
| Grid follows the view | Checkbox | `Prefs.grid_follows_view` (no page id in the table today) | `false` | "Side views show the grid on the facing plane." | none | |
| Single surface analysis | Checkbox | `Prefs.single_surface_analysis` | `true` | "Shading and Continuity share one analysis." | none | |
Expand Down