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 parchment).
7    pub bg:            u32,
8    /// Inner page area background.
9    pub page_bg:       u32,
10    /// Left panel (TOC) background.
11    pub sidebar_bg:    u32,
12    /// Default body text.
13    pub text:          u32,
14    /// Entry/category titles and selected items.
15    pub title:         u32,
16    /// Unselected navigation button text.
17    pub nav:           u32,
18    /// Selected navigation button highlight.
19    pub nav_selected:  u32,
20    /// Border/separator color.
21    pub border:        u32,
22    /// Book nameplate color.
23    pub nameplate:     u32,
24    /// Divider line between sections.
25    pub divider:       u32,
26}
27
28impl Default for BookTheme {
29    fn default() -> Self {
30        Self {
31            bg:           0xFF_1C1008,
32            page_bg:      0xFF_F5E6C8,
33            sidebar_bg:   0xFF_2A1A08,
34            text:         0xFF_3B2008,
35            title:        0xFF_7A3A00,
36            nav:          0xFF_5C4020,
37            nav_selected: 0xFF_C87820,
38            border:       0xFF_5C3A10,
39            nameplate:    0xFF_C8A050,
40            divider:      0xFF_8B6030,
41        }
42    }
43}
44
45impl BookTheme {
46    /// Override with colors from the book's `nameplate_color` hex string.
47    pub fn with_nameplate(mut self, hex: &str) -> Self {
48        if let Ok(v) = u32::from_str_radix(hex.trim_start_matches('#'), 16) {
49            self.nameplate = 0xFF_000000 | v;
50            self.title = 0xFF_000000 | v;
51        }
52        self
53    }
54}