yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
theme_manager.cc
Go to the documentation of this file.
1#include "theme_manager.h"
2
3#include <algorithm>
4#include <cctype>
5#include <fstream>
6#include <set>
7#include <sstream>
8#include <cstring>
9
10#include "absl/strings/str_format.h"
11#include "absl/strings/str_split.h"
12#include "util/file_util.h"
13#include "util/platform_paths.h"
14#include "app/gui/icons.h"
15#include "app/gui/style.h" // For ColorsYaze function
16#include "imgui/imgui.h"
17#include "util/log.h"
18
19namespace yaze {
20namespace gui {
21
22// Helper function to create Color from RGB values
23Color RGB(float r, float g, float b, float a = 1.0f) {
24 return {r / 255.0f, g / 255.0f, b / 255.0f, a};
25}
26
27Color RGBA(int r, int g, int b, int a = 255) {
28 return {r / 255.0f, g / 255.0f, b / 255.0f, a / 255.0f};
29}
30
31// Theme Implementation
33 ImGuiStyle* style = &ImGui::GetStyle();
34 ImVec4* colors = style->Colors;
35
36 // Apply colors
37 colors[ImGuiCol_Text] = ConvertColorToImVec4(text_primary);
38 colors[ImGuiCol_TextDisabled] = ConvertColorToImVec4(text_disabled);
39 colors[ImGuiCol_WindowBg] = ConvertColorToImVec4(window_bg);
40 colors[ImGuiCol_ChildBg] = ConvertColorToImVec4(child_bg);
41 colors[ImGuiCol_PopupBg] = ConvertColorToImVec4(popup_bg);
42 colors[ImGuiCol_Border] = ConvertColorToImVec4(border);
43 colors[ImGuiCol_BorderShadow] = ConvertColorToImVec4(border_shadow);
44 colors[ImGuiCol_FrameBg] = ConvertColorToImVec4(frame_bg);
45 colors[ImGuiCol_FrameBgHovered] = ConvertColorToImVec4(frame_bg_hovered);
46 colors[ImGuiCol_FrameBgActive] = ConvertColorToImVec4(frame_bg_active);
47 colors[ImGuiCol_TitleBg] = ConvertColorToImVec4(title_bg);
48 colors[ImGuiCol_TitleBgActive] = ConvertColorToImVec4(title_bg_active);
49 colors[ImGuiCol_TitleBgCollapsed] = ConvertColorToImVec4(title_bg_collapsed);
50 colors[ImGuiCol_MenuBarBg] = ConvertColorToImVec4(menu_bar_bg);
51 colors[ImGuiCol_ScrollbarBg] = ConvertColorToImVec4(scrollbar_bg);
52 colors[ImGuiCol_ScrollbarGrab] = ConvertColorToImVec4(scrollbar_grab);
53 colors[ImGuiCol_ScrollbarGrabHovered] = ConvertColorToImVec4(scrollbar_grab_hovered);
54 colors[ImGuiCol_ScrollbarGrabActive] = ConvertColorToImVec4(scrollbar_grab_active);
55 colors[ImGuiCol_Button] = ConvertColorToImVec4(button);
56 colors[ImGuiCol_ButtonHovered] = ConvertColorToImVec4(button_hovered);
57 colors[ImGuiCol_ButtonActive] = ConvertColorToImVec4(button_active);
58 colors[ImGuiCol_Header] = ConvertColorToImVec4(header);
59 colors[ImGuiCol_HeaderHovered] = ConvertColorToImVec4(header_hovered);
60 colors[ImGuiCol_HeaderActive] = ConvertColorToImVec4(header_active);
61 colors[ImGuiCol_Separator] = ConvertColorToImVec4(separator);
62 colors[ImGuiCol_SeparatorHovered] = ConvertColorToImVec4(separator_hovered);
63 colors[ImGuiCol_SeparatorActive] = ConvertColorToImVec4(separator_active);
64 colors[ImGuiCol_ResizeGrip] = ConvertColorToImVec4(resize_grip);
65 colors[ImGuiCol_ResizeGripHovered] = ConvertColorToImVec4(resize_grip_hovered);
66 colors[ImGuiCol_ResizeGripActive] = ConvertColorToImVec4(resize_grip_active);
67 colors[ImGuiCol_Tab] = ConvertColorToImVec4(tab);
68 colors[ImGuiCol_TabHovered] = ConvertColorToImVec4(tab_hovered);
69 colors[ImGuiCol_TabSelected] = ConvertColorToImVec4(tab_active);
70 colors[ImGuiCol_TabUnfocused] = ConvertColorToImVec4(tab_unfocused);
71 colors[ImGuiCol_TabUnfocusedActive] = ConvertColorToImVec4(tab_unfocused_active);
72 colors[ImGuiCol_DockingPreview] = ConvertColorToImVec4(docking_preview);
73 colors[ImGuiCol_DockingEmptyBg] = ConvertColorToImVec4(docking_empty_bg);
74
75 // Complete ImGui color support
76 colors[ImGuiCol_CheckMark] = ConvertColorToImVec4(check_mark);
77 colors[ImGuiCol_SliderGrab] = ConvertColorToImVec4(slider_grab);
78 colors[ImGuiCol_SliderGrabActive] = ConvertColorToImVec4(slider_grab_active);
79 colors[ImGuiCol_InputTextCursor] = ConvertColorToImVec4(input_text_cursor);
80 colors[ImGuiCol_NavCursor] = ConvertColorToImVec4(nav_cursor);
81 colors[ImGuiCol_NavWindowingHighlight] = ConvertColorToImVec4(nav_windowing_highlight);
82 colors[ImGuiCol_NavWindowingDimBg] = ConvertColorToImVec4(nav_windowing_dim_bg);
83 colors[ImGuiCol_ModalWindowDimBg] = ConvertColorToImVec4(modal_window_dim_bg);
84 colors[ImGuiCol_TextSelectedBg] = ConvertColorToImVec4(text_selected_bg);
85 colors[ImGuiCol_DragDropTarget] = ConvertColorToImVec4(drag_drop_target);
86 colors[ImGuiCol_TableHeaderBg] = ConvertColorToImVec4(table_header_bg);
87 colors[ImGuiCol_TableBorderStrong] = ConvertColorToImVec4(table_border_strong);
88 colors[ImGuiCol_TableBorderLight] = ConvertColorToImVec4(table_border_light);
89 colors[ImGuiCol_TableRowBg] = ConvertColorToImVec4(table_row_bg);
90 colors[ImGuiCol_TableRowBgAlt] = ConvertColorToImVec4(table_row_bg_alt);
91 colors[ImGuiCol_TextLink] = ConvertColorToImVec4(text_link);
92 colors[ImGuiCol_PlotLines] = ConvertColorToImVec4(plot_lines);
93 colors[ImGuiCol_PlotLinesHovered] = ConvertColorToImVec4(plot_lines_hovered);
94 colors[ImGuiCol_PlotHistogram] = ConvertColorToImVec4(plot_histogram);
95 colors[ImGuiCol_PlotHistogramHovered] = ConvertColorToImVec4(plot_histogram_hovered);
96 colors[ImGuiCol_TreeLines] = ConvertColorToImVec4(tree_lines);
97
98 // Additional ImGui colors for complete coverage
99 colors[ImGuiCol_TabDimmed] = ConvertColorToImVec4(tab_dimmed);
100 colors[ImGuiCol_TabDimmedSelected] = ConvertColorToImVec4(tab_dimmed_selected);
101 colors[ImGuiCol_TabDimmedSelectedOverline] = ConvertColorToImVec4(tab_dimmed_selected_overline);
102 colors[ImGuiCol_TabSelectedOverline] = ConvertColorToImVec4(tab_selected_overline);
103
104 // Apply style parameters
105 style->WindowRounding = window_rounding;
106 style->FrameRounding = frame_rounding;
107 style->ScrollbarRounding = scrollbar_rounding;
108 style->GrabRounding = grab_rounding;
109 style->TabRounding = tab_rounding;
110 style->WindowBorderSize = window_border_size;
111 style->FrameBorderSize = frame_border_size;
112}
113
114
115// ThemeManager Implementation
117 static ThemeManager instance;
118 return instance;
119}
120
122 // Always create fallback theme first
124
125 // Create the Classic YAZE theme during initialization
127
128 // Load all available theme files dynamically
129 auto status = LoadAllAvailableThemes();
130 if (!status.ok()) {
131 LOG_ERROR("Theme Manager", "Failed to load some theme files");
132 }
133
134 // Ensure we have a valid current theme (Classic is already set above)
135 // Only fallback to file themes if Classic creation failed
136 if (current_theme_name_ != "Classic YAZE") {
137 if (themes_.find("YAZE Tre") != themes_.end()) {
138 current_theme_ = themes_["YAZE Tre"];
139 current_theme_name_ = "YAZE Tre";
140 }
141 }
142}
143
145 // Fallback theme that matches the original ColorsYaze() function colors but in theme format
146 EnhancedTheme theme;
147 theme.name = "YAZE Tre";
148 theme.description = "YAZE theme resource edition";
149 theme.author = "YAZE Team";
150
151 // Use the exact original ColorsYaze colors
152 theme.primary = RGBA(92, 115, 92); // allttpLightGreen
153 theme.secondary = RGBA(71, 92, 71); // alttpMidGreen
154 theme.accent = RGBA(89, 119, 89); // TabActive
155 theme.background = RGBA(8, 8, 8); // Very dark gray for better grid visibility
156
157 theme.text_primary = RGBA(230, 230, 230); // 0.90f, 0.90f, 0.90f
158 theme.text_disabled = RGBA(153, 153, 153); // 0.60f, 0.60f, 0.60f
159 theme.window_bg = RGBA(8, 8, 8, 217); // Very dark gray with same alpha
160 theme.child_bg = RGBA(0, 0, 0, 0); // Transparent
161 theme.popup_bg = RGBA(28, 28, 36, 235); // 0.11f, 0.11f, 0.14f, 0.92f
162
163 theme.button = RGBA(71, 92, 71); // alttpMidGreen
164 theme.button_hovered = RGBA(125, 146, 125); // allttpLightestGreen
165 theme.button_active = RGBA(92, 115, 92); // allttpLightGreen
166
167 theme.header = RGBA(46, 66, 46); // alttpDarkGreen
168 theme.header_hovered = RGBA(92, 115, 92); // allttpLightGreen
169 theme.header_active = RGBA(71, 92, 71); // alttpMidGreen
170
171 theme.menu_bar_bg = RGBA(46, 66, 46); // alttpDarkGreen
172 theme.tab = RGBA(46, 66, 46); // alttpDarkGreen
173 theme.tab_hovered = RGBA(71, 92, 71); // alttpMidGreen
174 theme.tab_active = RGBA(89, 119, 89); // TabActive
175 theme.tab_unfocused = RGBA(37, 52, 37); // Darker version of tab
176 theme.tab_unfocused_active = RGBA(62, 83, 62); // Darker version of tab_active
177
178 // Complete all remaining ImGui colors from original ColorsYaze() function
179 theme.title_bg = RGBA(71, 92, 71); // alttpMidGreen
180 theme.title_bg_active = RGBA(46, 66, 46); // alttpDarkGreen
181 theme.title_bg_collapsed = RGBA(71, 92, 71); // alttpMidGreen
182
183 // Initialize missing fields that were added to the struct
184 theme.surface = theme.background;
185 theme.error = RGBA(220, 50, 50);
186 theme.warning = RGBA(255, 200, 50);
187 theme.success = theme.primary;
188 theme.info = RGBA(70, 170, 255);
189 theme.text_secondary = RGBA(200, 200, 200);
190 theme.modal_bg = theme.popup_bg;
191
192 // Borders and separators
193 theme.border = RGBA(92, 115, 92); // allttpLightGreen
194 theme.border_shadow = RGBA(0, 0, 0, 0); // Transparent
195 theme.separator = RGBA(128, 128, 128, 153); // 0.50f, 0.50f, 0.50f, 0.60f
196 theme.separator_hovered = RGBA(153, 153, 178); // 0.60f, 0.60f, 0.70f
197 theme.separator_active = RGBA(178, 178, 230); // 0.70f, 0.70f, 0.90f
198
199 // Scrollbars
200 theme.scrollbar_bg = RGBA(92, 115, 92, 153); // 0.36f, 0.45f, 0.36f, 0.60f
201 theme.scrollbar_grab = RGBA(92, 115, 92, 76); // 0.36f, 0.45f, 0.36f, 0.30f
202 theme.scrollbar_grab_hovered = RGBA(92, 115, 92, 102); // 0.36f, 0.45f, 0.36f, 0.40f
203 theme.scrollbar_grab_active = RGBA(92, 115, 92, 153); // 0.36f, 0.45f, 0.36f, 0.60f
204
205 // Resize grips (from original - light blue highlights)
206 theme.resize_grip = RGBA(255, 255, 255, 26); // 1.00f, 1.00f, 1.00f, 0.10f
207 theme.resize_grip_hovered = RGBA(199, 209, 255, 153); // 0.78f, 0.82f, 1.00f, 0.60f
208 theme.resize_grip_active = RGBA(199, 209, 255, 230); // 0.78f, 0.82f, 1.00f, 0.90f
209
210 // ENHANCED: Complete ImGui colors with theme-aware smart defaults
211 // Use theme colors instead of hardcoded values for consistency
212 theme.check_mark = RGBA(125, 255, 125, 255); // Bright green checkmark (highly visible!)
213 theme.slider_grab = RGBA(92, 115, 92, 255); // Theme green (solid)
214 theme.slider_grab_active = RGBA(125, 146, 125, 255); // Lighter green when active
215 theme.input_text_cursor = RGBA(255, 255, 255, 255); // White cursor (always visible)
216 theme.nav_cursor = RGBA(125, 146, 125, 255); // Light green for navigation
217 theme.nav_windowing_highlight = RGBA(89, 119, 89, 200); // Accent with high visibility
218 theme.nav_windowing_dim_bg = RGBA(0, 0, 0, 150); // Darker overlay for better contrast
219 theme.modal_window_dim_bg = RGBA(0, 0, 0, 128); // 50% alpha for modals
220 theme.text_selected_bg = RGBA(92, 115, 92, 128); // Theme green with 50% alpha (visible selection!)
221 theme.drag_drop_target = RGBA(125, 146, 125, 200); // Bright green for drop zones
222
223 // Table colors (from original)
224 theme.table_header_bg = RGBA(46, 66, 46); // alttpDarkGreen
225 theme.table_border_strong = RGBA(71, 92, 71); // alttpMidGreen
226 theme.table_border_light = RGBA(66, 66, 71); // 0.26f, 0.26f, 0.28f
227 theme.table_row_bg = RGBA(0, 0, 0, 0); // Transparent
228 theme.table_row_bg_alt = RGBA(255, 255, 255, 18); // 1.00f, 1.00f, 1.00f, 0.07f
229
230 // Links and plots - use accent colors intelligently
231 theme.text_link = theme.accent; // Accent for links
232 theme.plot_lines = RGBA(255, 255, 255); // White for plots
233 theme.plot_lines_hovered = RGBA(230, 178, 0); // 0.90f, 0.70f, 0.00f
234 theme.plot_histogram = RGBA(230, 178, 0); // Same as above
235 theme.plot_histogram_hovered = RGBA(255, 153, 0); // 1.00f, 0.60f, 0.00f
236
237 // Docking colors
238 theme.docking_preview = RGBA(92, 115, 92, 180); // Light green with transparency
239 theme.docking_empty_bg = RGBA(46, 66, 46, 255); // Dark green
240
241 // Apply original style settings
242 theme.window_rounding = 0.0f;
243 theme.frame_rounding = 5.0f;
244 theme.scrollbar_rounding = 5.0f;
245 theme.tab_rounding = 0.0f;
246 theme.enable_glow_effects = false;
247
248 themes_["YAZE Tre"] = theme;
249 current_theme_ = theme;
250 current_theme_name_ = "YAZE Tre";
251}
252
253absl::Status ThemeManager::LoadTheme(const std::string& theme_name) {
254 auto it = themes_.find(theme_name);
255 if (it == themes_.end()) {
256 return absl::NotFoundError(absl::StrFormat("Theme '%s' not found", theme_name));
257 }
258
259 current_theme_ = it->second;
260 current_theme_name_ = theme_name;
262
263 return absl::OkStatus();
264}
265
266absl::Status ThemeManager::LoadThemeFromFile(const std::string& filepath) {
267 // Try multiple possible paths where theme files might be located
268 std::vector<std::string> possible_paths = {
269 filepath, // Absolute path
270 "assets/themes/" + filepath, // Relative from build dir
271 "../assets/themes/" + filepath, // Relative from bin dir
272 util::GetResourcePath("assets/themes/" + filepath), // Platform-specific resource path
273 };
274
275 std::ifstream file;
276 std::string successful_path;
277
278 for (const auto& path : possible_paths) {
279 file.open(path);
280 if (file.is_open()) {
281 successful_path = path;
282 break;
283 } else {
284 file.clear(); // Clear any error flags before trying next path
285 }
286 }
287
288 if (!file.is_open()) {
289 return absl::InvalidArgumentError(absl::StrFormat("Cannot open theme file: %s (tried %zu paths)",
290 filepath, possible_paths.size()));
291 }
292
293 std::string content((std::istreambuf_iterator<char>(file)),
294 std::istreambuf_iterator<char>());
295 file.close();
296
297 if (content.empty()) {
298 return absl::InvalidArgumentError(absl::StrFormat("Theme file is empty: %s", successful_path));
299 }
300
301 EnhancedTheme theme;
302 auto parse_status = ParseThemeFile(content, theme);
303 if (!parse_status.ok()) {
304 return absl::InvalidArgumentError(absl::StrFormat("Failed to parse theme file %s: %s",
305 successful_path, parse_status.message()));
306 }
307
308 if (theme.name.empty()) {
309 return absl::InvalidArgumentError(absl::StrFormat("Theme file missing name: %s", successful_path));
310 }
311
312 themes_[theme.name] = theme;
313 return absl::OkStatus();
314}
315
316std::vector<std::string> ThemeManager::GetAvailableThemes() const {
317 std::vector<std::string> theme_names;
318 for (const auto& [name, theme] : themes_) {
319 theme_names.push_back(name);
320 }
321 return theme_names;
322}
323
324const EnhancedTheme* ThemeManager::GetTheme(const std::string& name) const {
325 auto it = themes_.find(name);
326 return (it != themes_.end()) ? &it->second : nullptr;
327}
328
329void ThemeManager::ApplyTheme(const std::string& theme_name) {
330 auto status = LoadTheme(theme_name);
331 if (!status.ok()) {
332 // Fallback to YAZE Tre if theme not found
333 auto fallback_status = LoadTheme("YAZE Tre");
334 if (!fallback_status.ok()) {
335 LOG_ERROR("Theme Manager", "Failed to load fallback theme");
336 }
337 }
338}
339
341 current_theme_ = theme;
342 current_theme_name_ = theme.name; // CRITICAL: Update the name tracking
344}
345
347 // Create a darker version of the window background for welcome screen
349 return {bg.red * 0.8f, bg.green * 0.8f, bg.blue * 0.8f, bg.alpha};
350}
351
355
359
361 if (!p_open || !*p_open) return;
362
363 if (ImGui::Begin(absl::StrFormat("%s Theme Selector", ICON_MD_PALETTE).c_str(), p_open)) {
364
365 // Add subtle particle effects to theme selector
366 static float theme_animation_time = 0.0f;
367 theme_animation_time += ImGui::GetIO().DeltaTime;
368
369 ImDrawList* draw_list = ImGui::GetWindowDrawList();
370 ImVec2 window_pos = ImGui::GetWindowPos();
371 ImVec2 window_size = ImGui::GetWindowSize();
372
373 // Subtle corner particles for theme selector
374 for (int i = 0; i < 4; ++i) {
375 float corner_offset = i * 1.57f; // 90 degrees apart
376 float x = window_pos.x + window_size.x * 0.5f + cosf(theme_animation_time * 0.8f + corner_offset) * (window_size.x * 0.4f);
377 float y = window_pos.y + window_size.y * 0.5f + sinf(theme_animation_time * 0.8f + corner_offset) * (window_size.y * 0.4f);
378
379 float alpha = 0.1f + 0.1f * sinf(theme_animation_time * 1.2f + corner_offset);
380 auto current_theme = GetCurrentTheme();
381 ImU32 particle_color = ImGui::ColorConvertFloat4ToU32(ImVec4(
382 current_theme.accent.red, current_theme.accent.green, current_theme.accent.blue, alpha));
383
384 draw_list->AddCircleFilled(ImVec2(x, y), 3.0f, particle_color);
385 }
386
387 ImGui::Text("%s Available Themes", ICON_MD_COLOR_LENS);
388 ImGui::Separator();
389
390 // Add Classic YAZE button first (direct ColorsYaze() application)
391 bool is_classic_active = (current_theme_name_ == "Classic YAZE");
392 if (is_classic_active) {
393 ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.36f, 0.45f, 0.36f, 1.0f)); // allttpLightGreen
394 }
395
396 if (ImGui::Button(absl::StrFormat("%s YAZE Classic (Original)",
397 is_classic_active ? ICON_MD_CHECK : ICON_MD_STAR).c_str(),
398 ImVec2(-1, 50))) {
400 }
401
402 if (is_classic_active) {
403 ImGui::PopStyleColor();
404 }
405
406 if (ImGui::IsItemHovered()) {
407 ImGui::BeginTooltip();
408 ImGui::Text("Original YAZE theme using ColorsYaze() function");
409 ImGui::Text("This is the authentic classic look - direct function call");
410 ImGui::EndTooltip();
411 }
412
413 ImGui::Separator();
414
415 // Sort themes alphabetically for consistent ordering (by name only)
416 std::vector<std::string> sorted_theme_names;
417 for (const auto& [name, theme] : themes_) {
418 sorted_theme_names.push_back(name);
419 }
420 std::sort(sorted_theme_names.begin(), sorted_theme_names.end());
421
422 for (const auto& name : sorted_theme_names) {
423 const auto& theme = themes_.at(name);
424 bool is_current = (name == current_theme_name_);
425
426 if (is_current) {
427 ImGui::PushStyleColor(ImGuiCol_Button, ConvertColorToImVec4(theme.accent));
428 }
429
430 if (ImGui::Button(absl::StrFormat("%s %s",
431 is_current ? ICON_MD_CHECK : ICON_MD_CIRCLE,
432 name.c_str()).c_str(), ImVec2(-1, 40))) {
433 auto status = LoadTheme(name); // Use LoadTheme instead of ApplyTheme to ensure correct tracking
434 if (!status.ok()) {
435 LOG_ERROR("Theme Manager", "Failed to load theme %s", name.c_str());
436 }
437 }
438
439 if (is_current) {
440 ImGui::PopStyleColor();
441 }
442
443 // Show theme preview colors
444 ImGui::SameLine();
445 ImGui::ColorButton(absl::StrFormat("##primary_%s", name.c_str()).c_str(),
446 ConvertColorToImVec4(theme.primary),
447 ImGuiColorEditFlags_NoTooltip, ImVec2(20, 20));
448 ImGui::SameLine();
449 ImGui::ColorButton(absl::StrFormat("##secondary_%s", name.c_str()).c_str(),
450 ConvertColorToImVec4(theme.secondary),
451 ImGuiColorEditFlags_NoTooltip, ImVec2(20, 20));
452 ImGui::SameLine();
453 ImGui::ColorButton(absl::StrFormat("##accent_%s", name.c_str()).c_str(),
454 ConvertColorToImVec4(theme.accent),
455 ImGuiColorEditFlags_NoTooltip, ImVec2(20, 20));
456
457 if (ImGui::IsItemHovered()) {
458 ImGui::BeginTooltip();
459 ImGui::Text("%s", theme.description.c_str());
460 ImGui::Text("Author: %s", theme.author.c_str());
461 ImGui::EndTooltip();
462 }
463 }
464
465 ImGui::Separator();
466 if (ImGui::Button(absl::StrFormat("%s Refresh Themes", ICON_MD_REFRESH).c_str())) {
467 auto status = RefreshAvailableThemes();
468 if (!status.ok()) {
469 LOG_ERROR("Theme Manager", "Failed to refresh themes");
470 }
471 }
472
473 ImGui::SameLine();
474 if (ImGui::Button(absl::StrFormat("%s Load Custom Theme", ICON_MD_FOLDER_OPEN).c_str())) {
476 if (!file_path.empty()) {
477 auto status = LoadThemeFromFile(file_path);
478 if (!status.ok()) {
479 // Show error toast (would need access to toast manager)
480 }
481 }
482 }
483
484 ImGui::SameLine();
485 static bool show_simple_editor = false;
486 if (ImGui::Button(absl::StrFormat("%s Theme Editor", ICON_MD_EDIT).c_str())) {
487 show_simple_editor = true;
488 }
489
490 if (ImGui::IsItemHovered()) {
491 ImGui::BeginTooltip();
492 ImGui::Text("Edit and save custom themes");
493 ImGui::Text("Includes 'Save to File' functionality");
494 ImGui::EndTooltip();
495 }
496
497 if (show_simple_editor) {
498 ShowSimpleThemeEditor(&show_simple_editor);
499 }
500 }
501 ImGui::End();
502}
503
504absl::Status ThemeManager::ParseThemeFile(const std::string& content, EnhancedTheme& theme) {
505 std::istringstream stream(content);
506 std::string line;
507 std::string current_section = "";
508
509 while (std::getline(stream, line)) {
510 // Skip empty lines and comments
511 if (line.empty() || line[0] == '#') continue;
512
513 // Check for section headers [section_name]
514 if (line[0] == '[' && line.back() == ']') {
515 current_section = line.substr(1, line.length() - 2);
516 continue;
517 }
518
519 size_t eq_pos = line.find('=');
520 if (eq_pos == std::string::npos) continue;
521
522 std::string key = line.substr(0, eq_pos);
523 std::string value = line.substr(eq_pos + 1);
524
525 // Trim whitespace and comments
526 key.erase(0, key.find_first_not_of(" \t"));
527 key.erase(key.find_last_not_of(" \t") + 1);
528 value.erase(0, value.find_first_not_of(" \t"));
529
530 // Remove inline comments
531 size_t comment_pos = value.find('#');
532 if (comment_pos != std::string::npos) {
533 value = value.substr(0, comment_pos);
534 }
535 value.erase(value.find_last_not_of(" \t") + 1);
536
537 // Parse based on section
538 if (current_section == "colors") {
539 Color color = ParseColorFromString(value);
540
541 if (key == "primary") theme.primary = color;
542 else if (key == "secondary") theme.secondary = color;
543 else if (key == "accent") theme.accent = color;
544 else if (key == "background") theme.background = color;
545 else if (key == "surface") theme.surface = color;
546 else if (key == "error") theme.error = color;
547 else if (key == "warning") theme.warning = color;
548 else if (key == "success") theme.success = color;
549 else if (key == "info") theme.info = color;
550 else if (key == "text_primary") theme.text_primary = color;
551 else if (key == "text_secondary") theme.text_secondary = color;
552 else if (key == "text_disabled") theme.text_disabled = color;
553 else if (key == "window_bg") theme.window_bg = color;
554 else if (key == "child_bg") theme.child_bg = color;
555 else if (key == "popup_bg") theme.popup_bg = color;
556 else if (key == "button") theme.button = color;
557 else if (key == "button_hovered") theme.button_hovered = color;
558 else if (key == "button_active") theme.button_active = color;
559 else if (key == "frame_bg") theme.frame_bg = color;
560 else if (key == "frame_bg_hovered") theme.frame_bg_hovered = color;
561 else if (key == "frame_bg_active") theme.frame_bg_active = color;
562 else if (key == "header") theme.header = color;
563 else if (key == "header_hovered") theme.header_hovered = color;
564 else if (key == "header_active") theme.header_active = color;
565 else if (key == "tab") theme.tab = color;
566 else if (key == "tab_hovered") theme.tab_hovered = color;
567 else if (key == "tab_active") theme.tab_active = color;
568 else if (key == "menu_bar_bg") theme.menu_bar_bg = color;
569 else if (key == "title_bg") theme.title_bg = color;
570 else if (key == "title_bg_active") theme.title_bg_active = color;
571 else if (key == "title_bg_collapsed") theme.title_bg_collapsed = color;
572 else if (key == "separator") theme.separator = color;
573 else if (key == "separator_hovered") theme.separator_hovered = color;
574 else if (key == "separator_active") theme.separator_active = color;
575 else if (key == "scrollbar_bg") theme.scrollbar_bg = color;
576 else if (key == "scrollbar_grab") theme.scrollbar_grab = color;
577 else if (key == "scrollbar_grab_hovered") theme.scrollbar_grab_hovered = color;
578 else if (key == "scrollbar_grab_active") theme.scrollbar_grab_active = color;
579 else if (key == "border") theme.border = color;
580 else if (key == "border_shadow") theme.border_shadow = color;
581 else if (key == "resize_grip") theme.resize_grip = color;
582 else if (key == "resize_grip_hovered") theme.resize_grip_hovered = color;
583 else if (key == "resize_grip_active") theme.resize_grip_active = color;
584 else if (key == "check_mark") theme.check_mark = color;
585 else if (key == "slider_grab") theme.slider_grab = color;
586 else if (key == "slider_grab_active") theme.slider_grab_active = color;
587 else if (key == "input_text_cursor") theme.input_text_cursor = color;
588 else if (key == "nav_cursor") theme.nav_cursor = color;
589 else if (key == "nav_windowing_highlight") theme.nav_windowing_highlight = color;
590 else if (key == "nav_windowing_dim_bg") theme.nav_windowing_dim_bg = color;
591 else if (key == "modal_window_dim_bg") theme.modal_window_dim_bg = color;
592 else if (key == "text_selected_bg") theme.text_selected_bg = color;
593 else if (key == "drag_drop_target") theme.drag_drop_target = color;
594 else if (key == "table_header_bg") theme.table_header_bg = color;
595 else if (key == "table_border_strong") theme.table_border_strong = color;
596 else if (key == "table_border_light") theme.table_border_light = color;
597 else if (key == "table_row_bg") theme.table_row_bg = color;
598 else if (key == "table_row_bg_alt") theme.table_row_bg_alt = color;
599 else if (key == "text_link") theme.text_link = color;
600 else if (key == "plot_lines") theme.plot_lines = color;
601 else if (key == "plot_lines_hovered") theme.plot_lines_hovered = color;
602 else if (key == "plot_histogram") theme.plot_histogram = color;
603 else if (key == "plot_histogram_hovered") theme.plot_histogram_hovered = color;
604 else if (key == "tree_lines") theme.tree_lines = color;
605 else if (key == "tab_dimmed") theme.tab_dimmed = color;
606 else if (key == "tab_dimmed_selected") theme.tab_dimmed_selected = color;
607 else if (key == "tab_dimmed_selected_overline") theme.tab_dimmed_selected_overline = color;
608 else if (key == "tab_selected_overline") theme.tab_selected_overline = color;
609 else if (key == "docking_preview") theme.docking_preview = color;
610 else if (key == "docking_empty_bg") theme.docking_empty_bg = color;
611 }
612 else if (current_section == "style") {
613 if (key == "window_rounding") theme.window_rounding = std::stof(value);
614 else if (key == "frame_rounding") theme.frame_rounding = std::stof(value);
615 else if (key == "scrollbar_rounding") theme.scrollbar_rounding = std::stof(value);
616 else if (key == "grab_rounding") theme.grab_rounding = std::stof(value);
617 else if (key == "tab_rounding") theme.tab_rounding = std::stof(value);
618 else if (key == "window_border_size") theme.window_border_size = std::stof(value);
619 else if (key == "frame_border_size") theme.frame_border_size = std::stof(value);
620 else if (key == "enable_animations") theme.enable_animations = (value == "true");
621 else if (key == "enable_glow_effects") theme.enable_glow_effects = (value == "true");
622 else if (key == "animation_speed") theme.animation_speed = std::stof(value);
623 }
624 else if (current_section == "" || current_section == "metadata") {
625 // Top-level metadata
626 if (key == "name") theme.name = value;
627 else if (key == "description") theme.description = value;
628 else if (key == "author") theme.author = value;
629 }
630 }
631
632 return absl::OkStatus();
633}
634
635Color ThemeManager::ParseColorFromString(const std::string& color_str) const {
636 std::vector<std::string> components = absl::StrSplit(color_str, ',');
637 if (components.size() != 4) {
638 return RGBA(255, 255, 255, 255); // White fallback
639 }
640
641 try {
642 int r = std::stoi(components[0]);
643 int g = std::stoi(components[1]);
644 int b = std::stoi(components[2]);
645 int a = std::stoi(components[3]);
646 return RGBA(r, g, b, a);
647 } catch (...) {
648 return RGBA(255, 255, 255, 255); // White fallback
649 }
650}
651
652std::string ThemeManager::SerializeTheme(const EnhancedTheme& theme) const {
653 std::ostringstream ss;
654
655 // Helper function to convert color to RGB string
656 auto colorToString = [](const Color& c) -> std::string {
657 int r = static_cast<int>(c.red * 255.0f);
658 int g = static_cast<int>(c.green * 255.0f);
659 int b = static_cast<int>(c.blue * 255.0f);
660 int a = static_cast<int>(c.alpha * 255.0f);
661 return std::to_string(r) + "," + std::to_string(g) + "," + std::to_string(b) + "," + std::to_string(a);
662 };
663
664 ss << "# yaze Theme File\n";
665 ss << "# Generated by YAZE Theme Editor\n";
666 ss << "name=" << theme.name << "\n";
667 ss << "description=" << theme.description << "\n";
668 ss << "author=" << theme.author << "\n";
669 ss << "version=1.0\n";
670 ss << "\n[colors]\n";
671
672 // Primary colors
673 ss << "# Primary colors\n";
674 ss << "primary=" << colorToString(theme.primary) << "\n";
675 ss << "secondary=" << colorToString(theme.secondary) << "\n";
676 ss << "accent=" << colorToString(theme.accent) << "\n";
677 ss << "background=" << colorToString(theme.background) << "\n";
678 ss << "surface=" << colorToString(theme.surface) << "\n";
679 ss << "\n";
680
681 // Status colors
682 ss << "# Status colors\n";
683 ss << "error=" << colorToString(theme.error) << "\n";
684 ss << "warning=" << colorToString(theme.warning) << "\n";
685 ss << "success=" << colorToString(theme.success) << "\n";
686 ss << "info=" << colorToString(theme.info) << "\n";
687 ss << "\n";
688
689 // Text colors
690 ss << "# Text colors\n";
691 ss << "text_primary=" << colorToString(theme.text_primary) << "\n";
692 ss << "text_secondary=" << colorToString(theme.text_secondary) << "\n";
693 ss << "text_disabled=" << colorToString(theme.text_disabled) << "\n";
694 ss << "\n";
695
696 // Window colors
697 ss << "# Window colors\n";
698 ss << "window_bg=" << colorToString(theme.window_bg) << "\n";
699 ss << "child_bg=" << colorToString(theme.child_bg) << "\n";
700 ss << "popup_bg=" << colorToString(theme.popup_bg) << "\n";
701 ss << "\n";
702
703 // Interactive elements
704 ss << "# Interactive elements\n";
705 ss << "button=" << colorToString(theme.button) << "\n";
706 ss << "button_hovered=" << colorToString(theme.button_hovered) << "\n";
707 ss << "button_active=" << colorToString(theme.button_active) << "\n";
708 ss << "frame_bg=" << colorToString(theme.frame_bg) << "\n";
709 ss << "frame_bg_hovered=" << colorToString(theme.frame_bg_hovered) << "\n";
710 ss << "frame_bg_active=" << colorToString(theme.frame_bg_active) << "\n";
711 ss << "\n";
712
713 // Navigation
714 ss << "# Navigation\n";
715 ss << "header=" << colorToString(theme.header) << "\n";
716 ss << "header_hovered=" << colorToString(theme.header_hovered) << "\n";
717 ss << "header_active=" << colorToString(theme.header_active) << "\n";
718 ss << "tab=" << colorToString(theme.tab) << "\n";
719 ss << "tab_hovered=" << colorToString(theme.tab_hovered) << "\n";
720 ss << "tab_active=" << colorToString(theme.tab_active) << "\n";
721 ss << "menu_bar_bg=" << colorToString(theme.menu_bar_bg) << "\n";
722 ss << "title_bg=" << colorToString(theme.title_bg) << "\n";
723 ss << "title_bg_active=" << colorToString(theme.title_bg_active) << "\n";
724 ss << "title_bg_collapsed=" << colorToString(theme.title_bg_collapsed) << "\n";
725 ss << "\n";
726
727 // Borders and separators
728 ss << "# Borders and separators\n";
729 ss << "border=" << colorToString(theme.border) << "\n";
730 ss << "border_shadow=" << colorToString(theme.border_shadow) << "\n";
731 ss << "separator=" << colorToString(theme.separator) << "\n";
732 ss << "separator_hovered=" << colorToString(theme.separator_hovered) << "\n";
733 ss << "separator_active=" << colorToString(theme.separator_active) << "\n";
734 ss << "\n";
735
736 // Scrollbars and controls
737 ss << "# Scrollbars and controls\n";
738 ss << "scrollbar_bg=" << colorToString(theme.scrollbar_bg) << "\n";
739 ss << "scrollbar_grab=" << colorToString(theme.scrollbar_grab) << "\n";
740 ss << "scrollbar_grab_hovered=" << colorToString(theme.scrollbar_grab_hovered) << "\n";
741 ss << "scrollbar_grab_active=" << colorToString(theme.scrollbar_grab_active) << "\n";
742 ss << "resize_grip=" << colorToString(theme.resize_grip) << "\n";
743 ss << "resize_grip_hovered=" << colorToString(theme.resize_grip_hovered) << "\n";
744 ss << "resize_grip_active=" << colorToString(theme.resize_grip_active) << "\n";
745 ss << "check_mark=" << colorToString(theme.check_mark) << "\n";
746 ss << "slider_grab=" << colorToString(theme.slider_grab) << "\n";
747 ss << "slider_grab_active=" << colorToString(theme.slider_grab_active) << "\n";
748 ss << "\n";
749
750 // Navigation and special elements
751 ss << "# Navigation and special elements\n";
752 ss << "input_text_cursor=" << colorToString(theme.input_text_cursor) << "\n";
753 ss << "nav_cursor=" << colorToString(theme.nav_cursor) << "\n";
754 ss << "nav_windowing_highlight=" << colorToString(theme.nav_windowing_highlight) << "\n";
755 ss << "nav_windowing_dim_bg=" << colorToString(theme.nav_windowing_dim_bg) << "\n";
756 ss << "modal_window_dim_bg=" << colorToString(theme.modal_window_dim_bg) << "\n";
757 ss << "text_selected_bg=" << colorToString(theme.text_selected_bg) << "\n";
758 ss << "drag_drop_target=" << colorToString(theme.drag_drop_target) << "\n";
759 ss << "docking_preview=" << colorToString(theme.docking_preview) << "\n";
760 ss << "docking_empty_bg=" << colorToString(theme.docking_empty_bg) << "\n";
761 ss << "\n";
762
763 // Table colors
764 ss << "# Table colors\n";
765 ss << "table_header_bg=" << colorToString(theme.table_header_bg) << "\n";
766 ss << "table_border_strong=" << colorToString(theme.table_border_strong) << "\n";
767 ss << "table_border_light=" << colorToString(theme.table_border_light) << "\n";
768 ss << "table_row_bg=" << colorToString(theme.table_row_bg) << "\n";
769 ss << "table_row_bg_alt=" << colorToString(theme.table_row_bg_alt) << "\n";
770 ss << "\n";
771
772 // Links and plots
773 ss << "# Links and plots\n";
774 ss << "text_link=" << colorToString(theme.text_link) << "\n";
775 ss << "plot_lines=" << colorToString(theme.plot_lines) << "\n";
776 ss << "plot_lines_hovered=" << colorToString(theme.plot_lines_hovered) << "\n";
777 ss << "plot_histogram=" << colorToString(theme.plot_histogram) << "\n";
778 ss << "plot_histogram_hovered=" << colorToString(theme.plot_histogram_hovered) << "\n";
779 ss << "tree_lines=" << colorToString(theme.tree_lines) << "\n";
780 ss << "\n";
781
782 // Tab variations
783 ss << "# Tab variations\n";
784 ss << "tab_dimmed=" << colorToString(theme.tab_dimmed) << "\n";
785 ss << "tab_dimmed_selected=" << colorToString(theme.tab_dimmed_selected) << "\n";
786 ss << "tab_dimmed_selected_overline=" << colorToString(theme.tab_dimmed_selected_overline) << "\n";
787 ss << "tab_selected_overline=" << colorToString(theme.tab_selected_overline) << "\n";
788 ss << "\n";
789
790 // Enhanced semantic colors
791 ss << "# Enhanced semantic colors\n";
792 ss << "text_highlight=" << colorToString(theme.text_highlight) << "\n";
793 ss << "link_hover=" << colorToString(theme.link_hover) << "\n";
794 ss << "code_background=" << colorToString(theme.code_background) << "\n";
795 ss << "success_light=" << colorToString(theme.success_light) << "\n";
796 ss << "warning_light=" << colorToString(theme.warning_light) << "\n";
797 ss << "error_light=" << colorToString(theme.error_light) << "\n";
798 ss << "info_light=" << colorToString(theme.info_light) << "\n";
799 ss << "\n";
800
801 // UI state colors
802 ss << "# UI state colors\n";
803 ss << "active_selection=" << colorToString(theme.active_selection) << "\n";
804 ss << "hover_highlight=" << colorToString(theme.hover_highlight) << "\n";
805 ss << "focus_border=" << colorToString(theme.focus_border) << "\n";
806 ss << "disabled_overlay=" << colorToString(theme.disabled_overlay) << "\n";
807 ss << "\n";
808
809 // Editor-specific colors
810 ss << "# Editor-specific colors\n";
811 ss << "editor_background=" << colorToString(theme.editor_background) << "\n";
812 ss << "editor_grid=" << colorToString(theme.editor_grid) << "\n";
813 ss << "editor_cursor=" << colorToString(theme.editor_cursor) << "\n";
814 ss << "editor_selection=" << colorToString(theme.editor_selection) << "\n";
815 ss << "\n";
816
817 // Style settings
818 ss << "[style]\n";
819 ss << "window_rounding=" << theme.window_rounding << "\n";
820 ss << "frame_rounding=" << theme.frame_rounding << "\n";
821 ss << "scrollbar_rounding=" << theme.scrollbar_rounding << "\n";
822 ss << "tab_rounding=" << theme.tab_rounding << "\n";
823 ss << "enable_animations=" << (theme.enable_animations ? "true" : "false") << "\n";
824 ss << "enable_glow_effects=" << (theme.enable_glow_effects ? "true" : "false") << "\n";
825
826 return ss.str();
827}
828
829absl::Status ThemeManager::SaveThemeToFile(const EnhancedTheme& theme, const std::string& filepath) const {
830 std::string theme_content = SerializeTheme(theme);
831
832 std::ofstream file(filepath);
833 if (!file.is_open()) {
834 return absl::InternalError(absl::StrFormat("Failed to open file for writing: %s", filepath));
835 }
836
837 file << theme_content;
838 file.close();
839
840 if (file.fail()) {
841 return absl::InternalError(absl::StrFormat("Failed to write theme file: %s", filepath));
842 }
843
844 return absl::OkStatus();
845}
846
848 // Apply the original ColorsYaze() function directly
849 ColorsYaze();
850 current_theme_name_ = "Classic YAZE";
851
852 // Create a complete Classic theme object that matches what ColorsYaze() sets
853 EnhancedTheme classic_theme;
854 classic_theme.name = "Classic YAZE";
855 classic_theme.description = "Original YAZE theme (direct ColorsYaze() function)";
856 classic_theme.author = "YAZE Team";
857
858 // Extract ALL the colors that ColorsYaze() sets (copy from CreateFallbackYazeClassic)
859 classic_theme.primary = RGBA(92, 115, 92); // allttpLightGreen
860 classic_theme.secondary = RGBA(71, 92, 71); // alttpMidGreen
861 classic_theme.accent = RGBA(89, 119, 89); // TabActive
862 classic_theme.background = RGBA(8, 8, 8); // Very dark gray for better grid visibility
863
864 classic_theme.text_primary = RGBA(230, 230, 230); // 0.90f, 0.90f, 0.90f
865 classic_theme.text_disabled = RGBA(153, 153, 153); // 0.60f, 0.60f, 0.60f
866 classic_theme.window_bg = RGBA(8, 8, 8, 217); // Very dark gray with same alpha
867 classic_theme.child_bg = RGBA(0, 0, 0, 0); // Transparent
868 classic_theme.popup_bg = RGBA(28, 28, 36, 235); // 0.11f, 0.11f, 0.14f, 0.92f
869
870 classic_theme.button = RGBA(71, 92, 71); // alttpMidGreen
871 classic_theme.button_hovered = RGBA(125, 146, 125); // allttpLightestGreen
872 classic_theme.button_active = RGBA(92, 115, 92); // allttpLightGreen
873
874 classic_theme.header = RGBA(46, 66, 46); // alttpDarkGreen
875 classic_theme.header_hovered = RGBA(92, 115, 92); // allttpLightGreen
876 classic_theme.header_active = RGBA(71, 92, 71); // alttpMidGreen
877
878 classic_theme.menu_bar_bg = RGBA(46, 66, 46); // alttpDarkGreen
879 classic_theme.tab = RGBA(46, 66, 46); // alttpDarkGreen
880 classic_theme.tab_hovered = RGBA(71, 92, 71); // alttpMidGreen
881 classic_theme.tab_active = RGBA(89, 119, 89); // TabActive
882 classic_theme.tab_unfocused = RGBA(37, 52, 37); // Darker version of tab
883 classic_theme.tab_unfocused_active = RGBA(62, 83, 62); // Darker version of tab_active
884
885 // Complete all remaining ImGui colors from original ColorsYaze() function
886 classic_theme.title_bg = RGBA(71, 92, 71); // alttpMidGreen
887 classic_theme.title_bg_active = RGBA(46, 66, 46); // alttpDarkGreen
888 classic_theme.title_bg_collapsed = RGBA(71, 92, 71); // alttpMidGreen
889
890 // Borders and separators
891 classic_theme.border = RGBA(92, 115, 92); // allttpLightGreen
892 classic_theme.border_shadow = RGBA(0, 0, 0, 0); // Transparent
893 classic_theme.separator = RGBA(128, 128, 128, 153); // 0.50f, 0.50f, 0.50f, 0.60f
894 classic_theme.separator_hovered = RGBA(153, 153, 178); // 0.60f, 0.60f, 0.70f
895 classic_theme.separator_active = RGBA(178, 178, 230); // 0.70f, 0.70f, 0.90f
896
897 // Scrollbars
898 classic_theme.scrollbar_bg = RGBA(92, 115, 92, 153); // 0.36f, 0.45f, 0.36f, 0.60f
899 classic_theme.scrollbar_grab = RGBA(92, 115, 92, 76); // 0.36f, 0.45f, 0.36f, 0.30f
900 classic_theme.scrollbar_grab_hovered = RGBA(92, 115, 92, 102); // 0.36f, 0.45f, 0.36f, 0.40f
901 classic_theme.scrollbar_grab_active = RGBA(92, 115, 92, 153); // 0.36f, 0.45f, 0.36f, 0.60f
902
903 // ENHANCED: Frame colors for inputs/widgets
904 classic_theme.frame_bg = RGBA(46, 66, 46, 140); // Darker green with some transparency
905 classic_theme.frame_bg_hovered = RGBA(71, 92, 71, 170); // Mid green when hovered
906 classic_theme.frame_bg_active = RGBA(92, 115, 92, 200); // Light green when active
907
908 // FIXED: Resize grips with better visibility
909 classic_theme.resize_grip = RGBA(92, 115, 92, 80); // Theme green, subtle
910 classic_theme.resize_grip_hovered = RGBA(125, 146, 125, 180); // Brighter when hovered
911 classic_theme.resize_grip_active = RGBA(125, 146, 125, 255); // Solid when active
912
913 // FIXED: Checkmark - bright green for high visibility!
914 classic_theme.check_mark = RGBA(125, 255, 125, 255); // Bright green (clearly visible)
915
916 // FIXED: Sliders with theme colors
917 classic_theme.slider_grab = RGBA(92, 115, 92, 255); // Theme green (solid)
918 classic_theme.slider_grab_active = RGBA(125, 146, 125, 255); // Lighter when grabbed
919
920 // FIXED: Input cursor - white for maximum visibility
921 classic_theme.input_text_cursor = RGBA(255, 255, 255, 255); // White cursor (always visible)
922
923 // FIXED: Navigation with theme colors
924 classic_theme.nav_cursor = RGBA(125, 146, 125, 255); // Light green navigation
925 classic_theme.nav_windowing_highlight = RGBA(92, 115, 92, 200); // Theme green highlight
926 classic_theme.nav_windowing_dim_bg = RGBA(0, 0, 0, 150); // Darker overlay
927
928 // FIXED: Modals with better dimming
929 classic_theme.modal_window_dim_bg = RGBA(0, 0, 0, 128); // 50% alpha
930
931 // FIXED: Text selection - visible and theme-appropriate!
932 classic_theme.text_selected_bg = RGBA(92, 115, 92, 128); // Theme green with 50% alpha (visible!)
933
934 // FIXED: Drag/drop target with high visibility
935 classic_theme.drag_drop_target = RGBA(125, 146, 125, 200); // Bright green
936 classic_theme.table_header_bg = RGBA(46, 66, 46);
937 classic_theme.table_border_strong = RGBA(71, 92, 71);
938 classic_theme.table_border_light = RGBA(66, 66, 71);
939 classic_theme.table_row_bg = RGBA(0, 0, 0, 0);
940 classic_theme.table_row_bg_alt = RGBA(255, 255, 255, 18);
941 classic_theme.text_link = classic_theme.accent;
942 classic_theme.plot_lines = RGBA(255, 255, 255);
943 classic_theme.plot_lines_hovered = RGBA(230, 178, 0);
944 classic_theme.plot_histogram = RGBA(230, 178, 0);
945 classic_theme.plot_histogram_hovered = RGBA(255, 153, 0);
946 classic_theme.docking_preview = RGBA(92, 115, 92, 180);
947 classic_theme.docking_empty_bg = RGBA(46, 66, 46, 255);
948 classic_theme.tree_lines = classic_theme.separator; // Use separator color for tree lines
949
950 // Tab dimmed colors (for unfocused tabs)
951 classic_theme.tab_dimmed = RGBA(37, 52, 37); // Darker version of tab
952 classic_theme.tab_dimmed_selected = RGBA(62, 83, 62); // Darker version of tab_active
953 classic_theme.tab_dimmed_selected_overline = classic_theme.accent;
954 classic_theme.tab_selected_overline = classic_theme.accent;
955
956 // Enhanced semantic colors for better theming
957 classic_theme.text_highlight = RGBA(255, 255, 150); // Light yellow for highlights
958 classic_theme.link_hover = RGBA(140, 220, 255); // Brighter blue for link hover
959 classic_theme.code_background = RGBA(40, 60, 40); // Slightly darker green for code
960 classic_theme.success_light = RGBA(140, 195, 140); // Light green
961 classic_theme.warning_light = RGBA(255, 220, 100); // Light yellow
962 classic_theme.error_light = RGBA(255, 150, 150); // Light red
963 classic_theme.info_light = RGBA(150, 200, 255); // Light blue
964
965 // UI state colors
966 classic_theme.active_selection = classic_theme.accent; // Use accent color for active selection
967 classic_theme.hover_highlight = RGBA(92, 115, 92, 100); // Semi-transparent green
968 classic_theme.focus_border = classic_theme.primary; // Use primary for focus
969 classic_theme.disabled_overlay = RGBA(50, 50, 50, 128); // Gray overlay
970
971 // Editor-specific colors
972 classic_theme.editor_background = RGBA(30, 45, 30); // Dark green background
973 classic_theme.editor_grid = RGBA(80, 100, 80, 100); // Subtle grid lines
974 classic_theme.editor_cursor = RGBA(255, 255, 255); // White cursor
975 classic_theme.editor_selection = RGBA(110, 145, 110, 100); // Semi-transparent selection
976
977 // Apply original style settings
978 classic_theme.window_rounding = 0.0f;
979 classic_theme.frame_rounding = 5.0f;
980 classic_theme.scrollbar_rounding = 5.0f;
981 classic_theme.tab_rounding = 0.0f;
982 classic_theme.enable_glow_effects = false;
983
984 // DON'T add Classic theme to themes map - keep it as a special case
985 // themes_["Classic YAZE"] = classic_theme; // REMOVED to prevent off-by-one
986 current_theme_ = classic_theme;
987}
988
990 if (!p_open || !*p_open) return;
991
992 ImGui::SetNextWindowSize(ImVec2(800, 600), ImGuiCond_FirstUseEver);
993
994 if (ImGui::Begin(absl::StrFormat("%s Theme Editor", ICON_MD_PALETTE).c_str(), p_open,
995 ImGuiWindowFlags_MenuBar)) {
996
997 // Add gentle particle effects to theme editor background
998 static float editor_animation_time = 0.0f;
999 editor_animation_time += ImGui::GetIO().DeltaTime;
1000
1001 ImDrawList* draw_list = ImGui::GetWindowDrawList();
1002 ImVec2 window_pos = ImGui::GetWindowPos();
1003 ImVec2 window_size = ImGui::GetWindowSize();
1004
1005 // Floating color orbs representing different color categories
1006 auto current_theme = GetCurrentTheme();
1007 std::vector<gui::Color> theme_colors = {
1008 current_theme.primary, current_theme.secondary, current_theme.accent,
1009 current_theme.success, current_theme.warning, current_theme.error
1010 };
1011
1012 for (size_t i = 0; i < theme_colors.size(); ++i) {
1013 float time_offset = i * 1.0f;
1014 float orbit_radius = 60.0f + i * 8.0f;
1015 float x = window_pos.x + window_size.x * 0.8f + cosf(editor_animation_time * 0.3f + time_offset) * orbit_radius;
1016 float y = window_pos.y + window_size.y * 0.3f + sinf(editor_animation_time * 0.3f + time_offset) * orbit_radius;
1017
1018 float alpha = 0.15f + 0.1f * sinf(editor_animation_time * 1.5f + time_offset);
1019 ImU32 orb_color = ImGui::ColorConvertFloat4ToU32(ImVec4(
1020 theme_colors[i].red, theme_colors[i].green, theme_colors[i].blue, alpha));
1021
1022 float radius = 4.0f + sinf(editor_animation_time * 2.0f + time_offset) * 1.0f;
1023 draw_list->AddCircleFilled(ImVec2(x, y), radius, orb_color);
1024 }
1025
1026 // Menu bar for theme operations
1027 if (ImGui::BeginMenuBar()) {
1028 if (ImGui::BeginMenu("File")) {
1029 if (ImGui::MenuItem(absl::StrFormat("%s New Theme", ICON_MD_ADD).c_str())) {
1030 // Reset to default theme
1032 }
1033 if (ImGui::MenuItem(absl::StrFormat("%s Load Theme", ICON_MD_FOLDER_OPEN).c_str())) {
1035 if (!file_path.empty()) {
1036 LoadThemeFromFile(file_path);
1037 }
1038 }
1039 ImGui::Separator();
1040 if (ImGui::MenuItem(absl::StrFormat("%s Save Theme", ICON_MD_SAVE).c_str())) {
1041 // Save current theme to its existing file
1042 std::string current_file_path = GetCurrentThemeFilePath();
1043 if (!current_file_path.empty()) {
1044 auto status = SaveThemeToFile(current_theme_, current_file_path);
1045 if (!status.ok()) {
1046 LOG_ERROR("Theme Manager", "Failed to save theme");
1047 }
1048 } else {
1049 // No existing file, prompt for new location
1051 if (!file_path.empty()) {
1052 auto status = SaveThemeToFile(current_theme_, file_path);
1053 if (!status.ok()) {
1054 LOG_ERROR("Theme Manager", "Failed to save theme");
1055 }
1056 }
1057 }
1058 }
1059 if (ImGui::MenuItem(absl::StrFormat("%s Save As...", ICON_MD_SAVE_AS).c_str())) {
1060 // Save theme to new file
1062 if (!file_path.empty()) {
1063 auto status = SaveThemeToFile(current_theme_, file_path);
1064 if (!status.ok()) {
1065 LOG_ERROR("Theme Manager", "Failed to save theme");
1066 }
1067 }
1068 }
1069 ImGui::EndMenu();
1070 }
1071
1072 if (ImGui::BeginMenu("Presets")) {
1073 if (ImGui::MenuItem("YAZE Classic")) {
1075 }
1076
1077 auto available_themes = GetAvailableThemes();
1078 if (!available_themes.empty()) {
1079 ImGui::Separator();
1080 for (const auto& theme_name : available_themes) {
1081 if (ImGui::MenuItem(theme_name.c_str())) {
1082 LoadTheme(theme_name);
1083 }
1084 }
1085 }
1086 ImGui::EndMenu();
1087 }
1088
1089 ImGui::EndMenuBar();
1090 }
1091
1092 static EnhancedTheme edit_theme = current_theme_;
1093 static char theme_name[128];
1094 static char theme_description[256];
1095 static char theme_author[128];
1096 static bool live_preview = true;
1097 static EnhancedTheme original_theme; // Store original theme for restoration
1098 static bool theme_backup_made = false;
1099
1100 // Helper lambda for live preview application
1101 auto apply_live_preview = [&]() {
1102 if (live_preview) {
1103 if (!theme_backup_made) {
1104 original_theme = current_theme_;
1105 theme_backup_made = true;
1106 }
1107 // Apply the edit theme directly to ImGui without changing theme manager state
1108 edit_theme.ApplyToImGui();
1109 }
1110 };
1111
1112 // Live preview toggle
1113 ImGui::Checkbox("Live Preview", &live_preview);
1114 ImGui::SameLine();
1115 ImGui::Text("| Changes apply immediately when enabled");
1116
1117 // If live preview was just disabled, restore original theme
1118 static bool prev_live_preview = live_preview;
1119 if (prev_live_preview && !live_preview && theme_backup_made) {
1120 ApplyTheme(original_theme);
1121 theme_backup_made = false;
1122 }
1123 prev_live_preview = live_preview;
1124
1125 ImGui::Separator();
1126
1127 // Theme metadata in a table for better layout
1128 if (ImGui::BeginTable("ThemeMetadata", 2, ImGuiTableFlags_SizingStretchProp)) {
1129 ImGui::TableSetupColumn("Field", ImGuiTableColumnFlags_WidthFixed, 100.0f);
1130 ImGui::TableSetupColumn("Value", ImGuiTableColumnFlags_WidthStretch);
1131
1132 ImGui::TableNextRow();
1133 ImGui::TableNextColumn();
1134 ImGui::AlignTextToFramePadding();
1135 ImGui::Text("Name:");
1136 ImGui::TableNextColumn();
1137 if (ImGui::InputText("##theme_name", theme_name, sizeof(theme_name))) {
1138 edit_theme.name = std::string(theme_name);
1139 }
1140
1141 ImGui::TableNextRow();
1142 ImGui::TableNextColumn();
1143 ImGui::AlignTextToFramePadding();
1144 ImGui::Text("Description:");
1145 ImGui::TableNextColumn();
1146 if (ImGui::InputText("##theme_description", theme_description, sizeof(theme_description))) {
1147 edit_theme.description = std::string(theme_description);
1148 }
1149
1150 ImGui::TableNextRow();
1151 ImGui::TableNextColumn();
1152 ImGui::AlignTextToFramePadding();
1153 ImGui::Text("Author:");
1154 ImGui::TableNextColumn();
1155 if (ImGui::InputText("##theme_author", theme_author, sizeof(theme_author))) {
1156 edit_theme.author = std::string(theme_author);
1157 }
1158
1159 ImGui::EndTable();
1160 }
1161
1162 ImGui::Separator();
1163
1164 // Enhanced theme editing with tabs for better organization
1165 if (ImGui::BeginTabBar("ThemeEditorTabs", ImGuiTabBarFlags_None)) {
1166
1167 // Apply live preview on first frame if enabled
1168 static bool first_frame = true;
1169 if (first_frame && live_preview) {
1170 apply_live_preview();
1171 first_frame = false;
1172 }
1173
1174 // Primary Colors Tab
1175 if (ImGui::BeginTabItem(absl::StrFormat("%s Primary", ICON_MD_COLOR_LENS).c_str())) {
1176 if (ImGui::BeginTable("PrimaryColorsTable", 3, ImGuiTableFlags_SizingStretchProp)) {
1177 ImGui::TableSetupColumn("Color", ImGuiTableColumnFlags_WidthFixed, 120.0f);
1178 ImGui::TableSetupColumn("Picker", ImGuiTableColumnFlags_WidthStretch, 0.6f);
1179 ImGui::TableSetupColumn("Preview", ImGuiTableColumnFlags_WidthStretch, 0.4f);
1180 ImGui::TableHeadersRow();
1181
1182 // Primary color
1183 ImGui::TableNextRow();
1184 ImGui::TableNextColumn();
1185 ImGui::AlignTextToFramePadding();
1186 ImGui::Text("Primary:");
1187 ImGui::TableNextColumn();
1188 ImVec4 primary = ConvertColorToImVec4(edit_theme.primary);
1189 if (ImGui::ColorEdit3("##primary", &primary.x)) {
1190 edit_theme.primary = {primary.x, primary.y, primary.z, primary.w};
1191 apply_live_preview();
1192 }
1193 ImGui::TableNextColumn();
1194 ImGui::Button("Primary Preview", ImVec2(-1, 30));
1195
1196 // Secondary color
1197 ImGui::TableNextRow();
1198 ImGui::TableNextColumn();
1199 ImGui::AlignTextToFramePadding();
1200 ImGui::Text("Secondary:");
1201 ImGui::TableNextColumn();
1202 ImVec4 secondary = ConvertColorToImVec4(edit_theme.secondary);
1203 if (ImGui::ColorEdit3("##secondary", &secondary.x)) {
1204 edit_theme.secondary = {secondary.x, secondary.y, secondary.z, secondary.w};
1205 apply_live_preview();
1206 }
1207 ImGui::TableNextColumn();
1208 ImGui::PushStyleColor(ImGuiCol_Button, secondary);
1209 ImGui::Button("Secondary Preview", ImVec2(-1, 30));
1210 ImGui::PopStyleColor();
1211
1212 // Accent color
1213 ImGui::TableNextRow();
1214 ImGui::TableNextColumn();
1215 ImGui::AlignTextToFramePadding();
1216 ImGui::Text("Accent:");
1217 ImGui::TableNextColumn();
1218 ImVec4 accent = ConvertColorToImVec4(edit_theme.accent);
1219 if (ImGui::ColorEdit3("##accent", &accent.x)) {
1220 edit_theme.accent = {accent.x, accent.y, accent.z, accent.w};
1221 apply_live_preview();
1222 }
1223 ImGui::TableNextColumn();
1224 ImGui::PushStyleColor(ImGuiCol_Button, accent);
1225 ImGui::Button("Accent Preview", ImVec2(-1, 30));
1226 ImGui::PopStyleColor();
1227
1228 // Background color
1229 ImGui::TableNextRow();
1230 ImGui::TableNextColumn();
1231 ImGui::AlignTextToFramePadding();
1232 ImGui::Text("Background:");
1233 ImGui::TableNextColumn();
1234 ImVec4 background = ConvertColorToImVec4(edit_theme.background);
1235 if (ImGui::ColorEdit4("##background", &background.x)) {
1236 edit_theme.background = {background.x, background.y, background.z, background.w};
1237 apply_live_preview();
1238 }
1239 ImGui::TableNextColumn();
1240 ImGui::Text("Background preview shown in window");
1241
1242 ImGui::EndTable();
1243 }
1244 ImGui::EndTabItem();
1245 }
1246
1247 // Text Colors Tab
1248 if (ImGui::BeginTabItem(absl::StrFormat("%s Text", ICON_MD_TEXT_FIELDS).c_str())) {
1249 if (ImGui::BeginTable("TextColorsTable", 3, ImGuiTableFlags_SizingStretchProp)) {
1250 ImGui::TableSetupColumn("Color", ImGuiTableColumnFlags_WidthFixed, 120.0f);
1251 ImGui::TableSetupColumn("Picker", ImGuiTableColumnFlags_WidthStretch, 0.6f);
1252 ImGui::TableSetupColumn("Preview", ImGuiTableColumnFlags_WidthStretch, 0.4f);
1253 ImGui::TableHeadersRow();
1254
1255 // Text colors with live preview
1256 auto text_colors = std::vector<std::pair<const char*, Color*>>{
1257 {"Primary Text", &edit_theme.text_primary},
1258 {"Secondary Text", &edit_theme.text_secondary},
1259 {"Disabled Text", &edit_theme.text_disabled},
1260 {"Link Text", &edit_theme.text_link},
1261 {"Text Highlight", &edit_theme.text_highlight},
1262 {"Link Hover", &edit_theme.link_hover},
1263 {"Text Selected BG", &edit_theme.text_selected_bg},
1264 {"Input Text Cursor", &edit_theme.input_text_cursor}
1265 };
1266
1267 for (auto& [label, color_ptr] : text_colors) {
1268 ImGui::TableNextRow();
1269 ImGui::TableNextColumn();
1270 ImGui::AlignTextToFramePadding();
1271 ImGui::Text("%s:", label);
1272
1273 ImGui::TableNextColumn();
1274 ImVec4 color_vec = ConvertColorToImVec4(*color_ptr);
1275 std::string id = absl::StrFormat("##%s", label);
1276 if (ImGui::ColorEdit3(id.c_str(), &color_vec.x)) {
1277 *color_ptr = {color_vec.x, color_vec.y, color_vec.z, color_vec.w};
1278 apply_live_preview();
1279 }
1280
1281 ImGui::TableNextColumn();
1282 ImGui::PushStyleColor(ImGuiCol_Text, color_vec);
1283 ImGui::Text("Sample %s", label);
1284 ImGui::PopStyleColor();
1285 }
1286
1287 ImGui::EndTable();
1288 }
1289 ImGui::EndTabItem();
1290 }
1291
1292 // Interactive Elements Tab
1293 if (ImGui::BeginTabItem(absl::StrFormat("%s Interactive", ICON_MD_TOUCH_APP).c_str())) {
1294 if (ImGui::BeginTable("InteractiveColorsTable", 3, ImGuiTableFlags_SizingStretchProp)) {
1295 ImGui::TableSetupColumn("Element", ImGuiTableColumnFlags_WidthFixed, 120.0f);
1296 ImGui::TableSetupColumn("Picker", ImGuiTableColumnFlags_WidthStretch, 0.6f);
1297 ImGui::TableSetupColumn("Preview", ImGuiTableColumnFlags_WidthStretch, 0.4f);
1298 ImGui::TableHeadersRow();
1299
1300 // Interactive element colors
1301 auto interactive_colors = std::vector<std::tuple<const char*, Color*, ImGuiCol>>{
1302 {"Button", &edit_theme.button, ImGuiCol_Button},
1303 {"Button Hovered", &edit_theme.button_hovered, ImGuiCol_ButtonHovered},
1304 {"Button Active", &edit_theme.button_active, ImGuiCol_ButtonActive},
1305 {"Frame Background", &edit_theme.frame_bg, ImGuiCol_FrameBg},
1306 {"Frame BG Hovered", &edit_theme.frame_bg_hovered, ImGuiCol_FrameBgHovered},
1307 {"Frame BG Active", &edit_theme.frame_bg_active, ImGuiCol_FrameBgActive},
1308 {"Check Mark", &edit_theme.check_mark, ImGuiCol_CheckMark},
1309 {"Slider Grab", &edit_theme.slider_grab, ImGuiCol_SliderGrab},
1310 {"Slider Grab Active", &edit_theme.slider_grab_active, ImGuiCol_SliderGrabActive}
1311 };
1312
1313 for (auto& [label, color_ptr, imgui_col] : interactive_colors) {
1314 ImGui::TableNextRow();
1315 ImGui::TableNextColumn();
1316 ImGui::AlignTextToFramePadding();
1317 ImGui::Text("%s:", label);
1318
1319 ImGui::TableNextColumn();
1320 ImVec4 color_vec = ConvertColorToImVec4(*color_ptr);
1321 std::string id = absl::StrFormat("##%s", label);
1322 if (ImGui::ColorEdit3(id.c_str(), &color_vec.x)) {
1323 *color_ptr = {color_vec.x, color_vec.y, color_vec.z, color_vec.w};
1324 apply_live_preview();
1325 }
1326
1327 ImGui::TableNextColumn();
1328 ImGui::PushStyleColor(imgui_col, color_vec);
1329 ImGui::Button(absl::StrFormat("Preview %s", label).c_str(), ImVec2(-1, 30));
1330 ImGui::PopStyleColor();
1331 }
1332
1333 ImGui::EndTable();
1334 }
1335 ImGui::EndTabItem();
1336 }
1337
1338 // Style Parameters Tab
1339 if (ImGui::BeginTabItem(absl::StrFormat("%s Style", ICON_MD_TUNE).c_str())) {
1340 ImGui::Text("Rounding and Border Settings:");
1341
1342 if (ImGui::SliderFloat("Window Rounding", &edit_theme.window_rounding, 0.0f, 20.0f)) {
1343 if (live_preview) ApplyTheme(edit_theme);
1344 }
1345 if (ImGui::SliderFloat("Frame Rounding", &edit_theme.frame_rounding, 0.0f, 20.0f)) {
1346 if (live_preview) ApplyTheme(edit_theme);
1347 }
1348 if (ImGui::SliderFloat("Scrollbar Rounding", &edit_theme.scrollbar_rounding, 0.0f, 20.0f)) {
1349 if (live_preview) ApplyTheme(edit_theme);
1350 }
1351 if (ImGui::SliderFloat("Tab Rounding", &edit_theme.tab_rounding, 0.0f, 20.0f)) {
1352 if (live_preview) ApplyTheme(edit_theme);
1353 }
1354 if (ImGui::SliderFloat("Grab Rounding", &edit_theme.grab_rounding, 0.0f, 20.0f)) {
1355 if (live_preview) ApplyTheme(edit_theme);
1356 }
1357
1358 ImGui::Separator();
1359 ImGui::Text("Border Sizes:");
1360
1361 if (ImGui::SliderFloat("Window Border Size", &edit_theme.window_border_size, 0.0f, 3.0f)) {
1362 if (live_preview) ApplyTheme(edit_theme);
1363 }
1364 if (ImGui::SliderFloat("Frame Border Size", &edit_theme.frame_border_size, 0.0f, 3.0f)) {
1365 if (live_preview) ApplyTheme(edit_theme);
1366 }
1367
1368 ImGui::Separator();
1369 ImGui::Text("Animation & Effects:");
1370
1371 if (ImGui::Checkbox("Enable Animations", &edit_theme.enable_animations)) {
1372 if (live_preview) ApplyTheme(edit_theme);
1373 }
1374 if (edit_theme.enable_animations) {
1375 if (ImGui::SliderFloat("Animation Speed", &edit_theme.animation_speed, 0.1f, 3.0f)) {
1376 apply_live_preview();
1377 }
1378 }
1379 if (ImGui::Checkbox("Enable Glow Effects", &edit_theme.enable_glow_effects)) {
1380 if (live_preview) ApplyTheme(edit_theme);
1381 }
1382
1383 ImGui::EndTabItem();
1384 }
1385
1386 // Navigation & Windows Tab
1387 if (ImGui::BeginTabItem(absl::StrFormat("%s Navigation", ICON_MD_NAVIGATION).c_str())) {
1388 if (ImGui::BeginTable("NavigationTable", 3, ImGuiTableFlags_SizingStretchProp)) {
1389 ImGui::TableSetupColumn("Element", ImGuiTableColumnFlags_WidthFixed, 120.0f);
1390 ImGui::TableSetupColumn("Picker", ImGuiTableColumnFlags_WidthStretch, 0.6f);
1391 ImGui::TableSetupColumn("Preview", ImGuiTableColumnFlags_WidthStretch, 0.4f);
1392 ImGui::TableHeadersRow();
1393
1394 // Window colors
1395 auto window_colors = std::vector<std::tuple<const char*, Color*, const char*>>{
1396 {"Window Background", &edit_theme.window_bg, "Main window background"},
1397 {"Child Background", &edit_theme.child_bg, "Child window background"},
1398 {"Popup Background", &edit_theme.popup_bg, "Popup window background"},
1399 {"Modal Background", &edit_theme.modal_bg, "Modal window background"},
1400 {"Menu Bar BG", &edit_theme.menu_bar_bg, "Menu bar background"}
1401 };
1402
1403 for (auto& [label, color_ptr, description] : window_colors) {
1404 ImGui::TableNextRow();
1405 ImGui::TableNextColumn();
1406 ImGui::AlignTextToFramePadding();
1407 ImGui::Text("%s:", label);
1408
1409 ImGui::TableNextColumn();
1410 ImVec4 color_vec = ConvertColorToImVec4(*color_ptr);
1411 std::string id = absl::StrFormat("##window_%s", label);
1412 if (ImGui::ColorEdit4(id.c_str(), &color_vec.x)) {
1413 *color_ptr = {color_vec.x, color_vec.y, color_vec.z, color_vec.w};
1414 apply_live_preview();
1415 }
1416
1417 ImGui::TableNextColumn();
1418 ImGui::TextWrapped("%s", description);
1419 }
1420
1421 ImGui::EndTable();
1422 }
1423
1424 ImGui::Separator();
1425
1426 // Header and Tab colors
1427 if (ImGui::CollapsingHeader("Headers & Tabs", ImGuiTreeNodeFlags_DefaultOpen)) {
1428 if (ImGui::BeginTable("HeaderTabTable", 3, ImGuiTableFlags_SizingStretchProp)) {
1429 ImGui::TableSetupColumn("Element", ImGuiTableColumnFlags_WidthFixed, 120.0f);
1430 ImGui::TableSetupColumn("Picker", ImGuiTableColumnFlags_WidthStretch, 0.6f);
1431 ImGui::TableSetupColumn("Preview", ImGuiTableColumnFlags_WidthStretch, 0.4f);
1432 ImGui::TableHeadersRow();
1433
1434 auto header_tab_colors = std::vector<std::pair<const char*, Color*>>{
1435 {"Header", &edit_theme.header},
1436 {"Header Hovered", &edit_theme.header_hovered},
1437 {"Header Active", &edit_theme.header_active},
1438 {"Tab", &edit_theme.tab},
1439 {"Tab Hovered", &edit_theme.tab_hovered},
1440 {"Tab Active", &edit_theme.tab_active},
1441 {"Tab Unfocused", &edit_theme.tab_unfocused},
1442 {"Tab Unfocused Active", &edit_theme.tab_unfocused_active},
1443 {"Tab Dimmed", &edit_theme.tab_dimmed},
1444 {"Tab Dimmed Selected", &edit_theme.tab_dimmed_selected},
1445 {"Title Background", &edit_theme.title_bg},
1446 {"Title BG Active", &edit_theme.title_bg_active},
1447 {"Title BG Collapsed", &edit_theme.title_bg_collapsed}
1448 };
1449
1450 for (auto& [label, color_ptr] : header_tab_colors) {
1451 ImGui::TableNextRow();
1452 ImGui::TableNextColumn();
1453 ImGui::AlignTextToFramePadding();
1454 ImGui::Text("%s:", label);
1455
1456 ImGui::TableNextColumn();
1457 ImVec4 color_vec = ConvertColorToImVec4(*color_ptr);
1458 std::string id = absl::StrFormat("##header_%s", label);
1459 if (ImGui::ColorEdit3(id.c_str(), &color_vec.x)) {
1460 *color_ptr = {color_vec.x, color_vec.y, color_vec.z, color_vec.w};
1461 apply_live_preview();
1462 }
1463
1464 ImGui::TableNextColumn();
1465 ImGui::PushStyleColor(ImGuiCol_Button, color_vec);
1466 ImGui::Button(absl::StrFormat("Preview %s", label).c_str(), ImVec2(-1, 25));
1467 ImGui::PopStyleColor();
1468 }
1469
1470 ImGui::EndTable();
1471 }
1472 }
1473
1474 // Navigation and Special Elements
1475 if (ImGui::CollapsingHeader("Navigation & Special")) {
1476 if (ImGui::BeginTable("NavSpecialTable", 3, ImGuiTableFlags_SizingStretchProp)) {
1477 ImGui::TableSetupColumn("Element", ImGuiTableColumnFlags_WidthFixed, 120.0f);
1478 ImGui::TableSetupColumn("Picker", ImGuiTableColumnFlags_WidthStretch, 0.6f);
1479 ImGui::TableSetupColumn("Description", ImGuiTableColumnFlags_WidthStretch, 0.4f);
1480 ImGui::TableHeadersRow();
1481
1482 auto nav_special_colors = std::vector<std::tuple<const char*, Color*, const char*>>{
1483 {"Nav Cursor", &edit_theme.nav_cursor, "Navigation cursor color"},
1484 {"Nav Win Highlight", &edit_theme.nav_windowing_highlight, "Window selection highlight"},
1485 {"Nav Win Dim BG", &edit_theme.nav_windowing_dim_bg, "Background dimming for navigation"},
1486 {"Modal Win Dim BG", &edit_theme.modal_window_dim_bg, "Background dimming for modals"},
1487 {"Drag Drop Target", &edit_theme.drag_drop_target, "Drag and drop target highlight"},
1488 {"Docking Preview", &edit_theme.docking_preview, "Docking area preview"},
1489 {"Docking Empty BG", &edit_theme.docking_empty_bg, "Empty docking space background"}
1490 };
1491
1492 for (auto& [label, color_ptr, description] : nav_special_colors) {
1493 ImGui::TableNextRow();
1494 ImGui::TableNextColumn();
1495 ImGui::AlignTextToFramePadding();
1496 ImGui::Text("%s:", label);
1497
1498 ImGui::TableNextColumn();
1499 ImVec4 color_vec = ConvertColorToImVec4(*color_ptr);
1500 std::string id = absl::StrFormat("##nav_%s", label);
1501 if (ImGui::ColorEdit4(id.c_str(), &color_vec.x)) {
1502 *color_ptr = {color_vec.x, color_vec.y, color_vec.z, color_vec.w};
1503 apply_live_preview();
1504 }
1505
1506 ImGui::TableNextColumn();
1507 ImGui::TextWrapped("%s", description);
1508 }
1509
1510 ImGui::EndTable();
1511 }
1512 }
1513
1514 ImGui::EndTabItem();
1515 }
1516
1517 // Tables & Data Tab
1518 if (ImGui::BeginTabItem(absl::StrFormat("%s Tables", ICON_MD_TABLE_CHART).c_str())) {
1519 if (ImGui::BeginTable("TablesDataTable", 3, ImGuiTableFlags_SizingStretchProp)) {
1520 ImGui::TableSetupColumn("Element", ImGuiTableColumnFlags_WidthFixed, 120.0f);
1521 ImGui::TableSetupColumn("Picker", ImGuiTableColumnFlags_WidthStretch, 0.6f);
1522 ImGui::TableSetupColumn("Description", ImGuiTableColumnFlags_WidthStretch, 0.4f);
1523 ImGui::TableHeadersRow();
1524
1525 auto table_colors = std::vector<std::tuple<const char*, Color*, const char*>>{
1526 {"Table Header BG", &edit_theme.table_header_bg, "Table column headers"},
1527 {"Table Border Strong", &edit_theme.table_border_strong, "Outer table borders"},
1528 {"Table Border Light", &edit_theme.table_border_light, "Inner table borders"},
1529 {"Table Row BG", &edit_theme.table_row_bg, "Normal table rows"},
1530 {"Table Row BG Alt", &edit_theme.table_row_bg_alt, "Alternating table rows"},
1531 {"Tree Lines", &edit_theme.tree_lines, "Tree view connection lines"}
1532 };
1533
1534 for (auto& [label, color_ptr, description] : table_colors) {
1535 ImGui::TableNextRow();
1536 ImGui::TableNextColumn();
1537 ImGui::AlignTextToFramePadding();
1538 ImGui::Text("%s:", label);
1539
1540 ImGui::TableNextColumn();
1541 ImVec4 color_vec = ConvertColorToImVec4(*color_ptr);
1542 std::string id = absl::StrFormat("##table_%s", label);
1543 if (ImGui::ColorEdit4(id.c_str(), &color_vec.x)) {
1544 *color_ptr = {color_vec.x, color_vec.y, color_vec.z, color_vec.w};
1545 apply_live_preview();
1546 }
1547
1548 ImGui::TableNextColumn();
1549 ImGui::TextWrapped("%s", description);
1550 }
1551
1552 ImGui::EndTable();
1553 }
1554
1555 ImGui::Separator();
1556
1557 // Plots and Graphs
1558 if (ImGui::CollapsingHeader("Plots & Graphs")) {
1559 if (ImGui::BeginTable("PlotsTable", 3, ImGuiTableFlags_SizingStretchProp)) {
1560 ImGui::TableSetupColumn("Element", ImGuiTableColumnFlags_WidthFixed, 120.0f);
1561 ImGui::TableSetupColumn("Picker", ImGuiTableColumnFlags_WidthStretch, 0.6f);
1562 ImGui::TableSetupColumn("Description", ImGuiTableColumnFlags_WidthStretch, 0.4f);
1563 ImGui::TableHeadersRow();
1564
1565 auto plot_colors = std::vector<std::tuple<const char*, Color*, const char*>>{
1566 {"Plot Lines", &edit_theme.plot_lines, "Line plot color"},
1567 {"Plot Lines Hovered", &edit_theme.plot_lines_hovered, "Line plot hover color"},
1568 {"Plot Histogram", &edit_theme.plot_histogram, "Histogram fill color"},
1569 {"Plot Histogram Hovered", &edit_theme.plot_histogram_hovered, "Histogram hover color"}
1570 };
1571
1572 for (auto& [label, color_ptr, description] : plot_colors) {
1573 ImGui::TableNextRow();
1574 ImGui::TableNextColumn();
1575 ImGui::AlignTextToFramePadding();
1576 ImGui::Text("%s:", label);
1577
1578 ImGui::TableNextColumn();
1579 ImVec4 color_vec = ConvertColorToImVec4(*color_ptr);
1580 std::string id = absl::StrFormat("##plot_%s", label);
1581 if (ImGui::ColorEdit3(id.c_str(), &color_vec.x)) {
1582 *color_ptr = {color_vec.x, color_vec.y, color_vec.z, color_vec.w};
1583 apply_live_preview();
1584 }
1585
1586 ImGui::TableNextColumn();
1587 ImGui::TextWrapped("%s", description);
1588 }
1589
1590 ImGui::EndTable();
1591 }
1592 }
1593
1594 ImGui::EndTabItem();
1595 }
1596
1597 // Borders & Controls Tab
1598 if (ImGui::BeginTabItem(absl::StrFormat("%s Borders", ICON_MD_BORDER_ALL).c_str())) {
1599 if (ImGui::BeginTable("BordersControlsTable", 3, ImGuiTableFlags_SizingStretchProp)) {
1600 ImGui::TableSetupColumn("Element", ImGuiTableColumnFlags_WidthFixed, 120.0f);
1601 ImGui::TableSetupColumn("Picker", ImGuiTableColumnFlags_WidthStretch, 0.6f);
1602 ImGui::TableSetupColumn("Description", ImGuiTableColumnFlags_WidthStretch, 0.4f);
1603 ImGui::TableHeadersRow();
1604
1605 auto border_control_colors = std::vector<std::tuple<const char*, Color*, const char*>>{
1606 {"Border", &edit_theme.border, "General border color"},
1607 {"Border Shadow", &edit_theme.border_shadow, "Border shadow/depth"},
1608 {"Separator", &edit_theme.separator, "Horizontal/vertical separators"},
1609 {"Separator Hovered", &edit_theme.separator_hovered, "Separator hover state"},
1610 {"Separator Active", &edit_theme.separator_active, "Separator active/dragged state"},
1611 {"Scrollbar BG", &edit_theme.scrollbar_bg, "Scrollbar track background"},
1612 {"Scrollbar Grab", &edit_theme.scrollbar_grab, "Scrollbar handle"},
1613 {"Scrollbar Grab Hovered", &edit_theme.scrollbar_grab_hovered, "Scrollbar handle hover"},
1614 {"Scrollbar Grab Active", &edit_theme.scrollbar_grab_active, "Scrollbar handle active"},
1615 {"Resize Grip", &edit_theme.resize_grip, "Window resize grip"},
1616 {"Resize Grip Hovered", &edit_theme.resize_grip_hovered, "Resize grip hover"},
1617 {"Resize Grip Active", &edit_theme.resize_grip_active, "Resize grip active"}
1618 };
1619
1620 for (auto& [label, color_ptr, description] : border_control_colors) {
1621 ImGui::TableNextRow();
1622 ImGui::TableNextColumn();
1623 ImGui::AlignTextToFramePadding();
1624 ImGui::Text("%s:", label);
1625
1626 ImGui::TableNextColumn();
1627 ImVec4 color_vec = ConvertColorToImVec4(*color_ptr);
1628 std::string id = absl::StrFormat("##border_%s", label);
1629 if (ImGui::ColorEdit4(id.c_str(), &color_vec.x)) {
1630 *color_ptr = {color_vec.x, color_vec.y, color_vec.z, color_vec.w};
1631 apply_live_preview();
1632 }
1633
1634 ImGui::TableNextColumn();
1635 ImGui::TextWrapped("%s", description);
1636 }
1637
1638 ImGui::EndTable();
1639 }
1640
1641 ImGui::EndTabItem();
1642 }
1643
1644 // Enhanced Colors Tab
1645 if (ImGui::BeginTabItem(absl::StrFormat("%s Enhanced", ICON_MD_AUTO_AWESOME).c_str())) {
1646 ImGui::Text("Enhanced semantic colors and editor-specific customization");
1647 ImGui::Separator();
1648
1649 // Enhanced semantic colors section
1650 if (ImGui::CollapsingHeader("Enhanced Semantic Colors", ImGuiTreeNodeFlags_DefaultOpen)) {
1651 if (ImGui::BeginTable("EnhancedSemanticTable", 3, ImGuiTableFlags_SizingStretchProp)) {
1652 ImGui::TableSetupColumn("Color", ImGuiTableColumnFlags_WidthFixed, 120.0f);
1653 ImGui::TableSetupColumn("Picker", ImGuiTableColumnFlags_WidthStretch, 0.6f);
1654 ImGui::TableSetupColumn("Description", ImGuiTableColumnFlags_WidthStretch, 0.4f);
1655 ImGui::TableHeadersRow();
1656
1657 auto enhanced_colors = std::vector<std::tuple<const char*, Color*, const char*>>{
1658 {"Code Background", &edit_theme.code_background, "Code blocks background"},
1659 {"Success Light", &edit_theme.success_light, "Light success variant"},
1660 {"Warning Light", &edit_theme.warning_light, "Light warning variant"},
1661 {"Error Light", &edit_theme.error_light, "Light error variant"},
1662 {"Info Light", &edit_theme.info_light, "Light info variant"}
1663 };
1664
1665 for (auto& [label, color_ptr, description] : enhanced_colors) {
1666 ImGui::TableNextRow();
1667 ImGui::TableNextColumn();
1668 ImGui::AlignTextToFramePadding();
1669 ImGui::Text("%s:", label);
1670
1671 ImGui::TableNextColumn();
1672 ImVec4 color_vec = ConvertColorToImVec4(*color_ptr);
1673 std::string id = absl::StrFormat("##enhanced_%s", label);
1674 if (ImGui::ColorEdit3(id.c_str(), &color_vec.x)) {
1675 *color_ptr = {color_vec.x, color_vec.y, color_vec.z, color_vec.w};
1676 apply_live_preview();
1677 }
1678
1679 ImGui::TableNextColumn();
1680 ImGui::TextWrapped("%s", description);
1681 }
1682
1683 ImGui::EndTable();
1684 }
1685 }
1686
1687 // UI State colors section
1688 if (ImGui::CollapsingHeader("UI State Colors")) {
1689 if (ImGui::BeginTable("UIStateTable", 3, ImGuiTableFlags_SizingStretchProp)) {
1690 ImGui::TableSetupColumn("Color", ImGuiTableColumnFlags_WidthFixed, 120.0f);
1691 ImGui::TableSetupColumn("Picker", ImGuiTableColumnFlags_WidthStretch, 0.6f);
1692 ImGui::TableSetupColumn("Description", ImGuiTableColumnFlags_WidthStretch, 0.4f);
1693 ImGui::TableHeadersRow();
1694
1695 // UI state colors with alpha support where needed
1696 ImGui::TableNextRow();
1697 ImGui::TableNextColumn();
1698 ImGui::AlignTextToFramePadding();
1699 ImGui::Text("Active Selection:");
1700 ImGui::TableNextColumn();
1701 ImVec4 active_selection = ConvertColorToImVec4(edit_theme.active_selection);
1702 if (ImGui::ColorEdit4("##active_selection", &active_selection.x)) {
1703 edit_theme.active_selection = {active_selection.x, active_selection.y, active_selection.z, active_selection.w};
1704 apply_live_preview();
1705 }
1706 ImGui::TableNextColumn();
1707 ImGui::TextWrapped("Active/selected UI elements");
1708
1709 ImGui::TableNextRow();
1710 ImGui::TableNextColumn();
1711 ImGui::AlignTextToFramePadding();
1712 ImGui::Text("Hover Highlight:");
1713 ImGui::TableNextColumn();
1714 ImVec4 hover_highlight = ConvertColorToImVec4(edit_theme.hover_highlight);
1715 if (ImGui::ColorEdit4("##hover_highlight", &hover_highlight.x)) {
1716 edit_theme.hover_highlight = {hover_highlight.x, hover_highlight.y, hover_highlight.z, hover_highlight.w};
1717 apply_live_preview();
1718 }
1719 ImGui::TableNextColumn();
1720 ImGui::TextWrapped("General hover state highlighting");
1721
1722 ImGui::TableNextRow();
1723 ImGui::TableNextColumn();
1724 ImGui::AlignTextToFramePadding();
1725 ImGui::Text("Focus Border:");
1726 ImGui::TableNextColumn();
1727 ImVec4 focus_border = ConvertColorToImVec4(edit_theme.focus_border);
1728 if (ImGui::ColorEdit3("##focus_border", &focus_border.x)) {
1729 edit_theme.focus_border = {focus_border.x, focus_border.y, focus_border.z, focus_border.w};
1730 apply_live_preview();
1731 }
1732 ImGui::TableNextColumn();
1733 ImGui::TextWrapped("Border for focused input elements");
1734
1735 ImGui::TableNextRow();
1736 ImGui::TableNextColumn();
1737 ImGui::AlignTextToFramePadding();
1738 ImGui::Text("Disabled Overlay:");
1739 ImGui::TableNextColumn();
1740 ImVec4 disabled_overlay = ConvertColorToImVec4(edit_theme.disabled_overlay);
1741 if (ImGui::ColorEdit4("##disabled_overlay", &disabled_overlay.x)) {
1742 edit_theme.disabled_overlay = {disabled_overlay.x, disabled_overlay.y, disabled_overlay.z, disabled_overlay.w};
1743 apply_live_preview();
1744 }
1745 ImGui::TableNextColumn();
1746 ImGui::TextWrapped("Semi-transparent overlay for disabled elements");
1747
1748 ImGui::EndTable();
1749 }
1750 }
1751
1752 // Editor-specific colors section
1753 if (ImGui::CollapsingHeader("Editor-Specific Colors")) {
1754 if (ImGui::BeginTable("EditorColorsTable", 3, ImGuiTableFlags_SizingStretchProp)) {
1755 ImGui::TableSetupColumn("Color", ImGuiTableColumnFlags_WidthFixed, 120.0f);
1756 ImGui::TableSetupColumn("Picker", ImGuiTableColumnFlags_WidthStretch, 0.6f);
1757 ImGui::TableSetupColumn("Description", ImGuiTableColumnFlags_WidthStretch, 0.4f);
1758 ImGui::TableHeadersRow();
1759
1760 auto editor_colors = std::vector<std::tuple<const char*, Color*, const char*, bool>>{
1761 {"Editor Background", &edit_theme.editor_background, "Main editor canvas background", false},
1762 {"Editor Grid", &edit_theme.editor_grid, "Grid lines in map/graphics editors", true},
1763 {"Editor Cursor", &edit_theme.editor_cursor, "Cursor color in editors", false},
1764 {"Editor Selection", &edit_theme.editor_selection, "Selection highlight in editors", true}
1765 };
1766
1767 for (auto& [label, color_ptr, description, use_alpha] : editor_colors) {
1768 ImGui::TableNextRow();
1769 ImGui::TableNextColumn();
1770 ImGui::AlignTextToFramePadding();
1771 ImGui::Text("%s:", label);
1772
1773 ImGui::TableNextColumn();
1774 ImVec4 color_vec = ConvertColorToImVec4(*color_ptr);
1775 std::string id = absl::StrFormat("##editor_%s", label);
1776 if (use_alpha ? ImGui::ColorEdit4(id.c_str(), &color_vec.x) : ImGui::ColorEdit3(id.c_str(), &color_vec.x)) {
1777 *color_ptr = {color_vec.x, color_vec.y, color_vec.z, color_vec.w};
1778 apply_live_preview();
1779 }
1780
1781 ImGui::TableNextColumn();
1782 ImGui::TextWrapped("%s", description);
1783 }
1784
1785 ImGui::EndTable();
1786 }
1787 }
1788
1789 ImGui::EndTabItem();
1790 }
1791
1792 ImGui::EndTabBar();
1793 }
1794
1795 ImGui::Separator();
1796
1797 if (ImGui::Button("Preview Theme")) {
1798 ApplyTheme(edit_theme);
1799 }
1800
1801 ImGui::SameLine();
1802 if (ImGui::Button("Reset to Current")) {
1803 edit_theme = current_theme_;
1804 // Safe string copy with bounds checking
1805 size_t name_len = std::min(current_theme_.name.length(), sizeof(theme_name) - 1);
1806 std::memcpy(theme_name, current_theme_.name.c_str(), name_len);
1807 theme_name[name_len] = '\0';
1808
1809 size_t desc_len = std::min(current_theme_.description.length(), sizeof(theme_description) - 1);
1810 std::memcpy(theme_description, current_theme_.description.c_str(), desc_len);
1811 theme_description[desc_len] = '\0';
1812
1813 size_t author_len = std::min(current_theme_.author.length(), sizeof(theme_author) - 1);
1814 std::memcpy(theme_author, current_theme_.author.c_str(), author_len);
1815 theme_author[author_len] = '\0';
1816
1817 // Reset backup state since we're back to current theme
1818 if (theme_backup_made) {
1819 theme_backup_made = false;
1820 current_theme_.ApplyToImGui(); // Apply current theme to clear any preview changes
1821 }
1822 }
1823
1824 ImGui::SameLine();
1825 if (ImGui::Button("Save Theme")) {
1826 edit_theme.name = std::string(theme_name);
1827 edit_theme.description = std::string(theme_description);
1828 edit_theme.author = std::string(theme_author);
1829
1830 // Add to themes map and apply
1831 themes_[edit_theme.name] = edit_theme;
1832 ApplyTheme(edit_theme);
1833
1834 // Reset backup state since theme is now applied
1835 theme_backup_made = false;
1836 }
1837
1838 ImGui::SameLine();
1839
1840 // Save Over Current button - overwrites the current theme file
1841 std::string current_file_path = GetCurrentThemeFilePath();
1842 bool can_save_over = !current_file_path.empty();
1843
1844 if (!can_save_over) {
1845 ImGui::BeginDisabled();
1846 }
1847
1848 if (ImGui::Button("Save Over Current")) {
1849 edit_theme.name = std::string(theme_name);
1850 edit_theme.description = std::string(theme_description);
1851 edit_theme.author = std::string(theme_author);
1852
1853 auto status = SaveThemeToFile(edit_theme, current_file_path);
1854 if (status.ok()) {
1855 // Update themes map and apply
1856 themes_[edit_theme.name] = edit_theme;
1857 ApplyTheme(edit_theme);
1858 theme_backup_made = false; // Reset backup state since theme is now applied
1859 } else {
1860 LOG_ERROR("Theme Manager", "Failed to save over current theme");
1861 }
1862 }
1863
1864 if (!can_save_over) {
1865 ImGui::EndDisabled();
1866 }
1867
1868 if (ImGui::IsItemHovered() && can_save_over) {
1869 ImGui::BeginTooltip();
1870 ImGui::Text("Save over current theme file:");
1871 ImGui::Text("%s", current_file_path.c_str());
1872 ImGui::EndTooltip();
1873 } else if (ImGui::IsItemHovered()) {
1874 ImGui::BeginTooltip();
1875 ImGui::Text("No current theme file to overwrite");
1876 ImGui::Text("Use 'Save to File...' to create a new theme file");
1877 ImGui::EndTooltip();
1878 }
1879
1880 ImGui::SameLine();
1881 if (ImGui::Button("Save to File...")) {
1882 edit_theme.name = std::string(theme_name);
1883 edit_theme.description = std::string(theme_description);
1884 edit_theme.author = std::string(theme_author);
1885
1886 // Use save file dialog with proper defaults
1887 std::string safe_name = edit_theme.name.empty() ? "custom_theme" : edit_theme.name;
1888 auto file_path = util::FileDialogWrapper::ShowSaveFileDialog(safe_name, "theme");
1889
1890 if (!file_path.empty()) {
1891 // Ensure .theme extension
1892 if (file_path.find(".theme") == std::string::npos) {
1893 file_path += ".theme";
1894 }
1895
1896 auto status = SaveThemeToFile(edit_theme, file_path);
1897 if (status.ok()) {
1898 // Also add to themes map for immediate use
1899 themes_[edit_theme.name] = edit_theme;
1900 ApplyTheme(edit_theme);
1901 } else {
1902 LOG_ERROR("Theme Manager", "Failed to save theme");
1903 }
1904 }
1905 }
1906
1907 if (ImGui::IsItemHovered()) {
1908 ImGui::BeginTooltip();
1909 ImGui::Text("Save theme to a .theme file");
1910 ImGui::Text("Saved themes can be shared and loaded later");
1911 ImGui::EndTooltip();
1912 }
1913 }
1914 ImGui::End();
1915}
1916
1917std::vector<std::string> ThemeManager::GetThemeSearchPaths() const {
1918 std::vector<std::string> search_paths;
1919
1920 // Development path (relative to build directory)
1921 search_paths.push_back("assets/themes/");
1922 search_paths.push_back("../assets/themes/");
1923
1924 // Platform-specific resource paths
1925#ifdef __APPLE__
1926 // macOS bundle resource path (this should be the primary path for bundled apps)
1927 std::string bundle_themes = util::GetResourcePath("assets/themes/");
1928 if (!bundle_themes.empty()) {
1929 search_paths.push_back(bundle_themes);
1930 }
1931
1932 // Alternative bundle locations
1933 std::string bundle_root = util::GetBundleResourcePath();
1934
1935 search_paths.push_back(bundle_root + "Contents/Resources/themes/");
1936 search_paths.push_back(bundle_root + "Contents/Resources/assets/themes/");
1937 search_paths.push_back(bundle_root + "assets/themes/");
1938 search_paths.push_back(bundle_root + "themes/");
1939#else
1940 // Linux/Windows relative paths
1941 search_paths.push_back("./assets/themes/");
1942 search_paths.push_back("./themes/");
1943#endif
1944
1945 // User config directory
1946 auto config_dir = util::PlatformPaths::GetConfigDirectory();
1947 if (config_dir.ok()) {
1948 search_paths.push_back((*config_dir / "themes/").string());
1949 }
1950
1951 return search_paths;
1952}
1953
1955 auto search_paths = GetThemeSearchPaths();
1956
1957 // Try each search path and return the first one that exists
1958 for (const auto& path : search_paths) {
1959 std::ifstream test_file(path + "."); // Test if directory exists by trying to access it
1960 if (test_file.good()) {
1961 return path;
1962 }
1963
1964 // Also try with platform-specific directory separators
1965 std::string normalized_path = path;
1966 if (!normalized_path.empty() && normalized_path.back() != '/' && normalized_path.back() != '\\') {
1967 normalized_path += "/";
1968 }
1969
1970 std::ifstream test_file2(normalized_path + ".");
1971 if (test_file2.good()) {
1972 return normalized_path;
1973 }
1974 }
1975
1976 return search_paths.empty() ? "assets/themes/" : search_paths[0];
1977}
1978
1979std::vector<std::string> ThemeManager::DiscoverAvailableThemeFiles() const {
1980 std::vector<std::string> theme_files;
1981 auto search_paths = GetThemeSearchPaths();
1982
1983 for (const auto& search_path : search_paths) {
1984
1985 try {
1986 // Use platform-specific file discovery instead of glob
1987#ifdef __APPLE__
1988 auto files_in_folder = util::FileDialogWrapper::GetFilesInFolder(search_path);
1989 for (const auto& file : files_in_folder) {
1990 if (file.length() > 6 && file.substr(file.length() - 6) == ".theme") {
1991 std::string full_path = search_path + file;
1992 theme_files.push_back(full_path);
1993 }
1994 }
1995#else
1996 // For Linux/Windows, use filesystem directory iteration
1997 // (could be extended with platform-specific implementations if needed)
1998 std::vector<std::string> known_themes = {
1999 "yaze_tre.theme", "cyberpunk.theme", "sunset.theme",
2000 "forest.theme", "midnight.theme"
2001 };
2002
2003 for (const auto& theme_name : known_themes) {
2004 std::string full_path = search_path + theme_name;
2005 std::ifstream test_file(full_path);
2006 if (test_file.good()) {
2007 theme_files.push_back(full_path);
2008 }
2009 }
2010#endif
2011 } catch (const std::exception& e) {
2012 LOG_ERROR("Theme Manager", "Error scanning directory %s", search_path.c_str());
2013 }
2014 }
2015
2016 // Remove duplicates while preserving order
2017 std::vector<std::string> unique_files;
2018 std::set<std::string> seen_basenames;
2019
2020 for (const auto& file : theme_files) {
2021 std::string basename = util::GetFileName(file);
2022 if (seen_basenames.find(basename) == seen_basenames.end()) {
2023 unique_files.push_back(file);
2024 seen_basenames.insert(basename);
2025 }
2026 }
2027
2028 return unique_files;
2029}
2030
2032 auto theme_files = DiscoverAvailableThemeFiles();
2033
2034 int successful_loads = 0;
2035 int failed_loads = 0;
2036
2037 for (const auto& theme_file : theme_files) {
2038 auto status = LoadThemeFromFile(theme_file);
2039 if (status.ok()) {
2040 successful_loads++;
2041 } else {
2042 failed_loads++;
2043 }
2044 }
2045
2046
2047 if (successful_loads == 0 && failed_loads > 0) {
2048 return absl::InternalError(absl::StrFormat("Failed to load any themes (%d failures)", failed_loads));
2049 }
2050
2051 return absl::OkStatus();
2052}
2053
2057
2059 if (current_theme_name_ == "Classic YAZE") {
2060 return ""; // Classic theme doesn't have a file
2061 }
2062
2063 // Try to find the current theme file in the search paths
2064 auto search_paths = GetThemeSearchPaths();
2065 std::string theme_filename = current_theme_name_ + ".theme";
2066
2067 // Convert theme name to safe filename (replace spaces and special chars)
2068 for (char& c : theme_filename) {
2069 if (!std::isalnum(c) && c != '.' && c != '_') {
2070 c = '_';
2071 }
2072 }
2073
2074 for (const auto& search_path : search_paths) {
2075 std::string full_path = search_path + theme_filename;
2076 std::ifstream test_file(full_path);
2077 if (test_file.good()) {
2078 return full_path;
2079 }
2080 }
2081
2082 // If not found, return path in the first search directory (for new saves)
2083 return search_paths.empty() ? theme_filename : search_paths[0] + theme_filename;
2084}
2085
2086} // namespace gui
2087} // namespace yaze
Manages themes, loading, saving, and switching.
Color ParseColorFromString(const std::string &color_str) const
const EnhancedTheme * GetTheme(const std::string &name) const
absl::Status ParseThemeFile(const std::string &content, EnhancedTheme &theme)
Color GetWelcomeScreenBackground() const
std::string GetCurrentThemeFilePath() const
EnhancedTheme current_theme_
absl::Status LoadTheme(const std::string &theme_name)
absl::Status LoadThemeFromFile(const std::string &filepath)
void ApplyTheme(const std::string &theme_name)
std::string GetThemesDirectory() const
std::string current_theme_name_
Color GetWelcomeScreenAccent() const
std::vector< std::string > DiscoverAvailableThemeFiles() const
absl::Status LoadAllAvailableThemes()
std::vector< std::string > GetThemeSearchPaths() const
std::string SerializeTheme(const EnhancedTheme &theme) const
static ThemeManager & Get()
absl::Status SaveThemeToFile(const EnhancedTheme &theme, const std::string &filepath) const
void ShowThemeSelector(bool *p_open)
absl::Status RefreshAvailableThemes()
const EnhancedTheme & GetCurrentTheme() const
Color GetWelcomeScreenBorder() const
void ShowSimpleThemeEditor(bool *p_open)
std::vector< std::string > GetAvailableThemes() const
std::map< std::string, EnhancedTheme > themes_
static std::string ShowSaveFileDialog(const std::string &default_name="", const std::string &default_extension="")
ShowSaveFileDialog opens a save file dialog and returns the selected filepath. Uses global feature fl...
static std::string ShowOpenFileDialog()
ShowOpenFileDialog opens a file dialog and returns the selected filepath. Uses global feature flag to...
static std::vector< std::string > GetFilesInFolder(const std::string &folder_path)
static absl::StatusOr< std::filesystem::path > GetConfigDirectory()
Get the user-specific configuration directory for YAZE.
#define ICON_MD_FOLDER_OPEN
Definition icons.h:811
#define ICON_MD_STAR
Definition icons.h:1846
#define ICON_MD_CHECK
Definition icons.h:395
#define ICON_MD_SAVE_AS
Definition icons.h:1644
#define ICON_MD_CIRCLE
Definition icons.h:409
#define ICON_MD_TEXT_FIELDS
Definition icons.h:1952
#define ICON_MD_TUNE
Definition icons.h:2020
#define ICON_MD_REFRESH
Definition icons.h:1570
#define ICON_MD_TABLE_CHART
Definition icons.h:1931
#define ICON_MD_AUTO_AWESOME
Definition icons.h:212
#define ICON_MD_EDIT
Definition icons.h:643
#define ICON_MD_ADD
Definition icons.h:84
#define ICON_MD_BORDER_ALL
Definition icons.h:290
#define ICON_MD_TOUCH_APP
Definition icons.h:1998
#define ICON_MD_SAVE
Definition icons.h:1642
#define ICON_MD_PALETTE
Definition icons.h:1368
#define ICON_MD_COLOR_LENS
Definition icons.h:438
#define ICON_MD_NAVIGATION
Definition icons.h:1274
#define LOG_ERROR(category, format,...)
Definition log.h:110
ImVec4 ConvertColorToImVec4(const Color &color)
Definition color.h:21
Color RGBA(int r, int g, int b, int a=255)
void ColorsYaze()
Definition style.cc:32
Color RGB(float r, float g, float b, float a=1.0f)
std::string GetFileName(const std::string &filename)
Gets the filename from a full path.
Definition file_util.cc:19
std::string GetResourcePath(const std::string &resource_path)
Definition file_util.cc:70
std::string GetBundleResourcePath()
GetBundleResourcePath returns the path to the bundle resource directory. Specific to MacOS.
Main namespace for the application.
float alpha
Definition color.h:18
float green
Definition color.h:16
Comprehensive theme structure for YAZE.