use frus_core::Color;
use crate::media::{Brightness, MediaQuery};
use crate::Theme;
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub enum CupertinoUserInterfaceLevelData {
#[default]
Base,
Elevated,
}
impl CupertinoUserInterfaceLevelData {
pub fn around<Msg: 'static>(
self,
child: impl crate::Widget<Msg> + 'static,
) -> crate::Themed<Msg> {
crate::Themed::tweak(move |t| t.user_interface_level = self, child)
}
pub fn of(theme: &Theme) -> Self {
theme.user_interface_level
}
}
#[derive(Clone, Copy, Debug)]
pub struct CupertinoDynamicColor {
pub color: Color,
pub dark_color: Color,
pub high_contrast_color: Color,
pub dark_high_contrast_color: Color,
pub elevated_color: Color,
pub dark_elevated_color: Color,
pub high_contrast_elevated_color: Color,
pub dark_high_contrast_elevated_color: Color,
pub debug_label: Option<&'static str>,
}
impl CupertinoDynamicColor {
#[allow(clippy::too_many_arguments)]
pub const fn new(
color: Color,
dark_color: Color,
high_contrast_color: Color,
dark_high_contrast_color: Color,
elevated_color: Color,
dark_elevated_color: Color,
high_contrast_elevated_color: Color,
dark_high_contrast_elevated_color: Color,
) -> Self {
Self {
color,
dark_color,
high_contrast_color,
dark_high_contrast_color,
elevated_color,
dark_elevated_color,
high_contrast_elevated_color,
dark_high_contrast_elevated_color,
debug_label: None,
}
}
pub const fn with_brightness_and_contrast(
color: Color,
dark_color: Color,
high_contrast_color: Color,
dark_high_contrast_color: Color,
) -> Self {
Self::new(
color,
dark_color,
high_contrast_color,
dark_high_contrast_color,
color,
dark_color,
high_contrast_color,
dark_high_contrast_color,
)
}
pub const fn with_brightness(color: Color, dark_color: Color) -> Self {
Self::new(
color, dark_color, color, dark_color, color, dark_color, color, dark_color,
)
}
#[must_use]
pub const fn labelled(mut self, label: &'static str) -> Self {
self.debug_label = Some(label);
self
}
pub fn resolve_with(
&self,
brightness: Brightness,
level: CupertinoUserInterfaceLevelData,
high_contrast: bool,
) -> Color {
use CupertinoUserInterfaceLevelData::{Base, Elevated};
match (brightness, level, high_contrast) {
(Brightness::Light, Base, false) => self.color,
(Brightness::Light, Base, true) => self.high_contrast_color,
(Brightness::Light, Elevated, false) => self.elevated_color,
(Brightness::Light, Elevated, true) => self.high_contrast_elevated_color,
(Brightness::Dark, Base, false) => self.dark_color,
(Brightness::Dark, Base, true) => self.dark_high_contrast_color,
(Brightness::Dark, Elevated, false) => self.dark_elevated_color,
(Brightness::Dark, Elevated, true) => self.dark_high_contrast_elevated_color,
}
}
pub fn resolve(&self, theme: &Theme) -> Color {
self.resolve_with(
crate::CupertinoTheme::brightness_of(theme),
theme.user_interface_level,
MediaQuery::of().accessibility.high_contrast,
)
}
}
impl PartialEq for CupertinoDynamicColor {
fn eq(&self, other: &Self) -> bool {
self.color == other.color
&& self.dark_color == other.dark_color
&& self.high_contrast_color == other.high_contrast_color
&& self.dark_high_contrast_color == other.dark_high_contrast_color
&& self.elevated_color == other.elevated_color
&& self.dark_elevated_color == other.dark_elevated_color
&& self.high_contrast_elevated_color == other.high_contrast_elevated_color
&& self.dark_high_contrast_elevated_color == other.dark_high_contrast_elevated_color
}
}
impl From<Color> for CupertinoDynamicColor {
fn from(c: Color) -> Self {
Self::with_brightness(c, c)
}
}
impl From<CupertinoDynamicColor> for Color {
fn from(c: CupertinoDynamicColor) -> Color {
c.color
}
}
pub struct CupertinoColors;
impl CupertinoColors {
pub const ACTIVE_BLUE: CupertinoDynamicColor = Self::SYSTEM_BLUE;
pub const ACTIVE_GREEN: CupertinoDynamicColor = Self::SYSTEM_GREEN;
pub const ACTIVE_ORANGE: CupertinoDynamicColor = Self::SYSTEM_ORANGE;
pub const WHITE: Color = Color::from_argb_u32(0xFFFFFFFF);
pub const BLACK: Color = Color::from_argb_u32(0xFF000000);
pub const TRANSPARENT: Color = Color::from_argb_u32(0x00000000);
pub const LIGHT_BACKGROUND_GRAY: Color = Color::from_argb_u32(0xFFE5E5EA);
pub const EXTRA_LIGHT_BACKGROUND_GRAY: Color = Color::from_argb_u32(0xFFEFEFF4);
pub const DARK_BACKGROUND_GRAY: Color = Color::from_argb_u32(0xFF171717);
pub const INACTIVE_GRAY: CupertinoDynamicColor = CupertinoDynamicColor::with_brightness(
Color::from_argb_u32(0xFF999999),
Color::from_argb_u32(0xFF757575),
)
.labelled("inactiveGray");
pub const DESTRUCTIVE_RED: CupertinoDynamicColor = Self::SYSTEM_RED;
pub const SYSTEM_BLUE: CupertinoDynamicColor =
CupertinoDynamicColor::with_brightness_and_contrast(
Color::rgba8(0, 122, 255, 255),
Color::rgba8(10, 132, 255, 255),
Color::rgba8(0, 64, 221, 255),
Color::rgba8(64, 156, 255, 255),
)
.labelled("systemBlue");
pub const SYSTEM_GREEN: CupertinoDynamicColor =
CupertinoDynamicColor::with_brightness_and_contrast(
Color::rgba8(52, 199, 89, 255),
Color::rgba8(48, 209, 88, 255),
Color::rgba8(36, 138, 61, 255),
Color::rgba8(48, 219, 91, 255),
)
.labelled("systemGreen");
pub const SYSTEM_MINT: CupertinoDynamicColor =
CupertinoDynamicColor::with_brightness_and_contrast(
Color::rgba8(0, 199, 190, 255),
Color::rgba8(99, 230, 226, 255),
Color::rgba8(12, 129, 123, 255),
Color::rgba8(102, 212, 207, 255),
)
.labelled("systemMint");
pub const SYSTEM_INDIGO: CupertinoDynamicColor =
CupertinoDynamicColor::with_brightness_and_contrast(
Color::rgba8(88, 86, 214, 255),
Color::rgba8(94, 92, 230, 255),
Color::rgba8(54, 52, 163, 255),
Color::rgba8(125, 122, 255, 255),
)
.labelled("systemIndigo");
pub const SYSTEM_ORANGE: CupertinoDynamicColor =
CupertinoDynamicColor::with_brightness_and_contrast(
Color::rgba8(255, 149, 0, 255),
Color::rgba8(255, 159, 10, 255),
Color::rgba8(201, 52, 0, 255),
Color::rgba8(255, 179, 64, 255),
)
.labelled("systemOrange");
pub const SYSTEM_PINK: CupertinoDynamicColor =
CupertinoDynamicColor::with_brightness_and_contrast(
Color::rgba8(255, 45, 85, 255),
Color::rgba8(255, 55, 95, 255),
Color::rgba8(211, 15, 69, 255),
Color::rgba8(255, 100, 130, 255),
)
.labelled("systemPink");
pub const SYSTEM_BROWN: CupertinoDynamicColor =
CupertinoDynamicColor::with_brightness_and_contrast(
Color::rgba8(162, 132, 94, 255),
Color::rgba8(172, 142, 104, 255),
Color::rgba8(127, 101, 69, 255),
Color::rgba8(181, 148, 105, 255),
)
.labelled("systemBrown");
pub const SYSTEM_PURPLE: CupertinoDynamicColor =
CupertinoDynamicColor::with_brightness_and_contrast(
Color::rgba8(175, 82, 222, 255),
Color::rgba8(191, 90, 242, 255),
Color::rgba8(137, 68, 171, 255),
Color::rgba8(218, 143, 255, 255),
)
.labelled("systemPurple");
pub const SYSTEM_RED: CupertinoDynamicColor =
CupertinoDynamicColor::with_brightness_and_contrast(
Color::rgba8(255, 59, 48, 255),
Color::rgba8(255, 69, 58, 255),
Color::rgba8(215, 0, 21, 255),
Color::rgba8(255, 105, 97, 255),
)
.labelled("systemRed");
pub const SYSTEM_TEAL: CupertinoDynamicColor =
CupertinoDynamicColor::with_brightness_and_contrast(
Color::rgba8(90, 200, 250, 255),
Color::rgba8(100, 210, 255, 255),
Color::rgba8(0, 113, 164, 255),
Color::rgba8(112, 215, 255, 255),
)
.labelled("systemTeal");
pub const SYSTEM_CYAN: CupertinoDynamicColor =
CupertinoDynamicColor::with_brightness_and_contrast(
Color::rgba8(50, 173, 230, 255),
Color::rgba8(100, 210, 255, 255),
Color::rgba8(0, 113, 164, 255),
Color::rgba8(112, 215, 255, 255),
)
.labelled("systemCyan");
pub const SYSTEM_YELLOW: CupertinoDynamicColor =
CupertinoDynamicColor::with_brightness_and_contrast(
Color::rgba8(255, 204, 0, 255),
Color::rgba8(255, 214, 10, 255),
Color::rgba8(160, 90, 0, 255),
Color::rgba8(255, 212, 38, 255),
)
.labelled("systemYellow");
pub const SYSTEM_GREY: CupertinoDynamicColor =
CupertinoDynamicColor::with_brightness_and_contrast(
Color::rgba8(142, 142, 147, 255),
Color::rgba8(142, 142, 147, 255),
Color::rgba8(108, 108, 112, 255),
Color::rgba8(174, 174, 178, 255),
)
.labelled("systemGrey");
pub const SYSTEM_GREY_2: CupertinoDynamicColor =
CupertinoDynamicColor::with_brightness_and_contrast(
Color::rgba8(174, 174, 178, 255),
Color::rgba8(99, 99, 102, 255),
Color::rgba8(142, 142, 147, 255),
Color::rgba8(124, 124, 128, 255),
)
.labelled("systemGrey2");
pub const SYSTEM_GREY_3: CupertinoDynamicColor =
CupertinoDynamicColor::with_brightness_and_contrast(
Color::rgba8(199, 199, 204, 255),
Color::rgba8(72, 72, 74, 255),
Color::rgba8(174, 174, 178, 255),
Color::rgba8(84, 84, 86, 255),
)
.labelled("systemGrey3");
pub const SYSTEM_GREY_4: CupertinoDynamicColor =
CupertinoDynamicColor::with_brightness_and_contrast(
Color::rgba8(209, 209, 214, 255),
Color::rgba8(58, 58, 60, 255),
Color::rgba8(188, 188, 192, 255),
Color::rgba8(68, 68, 70, 255),
)
.labelled("systemGrey4");
pub const SYSTEM_GREY_5: CupertinoDynamicColor =
CupertinoDynamicColor::with_brightness_and_contrast(
Color::rgba8(229, 229, 234, 255),
Color::rgba8(44, 44, 46, 255),
Color::rgba8(216, 216, 220, 255),
Color::rgba8(54, 54, 56, 255),
)
.labelled("systemGrey5");
pub const SYSTEM_GREY_6: CupertinoDynamicColor =
CupertinoDynamicColor::with_brightness_and_contrast(
Color::rgba8(242, 242, 247, 255),
Color::rgba8(28, 28, 30, 255),
Color::rgba8(235, 235, 240, 255),
Color::rgba8(36, 36, 38, 255),
)
.labelled("systemGrey6");
pub const LABEL: CupertinoDynamicColor = CupertinoDynamicColor::new(
Color::rgba8(0, 0, 0, 255),
Color::rgba8(255, 255, 255, 255),
Color::rgba8(0, 0, 0, 255),
Color::rgba8(255, 255, 255, 255),
Color::rgba8(0, 0, 0, 255),
Color::rgba8(255, 255, 255, 255),
Color::rgba8(0, 0, 0, 255),
Color::rgba8(255, 255, 255, 255),
)
.labelled("label");
pub const SECONDARY_LABEL: CupertinoDynamicColor = CupertinoDynamicColor::new(
Color::rgba8(60, 60, 67, 153),
Color::rgba8(235, 235, 245, 153),
Color::rgba8(60, 60, 67, 173),
Color::rgba8(235, 235, 245, 173),
Color::rgba8(60, 60, 67, 153),
Color::rgba8(235, 235, 245, 153),
Color::rgba8(60, 60, 67, 173),
Color::rgba8(235, 235, 245, 173),
)
.labelled("secondaryLabel");
pub const TERTIARY_LABEL: CupertinoDynamicColor = CupertinoDynamicColor::new(
Color::rgba8(60, 60, 67, 76),
Color::rgba8(235, 235, 245, 76),
Color::rgba8(60, 60, 67, 96),
Color::rgba8(235, 235, 245, 96),
Color::rgba8(60, 60, 67, 76),
Color::rgba8(235, 235, 245, 76),
Color::rgba8(60, 60, 67, 96),
Color::rgba8(235, 235, 245, 96),
)
.labelled("tertiaryLabel");
pub const QUATERNARY_LABEL: CupertinoDynamicColor = CupertinoDynamicColor::new(
Color::rgba8(60, 60, 67, 45),
Color::rgba8(235, 235, 245, 40),
Color::rgba8(60, 60, 67, 66),
Color::rgba8(235, 235, 245, 61),
Color::rgba8(60, 60, 67, 45),
Color::rgba8(235, 235, 245, 40),
Color::rgba8(60, 60, 67, 66),
Color::rgba8(235, 235, 245, 61),
)
.labelled("quaternaryLabel");
pub const SYSTEM_FILL: CupertinoDynamicColor = CupertinoDynamicColor::new(
Color::rgba8(120, 120, 128, 51),
Color::rgba8(120, 120, 128, 91),
Color::rgba8(120, 120, 128, 71),
Color::rgba8(120, 120, 128, 112),
Color::rgba8(120, 120, 128, 51),
Color::rgba8(120, 120, 128, 91),
Color::rgba8(120, 120, 128, 71),
Color::rgba8(120, 120, 128, 112),
)
.labelled("systemFill");
pub const SECONDARY_SYSTEM_FILL: CupertinoDynamicColor = CupertinoDynamicColor::new(
Color::rgba8(120, 120, 128, 40),
Color::rgba8(120, 120, 128, 81),
Color::rgba8(120, 120, 128, 61),
Color::rgba8(120, 120, 128, 102),
Color::rgba8(120, 120, 128, 40),
Color::rgba8(120, 120, 128, 81),
Color::rgba8(120, 120, 128, 61),
Color::rgba8(120, 120, 128, 102),
)
.labelled("secondarySystemFill");
pub const TERTIARY_SYSTEM_FILL: CupertinoDynamicColor = CupertinoDynamicColor::new(
Color::rgba8(118, 118, 128, 30),
Color::rgba8(118, 118, 128, 61),
Color::rgba8(118, 118, 128, 51),
Color::rgba8(118, 118, 128, 81),
Color::rgba8(118, 118, 128, 30),
Color::rgba8(118, 118, 128, 61),
Color::rgba8(118, 118, 128, 51),
Color::rgba8(118, 118, 128, 81),
)
.labelled("tertiarySystemFill");
pub const QUATERNARY_SYSTEM_FILL: CupertinoDynamicColor = CupertinoDynamicColor::new(
Color::rgba8(116, 116, 128, 20),
Color::rgba8(118, 118, 128, 45),
Color::rgba8(116, 116, 128, 40),
Color::rgba8(118, 118, 128, 66),
Color::rgba8(116, 116, 128, 20),
Color::rgba8(118, 118, 128, 45),
Color::rgba8(116, 116, 128, 40),
Color::rgba8(118, 118, 128, 66),
)
.labelled("quaternarySystemFill");
pub const PLACEHOLDER_TEXT: CupertinoDynamicColor = CupertinoDynamicColor::new(
Color::rgba8(60, 60, 67, 76),
Color::rgba8(235, 235, 245, 76),
Color::rgba8(60, 60, 67, 96),
Color::rgba8(235, 235, 245, 96),
Color::rgba8(60, 60, 67, 76),
Color::rgba8(235, 235, 245, 76),
Color::rgba8(60, 60, 67, 96),
Color::rgba8(235, 235, 245, 96),
)
.labelled("placeholderText");
pub const SYSTEM_BACKGROUND: CupertinoDynamicColor = CupertinoDynamicColor::new(
Color::rgba8(255, 255, 255, 255),
Color::rgba8(0, 0, 0, 255),
Color::rgba8(255, 255, 255, 255),
Color::rgba8(0, 0, 0, 255),
Color::rgba8(255, 255, 255, 255),
Color::rgba8(28, 28, 30, 255),
Color::rgba8(255, 255, 255, 255),
Color::rgba8(36, 36, 38, 255),
)
.labelled("systemBackground");
pub const SECONDARY_SYSTEM_BACKGROUND: CupertinoDynamicColor = CupertinoDynamicColor::new(
Color::rgba8(242, 242, 247, 255),
Color::rgba8(28, 28, 30, 255),
Color::rgba8(235, 235, 240, 255),
Color::rgba8(36, 36, 38, 255),
Color::rgba8(242, 242, 247, 255),
Color::rgba8(44, 44, 46, 255),
Color::rgba8(235, 235, 240, 255),
Color::rgba8(54, 54, 56, 255),
)
.labelled("secondarySystemBackground");
pub const TERTIARY_SYSTEM_BACKGROUND: CupertinoDynamicColor = CupertinoDynamicColor::new(
Color::rgba8(255, 255, 255, 255),
Color::rgba8(44, 44, 46, 255),
Color::rgba8(255, 255, 255, 255),
Color::rgba8(54, 54, 56, 255),
Color::rgba8(255, 255, 255, 255),
Color::rgba8(58, 58, 60, 255),
Color::rgba8(255, 255, 255, 255),
Color::rgba8(68, 68, 70, 255),
)
.labelled("tertiarySystemBackground");
pub const SYSTEM_GROUPED_BACKGROUND: CupertinoDynamicColor = CupertinoDynamicColor::new(
Color::rgba8(242, 242, 247, 255),
Color::rgba8(0, 0, 0, 255),
Color::rgba8(235, 235, 240, 255),
Color::rgba8(0, 0, 0, 255),
Color::rgba8(242, 242, 247, 255),
Color::rgba8(28, 28, 30, 255),
Color::rgba8(235, 235, 240, 255),
Color::rgba8(36, 36, 38, 255),
)
.labelled("systemGroupedBackground");
pub const SECONDARY_SYSTEM_GROUPED_BACKGROUND: CupertinoDynamicColor =
CupertinoDynamicColor::new(
Color::rgba8(255, 255, 255, 255),
Color::rgba8(28, 28, 30, 255),
Color::rgba8(255, 255, 255, 255),
Color::rgba8(36, 36, 38, 255),
Color::rgba8(255, 255, 255, 255),
Color::rgba8(44, 44, 46, 255),
Color::rgba8(255, 255, 255, 255),
Color::rgba8(54, 54, 56, 255),
)
.labelled("secondarySystemGroupedBackground");
pub const TERTIARY_SYSTEM_GROUPED_BACKGROUND: CupertinoDynamicColor =
CupertinoDynamicColor::new(
Color::rgba8(242, 242, 247, 255),
Color::rgba8(44, 44, 46, 255),
Color::rgba8(235, 235, 240, 255),
Color::rgba8(54, 54, 56, 255),
Color::rgba8(242, 242, 247, 255),
Color::rgba8(58, 58, 60, 255),
Color::rgba8(235, 235, 240, 255),
Color::rgba8(68, 68, 70, 255),
)
.labelled("tertiarySystemGroupedBackground");
pub const SEPARATOR: CupertinoDynamicColor = CupertinoDynamicColor::new(
Color::rgba8(60, 60, 67, 73),
Color::rgba8(84, 84, 88, 153),
Color::rgba8(60, 60, 67, 94),
Color::rgba8(84, 84, 88, 173),
Color::rgba8(60, 60, 67, 73),
Color::rgba8(210, 210, 210, 153),
Color::rgba8(60, 60, 67, 94),
Color::rgba8(84, 84, 88, 173),
)
.labelled("separator");
pub const OPAQUE_SEPARATOR: CupertinoDynamicColor = CupertinoDynamicColor::new(
Color::rgba8(198, 198, 200, 255),
Color::rgba8(56, 56, 58, 255),
Color::rgba8(198, 198, 200, 255),
Color::rgba8(56, 56, 58, 255),
Color::rgba8(198, 198, 200, 255),
Color::rgba8(56, 56, 58, 255),
Color::rgba8(198, 198, 200, 255),
Color::rgba8(56, 56, 58, 255),
)
.labelled("opaqueSeparator");
pub const LINK: CupertinoDynamicColor = CupertinoDynamicColor::new(
Color::rgba8(0, 122, 255, 255),
Color::rgba8(9, 132, 255, 255),
Color::rgba8(0, 122, 255, 255),
Color::rgba8(9, 132, 255, 255),
Color::rgba8(0, 122, 255, 255),
Color::rgba8(9, 132, 255, 255),
Color::rgba8(0, 122, 255, 255),
Color::rgba8(9, 132, 255, 255),
)
.labelled("link");
}
#[cfg(test)]
mod tests {
use super::{CupertinoColors as C, CupertinoDynamicColor, CupertinoUserInterfaceLevelData};
use crate::media::{Accessibility, Brightness, MediaQuery};
use crate::{build_ui, Container, Flex, Runtime, Theme, ThemeBuilder, Widget};
use frus_core::{Color, Primitive, Size};
use CupertinoUserInterfaceLevelData::{Base, Elevated};
#[derive(Clone, Debug, PartialEq)]
enum Msg {}
#[test]
fn each_condition_picks_its_value() {
let v: Vec<Color> = (0..8).map(|i| Color::rgb8(i * 10, 0, 0)).collect();
let c = CupertinoDynamicColor::new(v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7]);
let light = Brightness::Light;
let dark = Brightness::Dark;
assert_eq!(c.resolve_with(light, Base, false), v[0]);
assert_eq!(c.resolve_with(dark, Base, false), v[1]);
assert_eq!(c.resolve_with(light, Base, true), v[2]);
assert_eq!(c.resolve_with(dark, Base, true), v[3]);
assert_eq!(c.resolve_with(light, Elevated, false), v[4]);
assert_eq!(c.resolve_with(dark, Elevated, false), v[5]);
assert_eq!(c.resolve_with(light, Elevated, true), v[6]);
assert_eq!(c.resolve_with(dark, Elevated, true), v[7]);
assert_eq!(Color::from(c), v[0]);
}
#[test]
fn the_shorter_constructors_fill_the_other_axes() {
let [a, b, c, d] = [1, 2, 3, 4].map(|i| Color::rgb8(i, 0, 0));
assert_eq!(
CupertinoDynamicColor::with_brightness_and_contrast(a, b, c, d),
CupertinoDynamicColor::new(a, b, c, d, a, b, c, d)
);
assert_eq!(
CupertinoDynamicColor::with_brightness(a, b),
CupertinoDynamicColor::new(a, b, a, b, a, b, a, b)
);
assert_eq!(
CupertinoDynamicColor::with_brightness(a, b).labelled("ink"),
CupertinoDynamicColor::with_brightness(a, b)
);
}
#[test]
fn the_palette_is_the_reference_s() {
let rgba = Color::rgba8;
assert_eq!(
C::SYSTEM_BLUE,
CupertinoDynamicColor::with_brightness_and_contrast(
rgba(0, 122, 255, 255),
rgba(10, 132, 255, 255),
rgba(0, 64, 221, 255),
rgba(64, 156, 255, 255),
)
);
assert_eq!(C::SYSTEM_BLUE.debug_label, Some("systemBlue"));
assert_eq!(C::ACTIVE_BLUE, C::SYSTEM_BLUE);
assert_eq!(C::ACTIVE_GREEN, C::SYSTEM_GREEN);
assert_eq!(C::ACTIVE_ORANGE, C::SYSTEM_ORANGE);
assert_eq!(C::DESTRUCTIVE_RED, C::SYSTEM_RED);
assert_eq!(C::SECONDARY_LABEL.color, rgba(60, 60, 67, 153));
assert_eq!(
C::SECONDARY_LABEL.dark_high_contrast_color,
rgba(235, 235, 245, 173)
);
assert_eq!(C::SYSTEM_BACKGROUND.dark_color, rgba(0, 0, 0, 255));
assert_eq!(
C::SYSTEM_BACKGROUND.dark_elevated_color,
rgba(28, 28, 30, 255)
);
assert_eq!(
C::SYSTEM_BACKGROUND.dark_high_contrast_elevated_color,
rgba(36, 36, 38, 255)
);
assert_eq!(C::SEPARATOR.dark_elevated_color, rgba(210, 210, 210, 153));
assert_eq!(C::SYSTEM_GREY_6.color, rgba(242, 242, 247, 255));
assert_eq!(
C::INACTIVE_GRAY.dark_color,
Color::from_argb_u32(0xFF757575)
);
assert_eq!(
C::EXTRA_LIGHT_BACKGROUND_GRAY,
Color::from_argb_u32(0xFFEFEFF4)
);
}
#[test]
fn resolve_reads_the_theme_and_the_surface() {
let bg = C::SYSTEM_BACKGROUND;
assert_eq!(bg.resolve(&Theme::light()), bg.color);
assert_eq!(bg.resolve(&Theme::dark()), bg.dark_color);
let mut raised = Theme::dark();
raised.user_interface_level = Elevated;
assert_eq!(bg.resolve(&raised), bg.dark_elevated_color);
let mut surface = MediaQuery::new(Size::new(100.0, 100.0));
surface.accessibility = Accessibility {
high_contrast: true,
..Accessibility::NONE
};
surface.scope(|| {
assert_eq!(bg.resolve(&raised), bg.dark_high_contrast_elevated_color);
assert_eq!(
C::LABEL.resolve(&Theme::light()),
C::LABEL.high_contrast_color
);
});
}
#[test]
fn a_raised_subtree_resolves_raised() {
assert_eq!(Theme::default().user_interface_level, Base);
let mut raised = Theme::dark();
raised.user_interface_level = Elevated;
assert_eq!(raised.lerp(&raised, 0.3).user_interface_level, Elevated);
assert_eq!(
Theme::dark().lerp(&raised, 0.7).user_interface_level,
Elevated
);
assert_eq!(Theme::dark().lerp(&raised, 0.3).user_interface_level, Base);
let swatch = || {
ThemeBuilder::new(|t: &Theme| {
Container::new()
.width(50.0)
.height(50.0)
.color(C::SYSTEM_BACKGROUND.resolve(t))
})
};
let tree = Flex::<Msg>::column()
.width(200.0)
.height(200.0)
.child(swatch())
.child(Elevated.around(swatch()));
let painted: Vec<Color> = build_ui(
&tree as &dyn Widget<Msg>,
Size::new(200.0, 200.0),
&Runtime::default(),
&Theme::dark(),
)
.scene()
.primitives()
.iter()
.filter_map(|p| match p {
Primitive::Rect { color, blur, .. } if *blur == 0.0 => Some(*color),
_ => None,
})
.collect();
assert_eq!(
painted,
vec![
C::SYSTEM_BACKGROUND.dark_color,
C::SYSTEM_BACKGROUND.dark_elevated_color
]
);
assert_eq!(CupertinoUserInterfaceLevelData::of(&raised), Elevated);
}
}