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            bg:              0xFF_2A1A08,   // dark brown outer frame
37            page_bg:         0xFF_F5E6C8,   // left page: warm cream parchment
38            page_bg_right:   0xFF_EECF9A,   // right page: slightly golden parchment
39            text:            0xFF_3B2008,   // dark brown body text
40            title:           0xFF_7A3A00,   // mid-brown titles
41            nav:             0xFF_5C4020,   // nav links (unselected)
42            nav_selected:    0xFF_C87820,   // nav links (selected, amber)
43            nav_selected_bg: 0x50_C87820,   // selected row tint (semi-transparent amber)
44            border:          0xFF_5C3A10,   // spine + divider lines
45            nameplate:       0xFF_C8A050,   // book title color
46            divider:         0xFF_8B6030,   // section divider text/line
47            sidebar_bg:      0xFF_2A1A08,   // unused, kept for API compat
48        }
49    }
50}
51
52impl BookTheme {
53    /// Override nameplate/title color from the book's hex string (e.g. "0066cc").
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            self.title     = 0xFF_000000 | v;
58        }
59        self
60    }
61}