Skip to content

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

Merge PR #6837: Hue/Saturation: hue tracks and spectrum bars use full-strength sRGB hues, one shared hue_color (#6540)

aiongg7e6027f71d4b
diff --cc crates/ui-egui/src/widgets.rs
index 212a9ff80,051fa7601..753214431
--- a/crates/ui-egui/src/widgets.rs
+++ b/crates/ui-egui/src/widgets.rs
@@@ -1891,35 -1777,21 +1893,48 @@@ fn clean(text: &str) -> String
#[cfg(test)]
mod tests {
- use egui::{Key, Modifiers};
+ use super::{hue_color, hue_stops};
+ use egui::{Color32, Key, Modifiers};
+
+ #[test]
+ fn hue_stops_are_pure_and_evenly_spaced() {
+ let c = |r, g, b| Color32::from_rgb(r, g, b);
+ let want = [c(255, 0, 0), c(255, 255, 0), c(0, 255, 0), c(0, 255, 255), c(0, 0, 255), c(255, 0, 255), c(255, 0, 0)];
+ let stops = hue_stops();
+ assert_eq!(stops.len(), 13);
+ for (k, w) in want.iter().enumerate() {
+ assert_eq!(stops[k * 2], *w, "stop at {} degrees", k * 60);
+ assert_eq!(hue_color(k as f32 * 60.0), *w);
+ }
+ }
+ /// 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;