Skip to main content

kyu_visualizer/
theme.rs

1//! Color constants for canvas rendering and builder-only UI properties.
2//!
3//! Visual styling lives in `style.css` where possible. Colors here are used
4//! inside `canvas()` draw callbacks and for builder-only properties like
5//! directional borders and text colors (which don't inherit in Blinc CSS).
6
7use blinc_core::Color;
8
9// ── Background & accent (used in canvas for selection ring, etc.) ──
10
11pub const BG: Color = Color::rgba(0.04, 0.04, 0.05, 1.0); // #0a0a0c
12pub const ACCENT: Color = Color::rgba(0.77, 0.58, 0.42, 1.0); // #c4956a
13pub const EDGE_COLOR: Color = Color::rgba(0.29, 0.29, 0.33, 1.0); // #4a4a55
14pub const TEXT_COLOR: Color = Color::rgba(0.91, 0.90, 0.89, 1.0); // #e8e6e3
15pub const TEXT_DIM: Color = Color::rgba(0.53, 0.53, 0.53, 0.8); // #888 semi
16pub const BORDER: Color = Color::rgba(0.16, 0.16, 0.21, 1.0); // #2a2a35
17
18// ── Node radius (world-space, before camera zoom) ──
19
20pub const NODE_RADIUS: f32 = 16.0;
21
22// ── Node color palette — 8 distinct hues that work on dark bg ──
23
24pub const NODE_PALETTE: [Color; 8] = [
25    Color::rgba(0.77, 0.58, 0.42, 1.0), // warm sand   #c4956a
26    Color::rgba(0.40, 0.70, 0.90, 1.0), // sky blue    #66b3e6
27    Color::rgba(0.60, 0.85, 0.55, 1.0), // soft green  #99d98c
28    Color::rgba(0.85, 0.50, 0.55, 1.0), // rose        #d9808c
29    Color::rgba(0.70, 0.55, 0.85, 1.0), // lavender    #b38cd9
30    Color::rgba(0.90, 0.75, 0.40, 1.0), // gold        #e6bf66
31    Color::rgba(0.45, 0.80, 0.75, 1.0), // teal        #73ccbf
32    Color::rgba(0.85, 0.60, 0.75, 1.0), // pink        #d999bf
33];
34
35/// Deterministic color for a node table name.
36pub fn label_color(label: &str) -> Color {
37    let hash = label
38        .bytes()
39        .fold(0u32, |acc, b| acc.wrapping_mul(31).wrapping_add(b as u32));
40    NODE_PALETTE[(hash as usize) % NODE_PALETTE.len()]
41}
42
43/// Color index for a node table name (stored in NodeVisual).
44pub fn label_color_idx(label: &str) -> u8 {
45    let hash = label
46        .bytes()
47        .fold(0u32, |acc, b| acc.wrapping_mul(31).wrapping_add(b as u32));
48    (hash as usize % NODE_PALETTE.len()) as u8
49}