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    // kept for compatibility — no longer used for sidebar
29    #[allow(dead_code)]
30    pub sidebar_bg:       u32,
31}
32
33impl Default for BookTheme {
34    fn default() -> Self {
35        Self {
36            // Patchouli defaults: textColor=000000, headerColor=333333,
37            // nameplateColor=FFDD98.
38            bg:              0xFF_2A1A08,   // dark brown outer frame
39            page_bg:         0xFF_F5E6C8,   // left page: warm cream parchment
40            page_bg_right:   0xFF_EECF9A,   // right page: slightly golden parchment
41            text:            0xFF_000000,   // body text (Patchouli textColor)
42            title:           0xFF_333333,   // headers (Patchouli headerColor)
43            nav:             0xFF_5C4020,   // nav links (unselected)
44            nav_selected:    0xFF_C87820,   // nav links (selected, amber)
45            nav_selected_bg: 0x50_C87820,   // selected row tint (semi-transparent amber)
46            border:          0xFF_5C3A10,   // spine + divider lines
47            nameplate:       0xFF_FFDD98,   // book title color (Patchouli nameplateColor)
48            divider:         0xFF_333333,   // section headers ("Categories" etc.)
49            sidebar_bg:      0xFF_2A1A08,   // unused, kept for API compat
50        }
51    }
52}
53
54impl BookTheme {
55    /// Override nameplate color from the book's hex string (e.g. "0066cc").
56    /// Like Patchouli, this only affects the nameplate text — headers keep
57    /// their own headerColor.
58    pub fn with_nameplate(mut self, hex: &str) -> Self {
59        if let Ok(v) = u32::from_str_radix(hex.trim_start_matches('#'), 16) {
60            self.nameplate = 0xFF_000000 | v;
61        }
62        self
63    }
64}