From 7895c14e3f9000b79d924b1c8bc4ffe3bccf74df Mon Sep 17 00:00:00 2001 From: sascha2101 Date: Tue, 27 Oct 2026 12:29:55 +0000 Subject: [PATCH] Preferences: the Colour vision preview shows the chosen mode again (#7152) (#7169) * claim: #7152 * Preferences: the Colour vision preview shows the chosen mode again (#7152) Since the preferences redesign the Colour vision section previewed a mode with four status chips (Selected, Warning, Error, Done). No colour vision mode changes those colours, so the chips looked the same in every mode. The section shows the sample of what the modes recolour again (sketch lines, axes, bends, Draft Analysis, a failed feature), drawn in the mode being chosen (Tokens::get_in). The status chips stay as they are. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01FN5eEMrqWWXqi65FcK8GXq --------- Co-authored-by: sascha2101 <221609842+sascha2101@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 --- crates/ui-egui/src/colour_vision_tests.rs | 33 +++++++++++++++++++++++ crates/ui-egui/src/prefs/interface.rs | 3 +++ crates/ui-egui/src/theme.rs | 10 +++++-- crates/ui-egui/src/ui_kit/preferences.rs | 5 ++-- 4 files changed, 46 insertions(+), 5 deletions(-) diff --git a/crates/ui-egui/src/colour_vision_tests.rs b/crates/ui-egui/src/colour_vision_tests.rs index b1559249a..9b54848c7 100644 --- a/crates/ui-egui/src/colour_vision_tests.rs +++ b/crates/ui-egui/src/colour_vision_tests.rs @@ -965,6 +965,39 @@ fn ui_prefs_sets_each_mode_and_refuses_anything_else() { /// Random values (fixed seed): strings near the four ids and far from them, numbers, nesting. /// `ui.prefs` takes exactly the four ids and refuses the rest without a change; saved /// preferences load every value, unknown ones as Off. Nothing panics. +/// The section previews the mode being chosen (#7152): the sample's lines take that mode's +/// colours. The status chips beside it keep theirs in every mode. +#[test] +fn the_sample_previews_the_mode_being_chosen() { + let mut h = crate::scenario::Harness::new(); + crate::prefs::control(&mut h.app, &json!({"open": "Interface"})).unwrap(); + let lines = |h: &crate::scenario::Harness| { + let mut out = BTreeSet::new(); + for s in &h.shapes { + crate::test_support::each_shape(&s.shape, &mut |shape| { + if let egui::Shape::LineSegment { stroke, .. } = shape { + out.insert(stroke.color.to_array()); + } + }); + } + out + }; + for mode in [ColorVision::Protan, ColorVision::Tritan, ColorVision::Off] { + crate::prefs::control(&mut h.app, &json!({"color_vision": mode.id()})).unwrap(); + h.frames(2); + let (want, off) = (Tokens::get_in(mode), Tokens::get_in(ColorVision::Off)); + let painted = lines(&h); + for (name, c) in [("axis_x", want.axis_x), ("axis_y", want.axis_y), ("sketch_locked", want.sketch_locked)] { + assert!(painted.contains(&c.to_array()), "{mode:?}: the sample draws {name} {c:?}"); + } + if mode != ColorVision::Off { + let changed = [(want.axis_x, off.axis_x), (want.sketch_locked, off.sketch_locked)]; + assert!(changed.iter().any(|(a, b)| a != b), "{mode:?} recolours what the sample shows"); + } + } + crate::prefs::control(&mut h.app, &json!({"button": "cancel"})).unwrap(); +} + #[test] fn random_values_never_panic_and_only_the_four_ids_are_taken() { fn value(next: &mut impl FnMut() -> u64, depth: u32) -> serde_json::Value { diff --git a/crates/ui-egui/src/prefs/interface.rs b/crates/ui-egui/src/prefs/interface.rs index 3f8660ba8..c9665e7f0 100644 --- a/crates/ui-egui/src/prefs/interface.rs +++ b/crates/ui-egui/src/prefs/interface.rs @@ -201,6 +201,9 @@ pub(super) fn interface(app: &mut SolveApp, ui: &mut egui::Ui, t: &Tokens) { } ui_kit::status_palette_sample(ui, app.preferences.color_vision); }); + // What the modes recolour, in the mode being chosen (#7152): the status chips above keep + // their colours in every mode. + ui_kit::colour_vision_sample(ui, &crate::theme::Tokens::get_in(app.preferences.color_vision)); if app.preferences.color_vision != mode { ui.ctx().request_repaint(); } diff --git a/crates/ui-egui/src/theme.rs b/crates/ui-egui/src/theme.rs index c1c859197..71086dba5 100644 --- a/crates/ui-egui/src/theme.rs +++ b/crates/ui-egui/src/theme.rs @@ -840,8 +840,14 @@ impl Tokens { /// The tokens of the current theme and colour vision mode, the colours drawn in the 3D view /// from the view's own dark or light ([`viewport_dark`]). pub fn get() -> Tokens { - let window = Tokens::themed(is_dark(), vision()); - if viewport_dark() == is_dark() { window } else { window.with_viewport(Tokens::themed(viewport_dark(), vision())) } + Tokens::get_in(vision()) + } + + /// [`Tokens::get`] in another colour vision mode: the Colour vision preference previews the + /// mode being chosen before it is applied (#7152). + pub fn get_in(mode: ColorVision) -> Tokens { + let window = Tokens::themed(is_dark(), mode); + if viewport_dark() == is_dark() { window } else { window.with_viewport(Tokens::themed(viewport_dark(), mode)) } } /// The tokens of the 3D view's side (#4146), for a window colour drawn straight onto the view diff --git a/crates/ui-egui/src/ui_kit/preferences.rs b/crates/ui-egui/src/ui_kit/preferences.rs index c42763b7a..7c2799546 100644 --- a/crates/ui-egui/src/ui_kit/preferences.rs +++ b/crates/ui-egui/src/ui_kit/preferences.rs @@ -641,14 +641,13 @@ pub(crate) fn status_palette_sample(ui: &mut Ui, mode: ColorVision) { } /// The names under the Colour vision sample (message ids). -#[cfg(test)] pub(crate) const COLOUR_VISION_SAMPLE: [&str; 6] = ["ui.colour_vision_fixed", "ui.colour_vision_projected", "ui.axes", "Bends", "ui.draft", "ui.colour_vision_failed"]; /// The Colour vision sample (#778): fixed and projected sketch lines, the X and Y axes, bends up /// and down, Draft Analysis and a failed feature, each drawn as it is where it appears, in the -/// colours on now. The six cells share one responsive, clipped area. -#[cfg(test)] +/// colours of `t` (the preference passes the mode being chosen, #7152). The six cells share one +/// responsive, clipped area. pub(crate) fn colour_vision_sample(ui: &mut egui::Ui, t: &Tokens) { let width = (dimension(ui.available_width()) / COLOUR_VISION_SAMPLE.len() as f32).min(t.space_24 * 3.0); let line_width = t.space_4;