use crate::color::Color;
use crate::material::Material;
#[derive(Clone, Debug, PartialEq)]
pub struct Theme {
pub dark: bool,
pub accent: Color,
pub frost: f32,
pub adaptive: bool,
pub reduce_transparency: bool,
pub reduce_motion: bool,
pub high_contrast: bool,
pub regular: Material,
pub clear: Material,
pub thick: Material,
pub lens: Material,
pub blob: Material,
pub blob_labels: Material,
pub control_height: f32,
pub spacing: f32,
pub body: f32,
pub caption: f32,
pub title: f32,
}
impl Default for Theme {
fn default() -> Self {
Self {
dark: false,
accent: Color::BLUE,
frost: Theme::FROST,
adaptive: true,
reduce_transparency: false,
reduce_motion: false,
high_contrast: false,
regular: Material::REGULAR,
clear: Material::CLEAR,
thick: Material::THICK,
lens: Material::LENS,
blob: Material::BLOB,
blob_labels: Material::BLOB_LABELS,
control_height: 36.0,
spacing: 10.0,
body: 14.0,
caption: 12.0,
title: 24.0,
}
}
}
impl Theme {
pub const FROST: f32 = 0.35;
pub fn tinted(&self) -> f32 {
if self.reduce_transparency {
1.0
} else {
((self.frost - Self::FROST) / (1.0 - Self::FROST)).clamp(0.0, 1.0)
}
}
pub fn veil(&self) -> f32 {
if self.reduce_transparency { 1.0 } else { self.frost.clamp(0.0, 1.0) * 0.75 }
}
pub fn text(&self) -> Color {
if self.dark { Color::gray(0.97) } else { Color::gray(0.04) }
}
pub fn background(&self) -> Color {
if self.dark { Color::gray(0.07) } else { Color::gray(0.95) }
}
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum Surface {
Content { dark: bool },
Glass { dark: f32 },
}
impl Surface {
pub fn dark(&self) -> f32 {
match self {
Surface::Content { dark } => *dark as u32 as f32,
Surface::Glass { dark } => *dark,
}
}
pub fn is_glass(&self) -> bool {
matches!(self, Surface::Glass { .. })
}
pub fn text(&self) -> Color {
Color::gray(0.04).lerp(Color::gray(0.99), self.dark())
}
pub fn secondary(&self) -> Color {
Color::black(0.52).lerp(Color::white(0.62), self.dark())
}
pub fn tertiary(&self) -> Color {
Color::black(0.30).lerp(Color::white(0.36), self.dark())
}
pub fn fill(&self) -> Color {
Color::black(0.085).lerp(Color::white(0.13), self.dark())
}
pub fn fill_strong(&self) -> Color {
Color::black(0.15).lerp(Color::white(0.22), self.dark())
}
pub fn separator(&self) -> Color {
Color::black(0.10).lerp(Color::white(0.14), self.dark())
}
pub fn knob(&self) -> Color {
Color::WHITE.lerp(Color::gray(0.96), self.dark())
}
}