Skip to main content

euv_core/style/text_prop/
impl.rs

1use super::*;
2
3/// Default typography style (`14px` Sans Regular, `1.4` line height).
4impl Default for TextStyle {
5    /// Creates the default UI text style.
6    ///
7    /// # Returns
8    ///
9    /// - `Self` - Default `TextStyle`.
10    fn default() -> Self {
11        Self {
12            family: FontFamily::Sans,
13            font_size: 14.0,
14            weight: FontWeight::Normal,
15            line_height: 1.4,
16            letter_spacing: 0.0,
17            align: TextAlign::Left,
18            overflow: TextOverflow::Wrap,
19            color: COLOR_BLACK,
20            italic: false,
21            underline: false,
22            strikethrough: false,
23        }
24    }
25}
26
27/// Numeric weight helpers for `FontWeight`.
28impl FontWeight {
29    /// Returns the OpenType numeric weight (`300..=700`).
30    ///
31    /// # Arguments
32    ///
33    /// - `&Self` - Font weight variant.
34    ///
35    /// # Returns
36    ///
37    /// - `u16` - OpenType numeric weight value.
38    #[must_use]
39    pub const fn numeric(&self) -> u16 {
40        match *self {
41            Self::Light => 300,
42            Self::Normal => 400,
43            Self::Medium => 500,
44            Self::SemiBold => 600,
45            Self::Bold => 700,
46        }
47    }
48
49    /// Returns true when the weight renders bold strokes (`>= 600`).
50    ///
51    /// # Arguments
52    ///
53    /// - `&Self` - Font weight variant.
54    ///
55    /// # Returns
56    ///
57    /// - `bool` - True for `SemiBold` and `Bold`.
58    #[must_use]
59    pub const fn is_bold(&self) -> bool {
60        matches!(*self, Self::SemiBold | Self::Bold)
61    }
62}