Skip to main content

freya_components/
element_expansions.rs

1use freya_core::prelude::*;
2
3use crate::theming::hooks::get_theme_or_default;
4
5pub trait RectThemeExt {
6    fn theme_background(self) -> Self;
7    fn theme_color(self) -> Self;
8}
9
10impl RectThemeExt for Rect {
11    fn theme_background(self) -> Self {
12        let theme = get_theme_or_default();
13        self.background(theme.read().colors.background)
14    }
15
16    fn theme_color(self) -> Self {
17        let theme = get_theme_or_default();
18        self.color(theme.read().colors.text_primary)
19    }
20}
21
22pub trait LabelThemeExt {
23    fn theme_color(self) -> Self;
24}
25
26impl LabelThemeExt for Label {
27    fn theme_color(self) -> Self {
28        let theme = get_theme_or_default();
29        self.color(theme.read().colors.text_primary)
30    }
31}
32
33pub trait ParagraphThemeExt {
34    fn theme_color(self) -> Self;
35}
36
37impl ParagraphThemeExt for Paragraph {
38    fn theme_color(self) -> Self {
39        let theme = get_theme_or_default();
40        self.color(theme.read().colors.text_primary)
41    }
42}
43
44pub trait SvgThemeExt {
45    fn theme_color(self) -> Self;
46    fn theme_accent_color(self) -> Self;
47    fn theme_fill(self) -> Self;
48    fn theme_stroke(self) -> Self;
49    fn theme_accent_fill(self) -> Self;
50    fn theme_accent_stroke(self) -> Self;
51}
52
53impl SvgThemeExt for Svg {
54    fn theme_color(self) -> Self {
55        let theme = get_theme_or_default();
56        self.color(theme.read().colors.text_primary)
57    }
58
59    fn theme_accent_color(self) -> Self {
60        let theme = get_theme_or_default();
61        self.color(theme.read().colors.primary)
62    }
63
64    fn theme_fill(self) -> Self {
65        let theme = get_theme_or_default();
66        self.fill(theme.read().colors.text_primary)
67    }
68
69    fn theme_stroke(self) -> Self {
70        let theme = get_theme_or_default();
71        self.stroke(theme.read().colors.text_primary)
72    }
73
74    fn theme_accent_fill(self) -> Self {
75        let theme = get_theme_or_default();
76        self.fill(theme.read().colors.primary)
77    }
78
79    fn theme_accent_stroke(self) -> Self {
80        let theme = get_theme_or_default();
81        self.stroke(theme.read().colors.primary)
82    }
83}