yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
theme_manager.h
Go to the documentation of this file.
1#ifndef YAZE_APP_GUI_THEME_MANAGER_H
2#define YAZE_APP_GUI_THEME_MANAGER_H
3
4#include <map>
5#include <string>
6#include <vector>
7
8#include "absl/status/status.h"
9#include "absl/status/statusor.h"
10#include "app/gui/core/color.h"
11#include "imgui/imgui.h"
12
13namespace yaze {
14namespace gui {
15
20enum class DensityPreset {
21 kCompact, // 0.75x - Dense UI, more content visible
22 kNormal, // 1.0x - Default balanced spacing
23 kComfortable // 1.25x - Spacious, easier to click
24};
25
30struct Theme {
31 std::string name;
32 std::string description;
33 std::string author;
34
35 // Primary colors
45
46 // Text colors
50
51 // Window colors
56
57 // Interactive elements
64
65 // Navigation and selection
76
77 // Borders and separators
83
84 // Scrollbars and controls
89
90 // Special elements
96
97 // Complete ImGui color support
119
120 // Additional ImGui colors for complete coverage
127
128 // Enhanced theme system - semantic colors
129 Color text_highlight; // For selected text, highlighted items
130 Color link_hover; // For hover state of links
131 Color code_background; // For code blocks, monospace text backgrounds
132 Color success_light; // Lighter variant of success color
133 Color warning_light; // Lighter variant of warning color
134 Color error_light; // Lighter variant of error color
135 Color info_light; // Lighter variant of info color
136
137 // UI state colors
138 Color active_selection; // For active/selected UI elements
139 Color hover_highlight; // General hover state
140 Color focus_border; // For focused input elements
141 Color disabled_overlay; // Semi-transparent overlay for disabled elements
142
143 // Editor-specific colors
144 Color editor_background; // Main editor canvas background
145 Color editor_grid; // Grid lines in editors
146 Color editor_cursor; // Cursor/selection in editors
147 Color editor_selection; // Selected area in editors
148
149 // Unified selection and interaction colors (replacing hardcoded values)
150 Color selection_primary; // Primary selection (typically gold/yellow)
151 Color selection_secondary; // Secondary selection (typically cyan/blue)
152 Color selection_hover; // Hover highlight color
153 Color selection_pulsing; // Pulsing animation color
154 Color selection_handle; // Corner handles for resizing/moving
155 Color drag_preview; // Ghost preview when dragging
156 Color drag_preview_outline; // Outline for drag preview
157
158 // Common entity colors
166
167 // Nested struct for dungeon editor colors
196
197 // Nested struct for chat/agent colors
236
237 // Style parameters
238 float window_rounding = 0.0f;
239 float frame_rounding = 5.0f;
240 float scrollbar_rounding = 5.0f;
241 float grab_rounding = 3.0f;
242 float tab_rounding = 0.0f;
243 float window_border_size = 0.0f;
244 float frame_border_size = 0.0f;
245
246 // Animation and effects
247 bool enable_animations = true;
248 float animation_speed = 1.0f;
250
251 // Theme-aware sizing system (relative to font size)
252 // compact_factor: 0.8 = very compact, 1.0 = normal, 1.2 = spacious
253 float compact_factor = 1.0f;
255
256 // Semantic sizing multipliers (applied on top of compact_factor)
257 float widget_height_multiplier = 1.0f; // Standard widget height
258 float spacing_multiplier = 1.0f; // Padding/margins between elements
259 float toolbar_height_multiplier = 0.8f; // Compact toolbars
260 float panel_padding_multiplier = 1.0f; // Panel interior padding
261 float input_width_multiplier = 1.0f; // Standard input field width
262 float button_padding_multiplier = 1.0f; // Button interior padding
263 float table_row_height_multiplier = 1.0f; // Table row height
264 float canvas_toolbar_multiplier = 0.75f; // Canvas overlay toolbars
265
266 // Helper methods
267 void ApplyToImGui() const;
269};
270
276 public:
277 static ThemeManager& Get();
278
279 // Theme management
280 absl::Status LoadTheme(const std::string& theme_name);
281 absl::Status SaveTheme(const Theme& theme,
282 const std::string& filename);
283 absl::Status LoadThemeFromFile(const std::string& filepath);
284 absl::Status SaveThemeToFile(const Theme& theme,
285 const std::string& filepath) const;
286
287 // Dynamic theme discovery - replaces hardcoded theme lists with automatic
288 // discovery This works across development builds, macOS app bundles, and
289 // other deployment scenarios
290 std::vector<std::string> DiscoverAvailableThemeFiles() const;
291 absl::Status LoadAllAvailableThemes();
292 absl::Status RefreshAvailableThemes(); // Public method to refresh at runtime
293
294 // Built-in themes
296 std::vector<std::string> GetAvailableThemes() const;
297 const Theme* GetTheme(const std::string& name) const;
298 const Theme& GetCurrentTheme() const { return current_theme_; }
299 const std::string& GetCurrentThemeName() const { return current_theme_name_; }
300
301 // Theme application
302 void ApplyTheme(const std::string& theme_name);
303 void ApplyTheme(const Theme& theme);
304 void ApplyClassicYazeTheme(); // Apply original ColorsYaze() function
305
306 // Theme preview (for hover preview in selector)
307 void StartPreview(const std::string& theme_name);
308 void EndPreview();
309 bool IsPreviewActive() const;
310
311 // Smooth theme transitions
312 void UpdateTransition();
313 bool IsTransitioning() const { return transitioning_; }
314
315 // Theme creation and editing
316 Theme CreateCustomTheme(const std::string& name);
317 void ShowThemeEditor(bool* p_open);
318 void ShowThemeSelector(bool* p_open);
319 void ShowSimpleThemeEditor(bool* p_open);
320
321 // Accent color derivation - generate harmonious theme from single color
322 Theme GenerateThemeFromAccent(const Color& accent, bool dark_mode = true);
323 void ApplyAccentColor(const Color& accent, bool dark_mode = true);
324
325 // Integration with welcome screen
329
330 // Export current theme as JSON string for Web/WASM sync
331 std::string ExportCurrentThemeJson() const;
332
333 // Convenient theme color access interface
334 Color GetThemeColor(const std::string& color_name) const;
335 ImVec4 GetThemeColorVec4(const std::string& color_name) const;
336
337 // Material Design color accessors
356
357 private:
359
360 std::map<std::string, Theme> themes_;
362 std::string current_theme_name_ = "Classic YAZE";
363
364 // Preview state for hover preview in theme selector
365 bool preview_active_ = false;
368
369 // Smooth transition state (lerps ImGui colors per-frame)
370 bool transitioning_ = false;
372 ImVec4 transition_from_[ImGuiCol_COUNT] = {};
373 ImVec4 transition_to_[ImGuiCol_COUNT] = {};
374
376 absl::Status ParseThemeFile(const std::string& content, Theme& theme);
377 void ApplySmartDefaults(Theme& theme); // Fill missing properties from primary colors
378 Color ParseColorFromString(const std::string& color_str) const;
379 std::string SerializeTheme(const Theme& theme) const;
380
381 // Helper methods for path resolution
382 std::vector<std::string> GetThemeSearchPaths() const;
383 std::string GetThemesDirectory() const;
384 std::string GetUserThemesDirectory() const; // Returns ~/.yaze/themes/
385 std::string GetCurrentThemeFilePath() const;
386};
387
388// Global convenience functions for easy theme color access
389// Material Design color accessors - global convenience functions
390inline Color GetThemeColor(const std::string& color_name) {
391 return ThemeManager::Get().GetThemeColor(color_name);
392}
393
394inline ImVec4 GetThemeColorVec4(const std::string& color_name) {
395 return ThemeManager::Get().GetThemeColorVec4(color_name);
396}
397
398// Material Design color accessors
400 return ThemeManager::Get().GetPrimary();
401}
410}
412 return ThemeManager::Get().GetSurface();
413}
428}
434}
436 return ThemeManager::Get().GetOutline();
437}
444inline Color GetShadow() {
445 return ThemeManager::Get().GetShadow();
446}
447
448// ImVec4 versions for direct ImGui usage
449inline ImVec4 GetPrimaryVec4() {
451}
452inline ImVec4 GetPrimaryHoverVec4() {
454}
455inline ImVec4 GetPrimaryActiveVec4() {
457}
458inline ImVec4 GetSurfaceVec4() {
460}
473inline ImVec4 GetOnSurfaceVec4() {
475}
479inline ImVec4 GetOnPrimaryVec4() {
481}
482inline ImVec4 GetOutlineVec4() {
484}
485inline ImVec4 GetTextSecondaryVec4() {
487}
488inline ImVec4 GetTextDisabledVec4() {
490}
491inline ImVec4 GetShadowVec4() {
493}
494} // namespace gui
495
496} // namespace yaze
497
498#endif // YAZE_APP_GUI_THEME_MANAGER_H
Manages themes, loading, saving, and switching.
Color GetSurfaceContainerHigh() const
Color ParseColorFromString(const std::string &color_str) const
Color GetSurfaceVariant() const
std::string preview_original_name_
Color GetTextSecondary() const
void ShowThemeEditor(bool *p_open)
Color GetWelcomeScreenBackground() const
ImVec4 GetThemeColorVec4(const std::string &color_name) const
void StartPreview(const std::string &theme_name)
absl::Status SaveTheme(const Theme &theme, const std::string &filename)
std::string GetCurrentThemeFilePath() const
std::map< std::string, Theme > themes_
absl::Status LoadTheme(const std::string &theme_name)
const Theme & GetCurrentTheme() const
Color GetPrimaryHover() const
absl::Status LoadThemeFromFile(const std::string &filepath)
void ApplyTheme(const std::string &theme_name)
std::string GetThemesDirectory() const
std::string current_theme_name_
ImVec4 transition_to_[ImGuiCol_COUNT]
Color GetWelcomeScreenAccent() const
void ApplyAccentColor(const Color &accent, bool dark_mode=true)
std::vector< std::string > DiscoverAvailableThemeFiles() const
std::string GetUserThemesDirectory() const
Theme CreateCustomTheme(const std::string &name)
absl::Status LoadAllAvailableThemes()
Color GetSurfaceContainer() const
Color GetOnSurfaceVariant() const
absl::Status SaveThemeToFile(const Theme &theme, const std::string &filepath) const
std::vector< std::string > GetThemeSearchPaths() const
absl::Status ParseThemeFile(const std::string &content, Theme &theme)
static ThemeManager & Get()
Color GetThemeColor(const std::string &color_name) const
const std::string & GetCurrentThemeName() const
void ShowThemeSelector(bool *p_open)
Theme GenerateThemeFromAccent(const Color &accent, bool dark_mode=true)
const Theme * GetTheme(const std::string &name) const
std::string SerializeTheme(const Theme &theme) const
absl::Status RefreshAvailableThemes()
Color GetTextDisabled() const
std::string ExportCurrentThemeJson() const
void ApplySmartDefaults(Theme &theme)
Color GetSurfaceContainerHighest() const
Color GetWelcomeScreenBorder() const
void ShowSimpleThemeEditor(bool *p_open)
Color GetPrimaryActive() const
ImVec4 transition_from_[ImGuiCol_COUNT]
std::vector< std::string > GetAvailableThemes() const
ImVec4 ConvertColorToImVec4(const Color &color)
Definition color.h:134
ImVec4 GetSurfaceContainerHighestVec4()
Color GetPrimaryHover()
Color GetOnPrimary()
ImVec4 GetThemeColorVec4(const std::string &color_name)
Color GetOnSurfaceVariant()
ImVec4 GetOnPrimaryVec4()
Color GetTextDisabled()
ImVec4 GetPrimaryActiveVec4()
Color GetSurfaceContainerHighest()
Color GetOnSurface()
ImVec4 GetPrimaryVec4()
Color GetSecondary()
Color GetSurfaceContainer()
ImVec4 GetSurfaceVariantVec4()
ImVec4 GetSurfaceVec4()
DensityPreset
Typography and spacing density presets.
ImVec4 GetTextDisabledVec4()
Color GetTextSecondary()
Color GetOutline()
Color GetShadow()
ImVec4 GetTextSecondaryVec4()
ImVec4 GetShadowVec4()
ImVec4 GetSurfaceContainerHighVec4()
ImVec4 GetPrimaryHoverVec4()
Color GetPrimaryActive()
Color GetPrimary()
Color GetSurface()
ImVec4 GetOutlineVec4()
Color GetThemeColor(const std::string &color_name)
Color GetSurfaceContainerHigh()
ImVec4 GetOnSurfaceVariantVec4()
ImVec4 GetOnSurfaceVec4()
ImVec4 GetSurfaceContainerVec4()
Color GetSurfaceVariant()
Comprehensive theme structure for YAZE.
Color tab_dimmed_selected_overline
std::string description
std::string name
Color scrollbar_grab_hovered
Color scrollbar_grab_active
Color nav_windowing_highlight
float panel_padding_multiplier
float widget_height_multiplier
struct yaze::gui::Theme::DungeonColors dungeon
struct yaze::gui::Theme::AgentTheme agent
void ApplyToImGui() const
float button_padding_multiplier
float table_row_height_multiplier
float toolbar_height_multiplier
DensityPreset density_preset
void ApplyDensityPreset(DensityPreset preset)
std::string author
float canvas_toolbar_multiplier