yog_book/theme.rs
1//! Visual theme for book rendering.
2
3use yog_gfx::Color;
4
5#[derive(Debug, Clone)]
6pub struct BookTheme {
7 /// Outer book background (dark border frame).
8 pub bg: Color,
9 /// Left page background (light parchment).
10 pub page_bg: Color,
11 /// Right page background (slightly warmer parchment).
12 pub page_bg_right: Color,
13 /// Default body text.
14 pub text: Color,
15 /// Entry/category titles.
16 pub title: Color,
17 /// Unselected navigation text.
18 pub nav: Color,
19 /// Selected navigation item text.
20 pub nav_selected: Color,
21 /// Selected navigation item background.
22 pub nav_selected_bg: Color,
23 /// Border/separator line color.
24 pub border: Color,
25 /// Book nameplate (title) color.
26 pub nameplate: Color,
27 /// Divider line between sections.
28 pub divider: Color,
29}
30
31impl Default for BookTheme {
32 fn default() -> Self {
33 Self {
34 // Patchouli defaults: textColor=000000, headerColor=333333,
35 // nameplateColor=FFDD98.
36 bg: Color(0xFF_2A1A08), // dark brown outer frame
37 page_bg: Color(0xFF_F5E6C8), // left page: warm cream parchment
38 page_bg_right: Color(0xFF_EECF9A), // right page: slightly golden parchment
39 text: Color(0xFF_000000), // body text (Patchouli textColor)
40 title: Color(0xFF_333333), // headers (Patchouli headerColor)
41 nav: Color(0xFF_5C4020), // nav links (unselected)
42 nav_selected: Color(0xFF_C87820), // nav links (selected, amber)
43 nav_selected_bg: Color(0x50_C87820), // selected row tint (semi-transparent amber)
44 border: Color(0xFF_5C3A10), // spine + divider lines
45 nameplate: Color(0xFF_FFDD98), // book title color (Patchouli nameplateColor)
46 divider: Color(0xFF_333333), // section headers ("Categories" etc.)
47 }
48 }
49}
50
51impl BookTheme {
52 /// Override nameplate color from the book's hex string (e.g. "0066cc").
53 /// Like Patchouli, this only affects the nameplate text — headers keep
54 /// their own headerColor.
55 pub fn with_nameplate(mut self, hex: &str) -> Self {
56 if let Some(c) = Color::parse(&format!("#{}", hex.trim_start_matches('#'))) {
57 self.nameplate = c.with_alpha(0xff);
58 }
59 self
60 }
61}