#[derive(Debug, Clone, PartialEq)]
pub struct TextStyle {
pub font_size: Option<f32>,
pub font_weight: u16,
pub italic: bool,
pub color: Option<[u8; 4]>,
pub line_height: Option<f32>,
pub letter_spacing: f32,
pub underline: bool,
pub strikethrough: bool,
}
impl Default for TextStyle {
fn default() -> Self {
Self {
font_size: None,
font_weight: 400,
italic: false,
color: None,
line_height: None,
letter_spacing: 0.0,
underline: false,
strikethrough: false,
}
}
}
impl TextStyle {
pub fn bold() -> Self {
Self {
font_weight: 700,
..Self::default()
}
}
pub fn italic() -> Self {
Self {
italic: true,
..Self::default()
}
}
pub fn heading() -> Self {
Self {
font_size: Some(24.0),
font_weight: 700,
..Self::default()
}
}
pub fn body() -> Self {
Self::default()
}
pub fn caption() -> Self {
Self {
font_size: Some(11.0),
..Self::default()
}
}
pub fn with_size(mut self, size: f32) -> Self {
self.font_size = Some(size);
self
}
pub fn with_weight(mut self, weight: u16) -> Self {
self.font_weight = weight;
self
}
pub fn with_color(mut self, rgba: [u8; 4]) -> Self {
self.color = Some(rgba);
self
}
pub fn with_line_height(mut self, multiplier: f32) -> Self {
self.line_height = Some(multiplier);
self
}
pub fn with_letter_spacing(mut self, spacing: f32) -> Self {
self.letter_spacing = spacing;
self
}
pub fn with_underline(mut self, underline: bool) -> Self {
self.underline = underline;
self
}
pub fn with_strikethrough(mut self, strikethrough: bool) -> Self {
self.strikethrough = strikethrough;
self
}
}