Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

test(ui-egui): light themes outline the slider knob at 3:1 (#7927)

Korg1ch3d3b67b74c5c
diff --git a/crates/ui-egui/src/theme.rs b/crates/ui-egui/src/theme.rs
index 2fcf13887..ea4340113 100644
--- a/crates/ui-egui/src/theme.rs
+++ b/crates/ui-egui/src/theme.rs
@@ -1274,6 +1274,32 @@ mod tests {
(hi + 0.05) / (lo + 0.05)
}
+ /// The light themes outline their white slider knob so its edge holds WCAG's 3:1 non-text
+ /// contrast against the panels sliders sit on (#7927); the dark ones keep the plain knob.
+ #[test]
+ fn light_themes_outline_the_slider_knob() {
+ for kind in ThemeKind::ALL {
+ let t = Tokens::for_kind(kind);
+ // The Pro layouts keep their dark ring (it rims a grey knob), Classic its bevelled knob.
+ if t.pro || t.bevel {
+ continue;
+ }
+ match t.knob_outline() {
+ Some(outline) => {
+ assert!(!t.dark(), "{kind:?}");
+ for panel in [t.dock, t.card, t.chrome] {
+ assert!(contrast(outline, panel) >= 3.0, "{kind:?}: knob outline {outline:?} on {panel:?}");
+ }
+ }
+ None => assert!(t.dark(), "{kind:?}: a light theme without a knob outline"),
+ }
+ }
+ assert_eq!(Tokens::for_kind(ThemeKind::Pro).knob_outline(), Some(Color32::from_gray(40)), "Pro is unchanged");
+ for kind in [ThemeKind::StudioLight, ThemeKind::Adwaita, ThemeKind::BreezeLight, ThemeKind::SoftLight] {
+ assert!(Tokens::for_kind(kind).knob_outline().is_some(), "{kind:?}");
+ }
+ }
+
#[test]
fn adwaita_themes_parse_and_meet_text_contrast() {
for kind in [ThemeKind::Adwaita, ThemeKind::AdwaitaDark] {
diff --git a/crates/ui-egui/src/widgets.rs b/crates/ui-egui/src/widgets.rs
index 11535fe84..c973d710d 100644
--- a/crates/ui-egui/src/widgets.rs
+++ b/crates/ui-egui/src/widgets.rs
@@ -1867,6 +1867,33 @@ fn clean(text: &str) -> String {
mod tests {
use egui::{Key, Modifiers};
+ /// A light theme rings the slider knob with its outline token; a dark Studio-layout one draws
+ /// the plain knob (#7927).
+ #[test]
+ fn light_themes_draw_the_slider_knob_outline() {
+ use crate::theme::{ThemeKind, Tokens};
+ fn rings(shape: &egui::Shape, out: &mut Vec<egui::Color32>) {
+ match shape {
+ egui::Shape::Vec(v) => v.iter().for_each(|s| rings(s, out)),
+ egui::Shape::Circle(c) if c.radius == 7.0 && c.stroke.width == 1.0 => out.push(c.stroke.color),
+ _ => {}
+ }
+ }
+ for kind in [ThemeKind::StudioLight, ThemeKind::Adwaita, ThemeKind::BreezeLight, ThemeKind::SoftLight, ThemeKind::Studio] {
+ let ctx = egui::Context::default();
+ crate::theme::apply(&ctx, kind);
+ let mut v = 50.0;
+ let mut out = ctx.run_ui(egui::RawInput::default(), |ui| {
+ super::slider(ui, &mut v, 0.0..=100.0, None);
+ });
+ out.textures_delta.clear();
+ let mut found = Vec::new();
+ out.shapes.iter().for_each(|c| rings(&c.shape, &mut found));
+ let want: Vec<_> = Tokens::for_kind(kind).knob_outline().into_iter().collect();
+ assert_eq!(found, want, "{kind:?}");
+ }
+ }
+
#[test]
fn checkbox_label_is_a_button_target_not_selectable_text() {
use egui::CursorIcon;