1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//! Custom theme builder.
//!
//! For applications that want a theme that isn't one of the presets,
//! `CustomBuilder` provides a starting-from-Dark builder pattern.
use crate::{Component, Container, Palette, Theme, Typography};
use embedded_graphics::{mono_font::MonoFont, pixelcolor::Rgb888};
/// Builder for a custom theme. Starts from [`crate::theme::dark::THEME`] and
/// allows overriding individual fields.
#[derive(Clone)]
pub struct CustomBuilder<'a> {
theme: Theme<'a, Rgb888>,
}
impl<'a> CustomBuilder<'a> {
/// Start from the Dark theme.
#[must_use]
pub fn from_dark() -> Self {
Self {
theme: crate::theme::dark::THEME,
}
}
/// Start from the Light theme.
#[must_use]
pub fn from_light() -> Self {
Self {
theme: crate::theme::light::THEME,
}
}
/// Start from any existing theme.
#[must_use]
pub fn from_theme(theme: Theme<'a, Rgb888>) -> Self {
Self { theme }
}
/// Override the accent component.
#[must_use]
pub fn accent(mut self, accent: Component<Rgb888>) -> Self {
self.theme.accent = accent;
self
}
/// Override the background region.
#[must_use]
pub fn background(mut self, bg: Container<Rgb888>) -> Self {
self.theme.background = bg;
self
}
/// Override the primary region.
#[must_use]
pub fn primary(mut self, primary: Container<Rgb888>) -> Self {
self.theme.primary = primary;
self
}
/// Override the palette.
#[must_use]
pub fn palette(mut self, palette: Palette<Rgb888>) -> Self {
self.theme.palette = palette;
self
}
/// Override the typography scale.
#[must_use]
pub fn typography(mut self, typography: Typography<'a>) -> Self {
self.theme.typography = typography;
self
}
/// Override only the display font for hero text.
#[must_use]
pub fn display_font(mut self, font: &'a MonoFont<'a>) -> Self {
self.theme.typography.display = font;
self
}
/// Override only the body font (most common case). Display, heading,
/// and caption are left as the inherited theme's choices.
#[must_use]
pub fn font(mut self, font: &'a MonoFont<'a>) -> Self {
self.theme.typography.body = font;
self
}
/// Set the is_dark flag.
#[must_use]
pub fn dark(mut self, is_dark: bool) -> Self {
self.theme.is_dark = is_dark;
self
}
/// Finish, returning the built theme.
#[must_use]
pub fn build(self) -> Theme<'a, Rgb888> {
self.theme
}
}