|
1 | 1 | #pragma once |
2 | 2 |
|
3 | 3 | #include "common/types.h" |
4 | | -#include "../../rootex/vendor/JSON/json.hpp" |
5 | | -#include <fstream> |
6 | 4 |
|
7 | 5 | struct ThemeDefinition |
8 | 6 | { |
9 | 7 | String m_Name; |
10 | 8 | String m_filePath; |
11 | | - nlohmann::json m_ThemeData; |
| 9 | + JSON::json m_ThemeData; |
12 | 10 |
|
13 | | - void apply() const |
14 | | - { |
15 | | - ImGui::StyleColorsDark(); // Base reset |
16 | | - |
17 | | - ImGuiStyle& style = ImGui::GetStyle(); |
18 | | - ImVec4* colors = style.Colors; |
19 | | - |
20 | | - // Only apply if present |
21 | | - if (!m_ThemeData.contains("style") && !m_ThemeData.contains("colors")) |
22 | | - { |
23 | | - return; |
24 | | - } |
25 | | - |
26 | | - // --- Lambda utilities --- |
27 | | - auto setVec2 = [](const nlohmann::json& j, const char* key, ImVec2& ref) |
28 | | - { |
29 | | - if (j.contains(key) && j[key].is_array() && j[key].size() == 2) |
30 | | - ref = ImVec2(j[key][0], j[key][1]); |
31 | | - }; |
32 | | - |
33 | | - auto setFloat = [](const nlohmann::json& j, const char* key, float& ref) |
34 | | - { |
35 | | - if (j.contains(key)) |
36 | | - ref = j[key].get<float>(); |
37 | | - }; |
38 | | - |
39 | | - auto setColor = [](const nlohmann::json& j, const char* key, ImVec4& ref) |
40 | | - { |
41 | | - if (j.contains(key) && j[key].is_array() && j[key].size() == 4) |
42 | | - ref = ImVec4(j[key][0], j[key][1], j[key][2], j[key][3]); |
43 | | - }; |
44 | | - |
45 | | - // --- Apply style if present --- |
46 | | - if (m_ThemeData.contains("style")) |
47 | | - { |
48 | | - const auto& s = m_ThemeData["style"]; |
49 | | - setVec2(s, "WindowPadding", style.WindowPadding); |
50 | | - setFloat(s, "WindowRounding", style.WindowRounding); |
51 | | - setVec2(s, "FramePadding", style.FramePadding); |
52 | | - setFloat(s, "FrameRounding", style.FrameRounding); |
53 | | - setVec2(s, "ItemSpacing", style.ItemSpacing); |
54 | | - setVec2(s, "ItemInnerSpacing", style.ItemInnerSpacing); |
55 | | - setFloat(s, "IndentSpacing", style.IndentSpacing); |
56 | | - setFloat(s, "ScrollbarSize", style.ScrollbarSize); |
57 | | - setFloat(s, "ScrollbarRounding", style.ScrollbarRounding); |
58 | | - setFloat(s, "GrabMinSize", style.GrabMinSize); |
59 | | - setFloat(s, "GrabRounding", style.GrabRounding); |
60 | | - } |
61 | | - |
62 | | - // --- Apply colors if present --- |
63 | | - if (m_ThemeData.contains("colors")) |
64 | | - { |
65 | | - const auto& c = m_ThemeData["colors"]; |
66 | | - |
67 | | - setColor(c, "Text", colors[ImGuiCol_Text]); |
68 | | - setColor(c, "TextDisabled", colors[ImGuiCol_TextDisabled]); |
69 | | - setColor(c, "WindowBg", colors[ImGuiCol_WindowBg]); |
70 | | - setColor(c, "ChildBg", colors[ImGuiCol_ChildBg]); |
71 | | - setColor(c, "PopupBg", colors[ImGuiCol_PopupBg]); |
72 | | - setColor(c, "Border", colors[ImGuiCol_Border]); |
73 | | - setColor(c, "BorderShadow", colors[ImGuiCol_BorderShadow]); |
74 | | - setColor(c, "FrameBg", colors[ImGuiCol_FrameBg]); |
75 | | - setColor(c, "FrameBgHovered", colors[ImGuiCol_FrameBgHovered]); |
76 | | - setColor(c, "FrameBgActive", colors[ImGuiCol_FrameBgActive]); |
77 | | - setColor(c, "TitleBg", colors[ImGuiCol_TitleBg]); |
78 | | - setColor(c, "TitleBgActive", colors[ImGuiCol_TitleBgActive]); |
79 | | - setColor(c, "TitleBgCollapsed", colors[ImGuiCol_TitleBgCollapsed]); |
80 | | - setColor(c, "MenuBarBg", colors[ImGuiCol_MenuBarBg]); |
81 | | - setColor(c, "ScrollbarBg", colors[ImGuiCol_ScrollbarBg]); |
82 | | - setColor(c, "ScrollbarGrab", colors[ImGuiCol_ScrollbarGrab]); |
83 | | - setColor(c, "ScrollbarGrabHovered", colors[ImGuiCol_ScrollbarGrabHovered]); |
84 | | - setColor(c, "ScrollbarGrabActive", colors[ImGuiCol_ScrollbarGrabActive]); |
85 | | - setColor(c, "CheckMark", colors[ImGuiCol_CheckMark]); |
86 | | - setColor(c, "SliderGrab", colors[ImGuiCol_SliderGrab]); |
87 | | - setColor(c, "SliderGrabActive", colors[ImGuiCol_SliderGrabActive]); |
88 | | - setColor(c, "Button", colors[ImGuiCol_Button]); |
89 | | - setColor(c, "ButtonHovered", colors[ImGuiCol_ButtonHovered]); |
90 | | - setColor(c, "ButtonActive", colors[ImGuiCol_ButtonActive]); |
91 | | - setColor(c, "Header", colors[ImGuiCol_Header]); |
92 | | - setColor(c, "HeaderHovered", colors[ImGuiCol_HeaderHovered]); |
93 | | - setColor(c, "HeaderActive", colors[ImGuiCol_HeaderActive]); |
94 | | - setColor(c, "Separator", colors[ImGuiCol_Separator]); |
95 | | - setColor(c, "SeparatorHovered", colors[ImGuiCol_SeparatorHovered]); |
96 | | - setColor(c, "SeparatorActive", colors[ImGuiCol_SeparatorActive]); |
97 | | - setColor(c, "ResizeGrip", colors[ImGuiCol_ResizeGrip]); |
98 | | - setColor(c, "ResizeGripHovered", colors[ImGuiCol_ResizeGripHovered]); |
99 | | - setColor(c, "ResizeGripActive", colors[ImGuiCol_ResizeGripActive]); |
100 | | - setColor(c, "Tab", colors[ImGuiCol_Tab]); |
101 | | - setColor(c, "TabHovered", colors[ImGuiCol_TabHovered]); |
102 | | - setColor(c, "TabActive", colors[ImGuiCol_TabActive]); |
103 | | - setColor(c, "TabUnfocused", colors[ImGuiCol_TabUnfocused]); |
104 | | - setColor(c, "TabUnfocusedActive", colors[ImGuiCol_TabUnfocusedActive]); |
105 | | - setColor(c, "DockingPreview", colors[ImGuiCol_DockingPreview]); |
106 | | - setColor(c, "DockingEmptyBg", colors[ImGuiCol_DockingEmptyBg]); |
107 | | - setColor(c, "PlotLines", colors[ImGuiCol_PlotLines]); |
108 | | - setColor(c, "PlotLinesHovered", colors[ImGuiCol_PlotLinesHovered]); |
109 | | - setColor(c, "PlotHistogram", colors[ImGuiCol_PlotHistogram]); |
110 | | - setColor(c, "PlotHistogramHovered", colors[ImGuiCol_PlotHistogramHovered]); |
111 | | - setColor(c, "TableHeaderBg", colors[ImGuiCol_TableHeaderBg]); |
112 | | - setColor(c, "TableBorderStrong", colors[ImGuiCol_TableBorderStrong]); |
113 | | - setColor(c, "TableBorderLight", colors[ImGuiCol_TableBorderLight]); |
114 | | - setColor(c, "TableRowBg", colors[ImGuiCol_TableRowBg]); |
115 | | - setColor(c, "TableRowBgAlt", colors[ImGuiCol_TableRowBgAlt]); |
116 | | - setColor(c, "TextSelectedBg", colors[ImGuiCol_TextSelectedBg]); |
117 | | - setColor(c, "DragDropTarget", colors[ImGuiCol_DragDropTarget]); |
118 | | - setColor(c, "NavHighlight", colors[ImGuiCol_NavHighlight]); |
119 | | - setColor(c, "NavWindowingHighlight", colors[ImGuiCol_NavWindowingHighlight]); |
120 | | - setColor(c, "NavWindowingDimBg", colors[ImGuiCol_NavWindowingDimBg]); |
121 | | - setColor(c, "ModalWindowDimBg", colors[ImGuiCol_ModalWindowDimBg]); |
122 | | - } |
123 | | - } |
| 11 | + void apply() const; |
124 | 12 | }; |
0 commit comments