Skip to main content

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
31/// The book's colours by default — Patchouli's where it has them
32/// (`textColor`, `headerColor`, `nameplateColor`).
33const FRAME: Color = Color(0xFF_2A1A08);
34const PARCHMENT: Color = Color(0xFF_F5E6C8);
35const PARCHMENT_GOLDEN: Color = Color(0xFF_EECF9A);
36const TEXT: Color = Color(0xFF_000000);
37const HEADER: Color = Color(0xFF_333333);
38const NAV: Color = Color(0xFF_5C4020);
39const AMBER: Color = Color(0xFF_C87820);
40const AMBER_TINT: Color = Color(0x50_C87820);
41const SPINE: Color = Color(0xFF_5C3A10);
42const NAMEPLATE: Color = Color(0xFF_FFDD98);
43
44impl Default for BookTheme {
45    fn default() -> Self {
46        Self {
47            bg: FRAME,
48            page_bg: PARCHMENT,
49            page_bg_right: PARCHMENT_GOLDEN,
50            text: TEXT,
51            title: HEADER,
52            nav: NAV,
53            nav_selected: AMBER,
54            nav_selected_bg: AMBER_TINT,
55            border: SPINE,
56            nameplate: NAMEPLATE,
57            divider: HEADER,
58        }
59    }
60}
61
62/// What a hex colour starts with.
63const HASH: char = '#';
64
65impl BookTheme {
66    /// Override nameplate color from the book's hex string (e.g. "0066cc").
67    /// Like Patchouli, this only affects the nameplate text — headers keep
68    /// their own headerColor.
69    pub fn with_nameplate(mut self, hex: &str) -> Self {
70        if let Some(c) = Color::parse(&format!("{HASH}{}", hex.trim_start_matches(HASH))) {
71            self.nameplate = c.with_alpha(u8::MAX);
72        }
73        self
74    }
75}