konnektoren_bevy/theme/
resource.rs

1use bevy::prelude::*;
2use bevy_egui::egui;
3
4/// Shared theme resource that works for both Bevy UI and egui
5#[derive(Resource, Clone)]
6pub struct KonnektorenTheme {
7    // Base colors
8    pub base_100: egui::Color32,
9    pub base_200: egui::Color32,
10    pub base_300: egui::Color32,
11    pub base_content: egui::Color32,
12
13    // Primary colors
14    pub primary: egui::Color32,
15    pub primary_content: egui::Color32,
16
17    // Secondary colors
18    pub secondary: egui::Color32,
19    pub secondary_content: egui::Color32,
20
21    // Accent colors
22    pub accent: egui::Color32,
23    pub accent_content: egui::Color32,
24
25    // Status colors
26    pub info: egui::Color32,
27    pub success: egui::Color32,
28    pub warning: egui::Color32,
29    pub error: egui::Color32,
30    pub error_content: egui::Color32,
31
32    // UI elements
33    pub radius: u8,
34    pub border_width: f32,
35}
36
37impl Default for KonnektorenTheme {
38    fn default() -> Self {
39        Self {
40            // Base colors
41            base_100: egui::Color32::from_rgb(246, 246, 246),
42            base_200: egui::Color32::from_rgb(240, 240, 240),
43            base_300: egui::Color32::from_rgb(232, 232, 232),
44            base_content: egui::Color32::from_rgb(41, 41, 41),
45
46            // Primary color - orange FF8C00
47            primary: egui::Color32::from_rgb(255, 140, 0),
48            primary_content: egui::Color32::from_rgb(255, 255, 255),
49
50            // Secondary color - purple 8A2BE2
51            secondary: egui::Color32::from_rgb(138, 43, 226),
52            secondary_content: egui::Color32::from_rgb(255, 255, 255),
53
54            // Accent color - gray 808080
55            accent: egui::Color32::from_rgb(128, 128, 128),
56            accent_content: egui::Color32::from_rgb(255, 255, 255),
57
58            // Status colors
59            info: egui::Color32::from_rgb(23, 162, 184),
60            success: egui::Color32::from_rgb(40, 167, 69),
61            warning: egui::Color32::from_rgb(255, 193, 7),
62            error: egui::Color32::from_rgb(220, 53, 69),
63            error_content: egui::Color32::WHITE,
64
65            radius: 8,
66            border_width: 1.0,
67        }
68    }
69}
70
71impl KonnektorenTheme {
72    /// Create a new theme with custom colors
73    pub fn new() -> Self {
74        Self::default()
75    }
76
77    /// Create a theme builder for customization
78    pub fn builder() -> KonnektorenThemeBuilder {
79        KonnektorenThemeBuilder::new()
80    }
81
82    /// Convert Bevy Color to egui Color32
83    pub fn bevy_to_egui(color: Color) -> egui::Color32 {
84        let rgba = color.to_srgba();
85        egui::Color32::from_rgba_unmultiplied(
86            (rgba.red * 255.0) as u8,
87            (rgba.green * 255.0) as u8,
88            (rgba.blue * 255.0) as u8,
89            (rgba.alpha * 255.0) as u8,
90        )
91    }
92
93    /// Get Bevy-compatible colors
94    pub fn primary_bevy(&self) -> Color {
95        Color::srgb(
96            self.primary.r() as f32 / 255.0,
97            self.primary.g() as f32 / 255.0,
98            self.primary.b() as f32 / 255.0,
99        )
100    }
101
102    pub fn secondary_bevy(&self) -> Color {
103        Color::srgb(
104            self.secondary.r() as f32 / 255.0,
105            self.secondary.g() as f32 / 255.0,
106            self.secondary.b() as f32 / 255.0,
107        )
108    }
109
110    pub fn success_bevy(&self) -> Color {
111        Color::srgb(
112            self.success.r() as f32 / 255.0,
113            self.success.g() as f32 / 255.0,
114            self.success.b() as f32 / 255.0,
115        )
116    }
117
118    pub fn error_bevy(&self) -> Color {
119        Color::srgb(
120            self.error.r() as f32 / 255.0,
121            self.error.g() as f32 / 255.0,
122            self.error.b() as f32 / 255.0,
123        )
124    }
125}
126
127/// Builder for creating custom themes
128pub struct KonnektorenThemeBuilder {
129    theme: KonnektorenTheme,
130}
131
132impl KonnektorenThemeBuilder {
133    pub fn new() -> Self {
134        Self {
135            theme: KonnektorenTheme::default(),
136        }
137    }
138
139    pub fn primary(mut self, color: egui::Color32) -> Self {
140        self.theme.primary = color;
141        self
142    }
143
144    pub fn secondary(mut self, color: egui::Color32) -> Self {
145        self.theme.secondary = color;
146        self
147    }
148
149    pub fn accent(mut self, color: egui::Color32) -> Self {
150        self.theme.accent = color;
151        self
152    }
153
154    pub fn success(mut self, color: egui::Color32) -> Self {
155        self.theme.success = color;
156        self
157    }
158
159    pub fn error(mut self, color: egui::Color32) -> Self {
160        self.theme.error = color;
161        self
162    }
163
164    pub fn radius(mut self, radius: u8) -> Self {
165        self.theme.radius = radius;
166        self
167    }
168
169    pub fn border_width(mut self, width: f32) -> Self {
170        self.theme.border_width = width;
171        self
172    }
173
174    pub fn build(self) -> KonnektorenTheme {
175        self.theme
176    }
177}
178
179impl Default for KonnektorenThemeBuilder {
180    fn default() -> Self {
181        Self::new()
182    }
183}