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}