use crate::{
modifier::Color,
text::{
FontFamily, FontWeight, TextUnit,
paragraph::TextAlign,
style::{
LineHeightAlignment, LineHeightMode, LineHeightStyle, LineHeightTrim, ParagraphStyle,
PlatformParagraphStyle, SpanStyle, TextStyle,
},
},
widgets::wear::color_appearance::set_luminance,
};
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct WearColors {
pub primary: Color,
pub primary_container: Color,
pub on_primary: Color,
pub on_primary_container: Color,
pub surface_container: Color,
pub on_surface: Color,
pub on_surface_variant: Color,
pub outline: Color,
pub background: Color,
pub on_background: Color,
pub content: Color,
pub indicator_thumb: Color,
pub indicator_track: Color,
}
impl Default for WearColors {
fn default() -> Self {
Self {
primary: Color::from_rgb_u8(0xA8, 0xC7, 0xFA),
primary_container: Color::from_rgb_u8(0x0B, 0x57, 0xD0),
on_primary: Color::from_rgb_u8(0x00, 0x00, 0x00),
on_primary_container: Color::from_rgb_u8(0xD3, 0xE3, 0xFD),
surface_container: Color::from_rgb_u8(0x1E, 0x1F, 0x20),
on_surface: Color::from_rgb_u8(0xE3, 0xE3, 0xE3),
on_surface_variant: Color::from_rgb_u8(0xC4, 0xC7, 0xC5),
outline: Color::from_rgb_u8(0x8E, 0x91, 0x8F),
background: Color::from_rgb_u8(0x00, 0x00, 0x00),
on_background: Color::from_rgb_u8(0xE3, 0xE3, 0xE3),
content: Color::WHITE,
indicator_thumb: Color::WHITE,
indicator_track: Color::WHITE,
}
.with_wear_scroll_indicator()
}
}
impl WearColors {
pub fn with_wear_scroll_indicator(mut self) -> Self {
self.indicator_thumb = set_luminance(self.on_background, 80.0);
self.indicator_track = set_luminance(self.on_background, 20.0);
self
}
}
pub fn wear_line_height_style() -> LineHeightStyle {
LineHeightStyle {
alignment: LineHeightAlignment::Center,
trim: LineHeightTrim::None,
mode: LineHeightMode::Minimum,
}
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct WearTextStyle {
pub size_sp: f32,
pub line_height_sp: f32,
pub weight: u16,
pub tracking_sp: f32,
pub align: TextAlign,
}
impl WearTextStyle {
pub const BRAND_FAMILY: FontFamily = FontFamily::SansSerif;
pub const TITLE_MEDIUM: Self = Self {
size_sp: 16.0,
line_height_sp: 18.0,
weight: 550,
tracking_sp: 0.4,
align: TextAlign::Unspecified,
};
pub const LABEL_MEDIUM: Self = Self {
size_sp: 15.0,
line_height_sp: 18.0,
weight: 500,
tracking_sp: 0.4,
align: TextAlign::Unspecified,
};
pub const LABEL_SMALL: Self = Self {
size_sp: 13.0,
line_height_sp: 16.0,
weight: 500,
tracking_sp: 0.4,
align: TextAlign::Unspecified,
};
pub const BODY_LARGE: Self = Self {
size_sp: 16.0,
line_height_sp: 18.0,
weight: 450,
tracking_sp: 0.4,
align: TextAlign::Unspecified,
};
pub const fn at_size(self, size_sp: f32) -> Self {
Self { size_sp, ..self }
}
pub const fn with_line_height(self, line_height_sp: f32) -> Self {
Self {
line_height_sp,
..self
}
}
pub const fn aligned(self, align: TextAlign) -> Self {
Self { align, ..self }
}
pub fn resolve(self, color: Color) -> TextStyle {
self.resolve_in(color, Self::BRAND_FAMILY)
}
pub fn resolve_in(self, color: Color, family: FontFamily) -> TextStyle {
TextStyle {
span_style: SpanStyle {
color: Some(color),
font_size: TextUnit::Sp(self.size_sp),
font_weight: Some(FontWeight(self.weight)),
letter_spacing: TextUnit::Sp(self.tracking_sp),
font_family: Some(family),
..SpanStyle::default()
},
paragraph_style: ParagraphStyle {
line_height: TextUnit::Sp(self.line_height_sp),
text_align: self.align,
line_height_style: Some(wear_line_height_style()),
platform_style: Some(PlatformParagraphStyle {
include_font_padding: Some(false),
shaping: None,
}),
..ParagraphStyle::default()
},
}
}
}
#[cfg(test)]
#[path = "tests/theme_tests.rs"]
mod tests;