freya_components/
element_expansions.rs1use freya_core::prelude::*;
2
3use crate::{
4 get_theme,
5 theming::hooks::get_theme_or_default,
6 typography::{
7 TypographyThemePartial,
8 TypographyThemePreference,
9 },
10};
11
12pub trait RectThemeExt {
13 fn theme_background(self) -> Self;
14 fn theme_color(self) -> Self;
15}
16
17impl RectThemeExt for Rect {
18 fn theme_background(self) -> Self {
19 let theme = get_theme_or_default();
20 self.background(theme.read().colors.background)
21 }
22
23 fn theme_color(self) -> Self {
24 let theme = get_theme_or_default();
25 self.color(theme.read().colors.text_primary)
26 }
27}
28
29pub trait LabelThemeExt {
30 fn theme_color(self) -> Self;
31
32 fn title(self) -> Self;
34
35 fn subtitle(self) -> Self;
37
38 fn body(self) -> Self;
40
41 fn caption(self) -> Self;
43
44 fn overline(self) -> Self;
46}
47
48fn typography() -> crate::typography::TypographyTheme {
49 get_theme!(
50 &None::<TypographyThemePartial>,
51 TypographyThemePreference,
52 "typography"
53 )
54}
55
56impl LabelThemeExt for Label {
57 fn theme_color(self) -> Self {
58 let theme = get_theme_or_default();
59 self.color(theme.read().colors.text_primary)
60 }
61
62 fn title(self) -> Self {
63 self.font_size(typography().title)
64 }
65
66 fn subtitle(self) -> Self {
67 self.font_size(typography().subtitle)
68 }
69
70 fn body(self) -> Self {
71 self.font_size(typography().body)
72 }
73
74 fn caption(self) -> Self {
75 self.font_size(typography().caption)
76 }
77
78 fn overline(self) -> Self {
79 self.font_size(typography().overline)
80 }
81}
82
83pub trait ParagraphThemeExt {
84 fn theme_color(self) -> Self;
85}
86
87impl ParagraphThemeExt for Paragraph {
88 fn theme_color(self) -> Self {
89 let theme = get_theme_or_default();
90 self.color(theme.read().colors.text_primary)
91 }
92}
93
94pub trait SvgThemeExt {
95 fn theme_color(self) -> Self;
96 fn theme_accent_color(self) -> Self;
97 fn theme_fill(self) -> Self;
98 fn theme_stroke(self) -> Self;
99 fn theme_accent_fill(self) -> Self;
100 fn theme_accent_stroke(self) -> Self;
101}
102
103impl SvgThemeExt for Svg {
104 fn theme_color(self) -> Self {
105 let theme = get_theme_or_default();
106 self.color(theme.read().colors.text_primary)
107 }
108
109 fn theme_accent_color(self) -> Self {
110 let theme = get_theme_or_default();
111 self.color(theme.read().colors.primary)
112 }
113
114 fn theme_fill(self) -> Self {
115 let theme = get_theme_or_default();
116 self.fill(theme.read().colors.text_primary)
117 }
118
119 fn theme_stroke(self) -> Self {
120 let theme = get_theme_or_default();
121 self.stroke(theme.read().colors.text_primary)
122 }
123
124 fn theme_accent_fill(self) -> Self {
125 let theme = get_theme_or_default();
126 self.fill(theme.read().colors.primary)
127 }
128
129 fn theme_accent_stroke(self) -> Self {
130 let theme = get_theme_or_default();
131 self.stroke(theme.read().colors.primary)
132 }
133}