Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

Preferences: the Colour vision preview shows the chosen mode again (#7152) (#7169)

sascha21017895c14e3f90
diff --git a/crates/ui-egui/src/colour_vision_tests.rs b/crates/ui-egui/src/colour_vision_tests.rs
index b1559249a8..9b54848c77 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 3f8660ba8d..c9665e7f0c 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 c1c8591976..71086dba59 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 c42763b7a3..7c27995467 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;