#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Color {
Rgba(u8, u8, u8, u8),
Label,
SecondaryLabel,
Accent,
Separator,
SystemRed,
SystemOrange,
SystemGreen,
SystemYellow,
}
impl Color {
pub fn rgb(r: u8, g: u8, b: u8) -> Self {
Color::Rgba(r, g, b, 255)
}
pub fn is_literal(&self) -> bool {
matches!(self, Color::Rgba(..))
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Rgba {
pub r: u8,
pub g: u8,
pub b: u8,
pub a: u8,
}
impl Rgba {
pub const BLACK: Rgba = Rgba {
r: 0,
g: 0,
b: 0,
a: 255,
};
pub const WHITE: Rgba = Rgba {
r: 255,
g: 255,
b: 255,
a: 255,
};
pub const TRANSPARENT: Rgba = Rgba {
r: 0,
g: 0,
b: 0,
a: 0,
};
pub const fn new(r: u8, g: u8, b: u8, a: u8) -> Self {
Rgba { r, g, b, a }
}
pub const fn opaque(r: u8, g: u8, b: u8) -> Self {
Rgba { r, g, b, a: 255 }
}
}
#[derive(Clone, Debug, PartialEq, Eq, Hash, Default)]
pub enum FontFamily {
#[default]
System,
SystemMono,
Named(String),
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
pub enum Weight {
#[default]
Regular,
Medium,
Semibold,
Bold,
}
impl Weight {
pub fn ot_weight(&self) -> u16 {
match self {
Weight::Regular => 400,
Weight::Medium => 500,
Weight::Semibold => 600,
Weight::Bold => 700,
}
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct Font {
pub family: FontFamily,
pub size: f32,
pub weight: Weight,
pub letter_spacing: f32,
}
impl Default for Font {
fn default() -> Self {
Font {
family: FontFamily::System,
size: 13.0,
weight: Weight::Regular,
letter_spacing: 0.0,
}
}
}
impl Font {
pub fn system(size: f32, weight: Weight) -> Self {
Font {
family: FontFamily::System,
size,
weight,
letter_spacing: 0.0,
}
}
pub fn mono(size: f32, weight: Weight) -> Self {
Font {
family: FontFamily::SystemMono,
size,
weight,
letter_spacing: 0.0,
}
}
pub fn with_weight(mut self, weight: Weight) -> Self {
self.weight = weight;
self
}
pub fn with_letter_spacing(mut self, points: f32) -> Self {
self.letter_spacing = points;
self
}
}