Skip to content

Commit 8d9e8ed

Browse files
committed
Fixes json import, removes lambda functions
1 parent 99b6f85 commit 8d9e8ed

File tree

2 files changed

+117
-114
lines changed

2 files changed

+117
-114
lines changed

editor/themes/theme.cpp

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

editor/themes/theme.h

Lines changed: 2 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -1,124 +1,12 @@
11
#pragma once
22

33
#include "common/types.h"
4-
#include "../../rootex/vendor/JSON/json.hpp"
5-
#include <fstream>
64

75
struct ThemeDefinition
86
{
97
String m_Name;
108
String m_filePath;
11-
nlohmann::json m_ThemeData;
9+
JSON::json m_ThemeData;
1210

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;
12412
};

0 commit comments

Comments
 (0)