Skip to main content

yog_book/
theme.rs

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