Skip to main content

draw_core/
style.rs

1use serde::{Deserialize, Serialize};
2
3// ── Defaults ─────────────────────────────────────────────────────────
4
5pub const DEFAULT_STROKE_COLOR: &str = "#e2e8f0";
6pub const DEFAULT_STROKE_WIDTH: f64 = 2.0;
7pub const DEFAULT_FILL_COLOR: &str = "#3b82f6";
8pub const DEFAULT_FONT_FAMILY: &str = "Inter, sans-serif";
9pub const DEFAULT_FONT_SIZE: f64 = 20.0;
10
11// ── StrokeStyle ──────────────────────────────────────────────────────
12
13#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14pub struct StrokeStyle {
15    pub color: String,
16    pub width: f64,
17    #[serde(default)]
18    pub dash: Vec<f64>,
19}
20
21impl Default for StrokeStyle {
22    fn default() -> Self {
23        Self {
24            color: DEFAULT_STROKE_COLOR.to_string(),
25            width: DEFAULT_STROKE_WIDTH,
26            dash: vec![],
27        }
28    }
29}
30
31// ── FillStyle ────────────────────────────────────────────────────────
32
33pub const DEFAULT_HACHURE_GAP: f64 = 10.0;
34pub const DEFAULT_HACHURE_ANGLE: f64 = -0.785; // -45 degrees in radians
35
36#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
37pub struct FillStyle {
38    pub color: String,
39    pub style: FillType,
40    #[serde(default = "default_hachure_gap")]
41    pub gap: f64,
42    #[serde(default = "default_hachure_angle")]
43    pub angle: f64,
44}
45
46impl Default for FillStyle {
47    fn default() -> Self {
48        Self {
49            color: DEFAULT_FILL_COLOR.to_string(),
50            style: FillType::Hachure,
51            gap: DEFAULT_HACHURE_GAP,
52            angle: DEFAULT_HACHURE_ANGLE,
53        }
54    }
55}
56
57fn default_hachure_gap() -> f64 {
58    DEFAULT_HACHURE_GAP
59}
60fn default_hachure_angle() -> f64 {
61    DEFAULT_HACHURE_ANGLE
62}
63
64#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
65#[serde(rename_all = "lowercase")]
66pub enum FillType {
67    Solid,
68    Hachure,
69    CrossHatch,
70    None,
71}
72
73// ── FontStyle ────────────────────────────────────────────────────────
74
75#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
76pub struct FontStyle {
77    pub family: String,
78    pub size: f64,
79    pub align: TextAlign,
80}
81
82impl Default for FontStyle {
83    fn default() -> Self {
84        Self {
85            family: DEFAULT_FONT_FAMILY.to_string(),
86            size: DEFAULT_FONT_SIZE,
87            align: TextAlign::Left,
88        }
89    }
90}
91
92#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
93#[serde(rename_all = "lowercase")]
94pub enum TextAlign {
95    Left,
96    Center,
97    Right,
98}
99
100// ── Arrowhead ────────────────────────────────────────────────────────
101
102#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
103#[serde(rename_all = "lowercase")]
104pub enum Arrowhead {
105    Arrow,
106    Triangle,
107    Dot,
108}