Skip to main content

mirror

Function mirror 

Source
pub fn mirror(c: Color) -> Color
Expand description

A colour’s counterpart in a theme of the other scheme, light for dark: the same OkHsl hue and saturation (the chroma, as far as the sRGB gamut holds it at the new lightness), the lightness mirrored (1 - l), the alpha kept. Black and white swap, a mid grey stays; mirrored twice, a colour comes back (to within rounding), unless a mirror was clipped: near the cusp of its hue (the most saturated colours, #0000ff), the mirrored colour can lie just outside the sRGB gamut, and is clipped to it channel by channel, so its hue is kept but its saturation and lightness move a little, and mirroring it back does not give the colour it came from. What the theme editor’s “Generate the other variant” does to a colour (crate::ThemeDraft::generate_counterpart).

use egui_pop_tokens::{Color, palette};

let white = palette::mirror(Color::BLACK);
assert_eq!(white.to_hex(), "#ffffff");
let deep = Color::from_hex("#1a3a6e").unwrap();
let pale = palette::mirror(deep);
assert!(deep.is_dark() && !pale.is_dark());