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 #[inline(always)]
11 fn default() -> Self {
12 Self {
13 family: FontFamily::Sans,
14 font_size: 14.0,
15 weight: FontWeight::Normal,
16 line_height: 1.4,
17 letter_spacing: 0.0,
18 align: TextAlign::Left,
19 overflow: TextOverflow::Wrap,
20 color: COLOR_BLACK,
21 italic: false,
22 underline: false,
23 strikethrough: false,
24 selectable: false,
25 selectable_explicit: false,
26 selection_color: None,
27 }
28 }
29}
30
31/// Optional selection highlight helpers for `TextStyle`.
32impl TextStyle {
33 /// Returns the optional custom selection highlight fill color.
34 ///
35 /// # Arguments
36 ///
37 /// - `&Self` - Text style reference.
38 ///
39 /// # Returns
40 ///
41 /// - `Option<Color>` - Selection highlight tint if explicitly configured.
42 #[must_use]
43 #[inline(always)]
44 pub fn selection_color(&self) -> Option<Color> {
45 let Self {
46 selection_color, ..
47 } = *self;
48 selection_color
49 }
50
51 /// Returns `true` when `other` differs only in color or selection properties and has identical layout metrics.
52 ///
53 /// # Arguments
54 ///
55 /// - `&Self` - Previous text style.
56 /// - `&Self` - Candidate updated text style.
57 ///
58 /// # Returns
59 ///
60 /// - `bool` - `true` when typography layout metrics are unchanged.
61 #[must_use]
62 #[inline(always)]
63 pub(crate) fn same_layout_metrics(&self, other: &Self) -> bool {
64 self.get_family() == other.get_family()
65 && self.get_font_size() == other.get_font_size()
66 && self.get_weight() == other.get_weight()
67 && self.get_line_height() == other.get_line_height()
68 && self.get_letter_spacing() == other.get_letter_spacing()
69 && self.get_align() == other.get_align()
70 && self.get_overflow() == other.get_overflow()
71 && self.get_italic() == other.get_italic()
72 }
73}
74
75/// Numeric weight helpers for `FontWeight`.
76impl FontWeight {
77 /// Returns the OpenType numeric weight (`300..=700`).
78 ///
79 /// # Arguments
80 ///
81 /// - `&Self` - Font weight variant.
82 ///
83 /// # Returns
84 ///
85 /// - `u16` - OpenType numeric weight value.
86 #[must_use]
87 #[inline(always)]
88 pub const fn numeric(&self) -> u16 {
89 match *self {
90 Self::Light => 300,
91 Self::Normal => 400,
92 Self::Medium => 500,
93 Self::SemiBold => 600,
94 Self::Bold => 700,
95 }
96 }
97
98 /// Returns true when the weight renders bold strokes (`>= 600`).
99 ///
100 /// # Arguments
101 ///
102 /// - `&Self` - Font weight variant.
103 ///
104 /// # Returns
105 ///
106 /// - `bool` - True for `SemiBold` and `Bold`.
107 #[must_use]
108 #[inline(always)]
109 pub const fn is_bold(&self) -> bool {
110 matches!(*self, Self::SemiBold | Self::Bold)
111 }
112}