* 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 <noreply@anthropic.com> 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 <noreply@anthropic.com>
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user