Skip to content

Commit 7fd9f77

Browse files
committed
Adds theme interface
1 parent 5fb0034 commit 7fd9f77

File tree

6 files changed

+138
-88
lines changed

6 files changed

+138
-88
lines changed

editor/editor.app.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
}
2121
},
2222
"InputSystem": {
23-
"height": 991,
23+
"height": 1009,
2424
"inputSchemes": {
2525
"Editor": {
2626
"bools": [
@@ -91,7 +91,7 @@
9191
},
9292
"PhysicsSystem": {},
9393
"UISystem": {
94-
"height": 991,
94+
"height": 1009,
9595
"width": 1920
9696
}
9797
},

editor/editor_system.cpp

Lines changed: 18 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -96,80 +96,11 @@ bool EditorSystem::initialize(const JSON::json& systemData)
9696
}
9797
ImGui_ImplWin32_Init(Application::GetSingleton()->getWindow()->getWindowHandle());
9898
ImGui_ImplDX11_Init(RenderingDevice::GetSingleton()->getDevice(), RenderingDevice::GetSingleton()->getContext());
99-
ImGui::StyleColorsDark();
100-
101-
{
102-
ImGuiStyle& style = ImGui::GetStyle();
103-
style.WindowPadding = ImVec2(15, 15);
104-
style.WindowRounding = 5.0f;
105-
style.FramePadding = ImVec2(5, 5);
106-
style.FrameRounding = 4.0f;
107-
style.ItemSpacing = ImVec2(12, 6);
108-
style.ItemInnerSpacing = ImVec2(8, 4);
109-
style.IndentSpacing = 25.0f;
110-
style.ScrollbarSize = 15.0f;
111-
style.ScrollbarRounding = 9.0f;
112-
style.GrabMinSize = 5.0f;
113-
style.GrabRounding = 3.0f;
114-
115-
ImVec4* colors = ImGui::GetStyle().Colors;
116-
colors[ImGuiCol_Text] = ImVec4(0.80f, 0.80f, 0.83f, 1.00f);
117-
colors[ImGuiCol_TextDisabled] = ImVec4(0.24f, 0.23f, 0.29f, 1.00f);
118-
colors[ImGuiCol_WindowBg] = ImVec4(0.05f, 0.05f, 0.07f, 1.00f);
119-
colors[ImGuiCol_ChildBg] = ImVec4(0.07f, 0.07f, 0.09f, 1.00f);
120-
colors[ImGuiCol_PopupBg] = ImVec4(0.14f, 0.14f, 0.14f, 1.00f);
121-
colors[ImGuiCol_Border] = ImVec4(0.23f, 0.23f, 0.23f, 1.00f);
122-
colors[ImGuiCol_BorderShadow] = ImVec4(0.68f, 0.63f, 0.63f, 1.00f);
123-
colors[ImGuiCol_FrameBg] = ImVec4(0.10f, 0.09f, 0.12f, 1.00f);
124-
colors[ImGuiCol_FrameBgHovered] = ImVec4(0.24f, 0.23f, 0.29f, 1.00f);
125-
colors[ImGuiCol_FrameBgActive] = ImVec4(0.56f, 0.56f, 0.58f, 1.00f);
126-
colors[ImGuiCol_TitleBg] = ImVec4(0.10f, 0.09f, 0.12f, 1.00f);
127-
colors[ImGuiCol_TitleBgActive] = ImVec4(0.07f, 0.07f, 0.09f, 1.00f);
128-
colors[ImGuiCol_TitleBgCollapsed] = ImVec4(1.00f, 0.98f, 0.95f, 0.75f);
129-
colors[ImGuiCol_MenuBarBg] = ImVec4(0.10f, 0.09f, 0.12f, 1.00f);
130-
colors[ImGuiCol_ScrollbarBg] = ImVec4(0.10f, 0.09f, 0.12f, 1.00f);
131-
colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.80f, 0.80f, 0.83f, 0.31f);
132-
colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.56f, 0.56f, 0.58f, 1.00f);
133-
colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.06f, 0.05f, 0.07f, 1.00f);
134-
colors[ImGuiCol_CheckMark] = ImVec4(0.20f, 0.68f, 0.42f, 0.83f);
135-
colors[ImGuiCol_SliderGrab] = ImVec4(0.80f, 0.80f, 0.83f, 0.31f);
136-
colors[ImGuiCol_SliderGrabActive] = ImVec4(0.06f, 0.05f, 0.07f, 1.00f);
137-
colors[ImGuiCol_Button] = ImVec4(0.12f, 0.43f, 0.33f, 0.88f);
138-
colors[ImGuiCol_ButtonHovered] = ImVec4(0.20f, 0.68f, 0.42f, 0.83f);
139-
colors[ImGuiCol_ButtonActive] = ImVec4(0.56f, 0.56f, 0.58f, 1.00f);
140-
colors[ImGuiCol_Header] = ImVec4(0.20f, 0.68f, 0.42f, 0.58f);
141-
colors[ImGuiCol_HeaderHovered] = ImVec4(0.20f, 0.68f, 0.42f, 0.83f);
142-
colors[ImGuiCol_HeaderActive] = ImVec4(0.06f, 0.05f, 0.07f, 1.00f);
143-
colors[ImGuiCol_Separator] = ImVec4(0.43f, 0.43f, 0.50f, 0.50f);
144-
colors[ImGuiCol_SeparatorHovered] = ImVec4(0.20f, 0.68f, 0.42f, 0.83f);
145-
colors[ImGuiCol_SeparatorActive] = ImVec4(0.36f, 0.75f, 0.10f, 1.00f);
146-
colors[ImGuiCol_ResizeGrip] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
147-
colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.56f, 0.56f, 0.58f, 1.00f);
148-
colors[ImGuiCol_ResizeGripActive] = ImVec4(0.06f, 0.05f, 0.07f, 1.00f);
149-
colors[ImGuiCol_Tab] = ImVec4(0.18f, 0.57f, 0.58f, 0.86f);
150-
colors[ImGuiCol_TabHovered] = ImVec4(0.20f, 0.68f, 0.42f, 0.83f);
151-
colors[ImGuiCol_TabActive] = ImVec4(0.20f, 0.68f, 0.42f, 1.00f);
152-
colors[ImGuiCol_TabUnfocused] = ImVec4(0.14f, 0.41f, 0.42f, 0.46f);
153-
colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.14f, 0.41f, 0.42f, 1.00f);
154-
colors[ImGuiCol_DockingPreview] = ImVec4(0.00f, 1.00f, 0.21f, 0.70f);
155-
colors[ImGuiCol_DockingEmptyBg] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f);
156-
colors[ImGuiCol_PlotLines] = ImVec4(0.40f, 0.39f, 0.38f, 0.63f);
157-
colors[ImGuiCol_PlotLinesHovered] = ImVec4(0.25f, 1.00f, 0.00f, 1.00f);
158-
colors[ImGuiCol_PlotHistogram] = ImVec4(0.40f, 0.39f, 0.38f, 0.63f);
159-
colors[ImGuiCol_PlotHistogramHovered] = ImVec4(0.25f, 1.00f, 0.00f, 1.00f);
160-
colors[ImGuiCol_TableHeaderBg] = ImVec4(0.19f, 0.19f, 0.20f, 1.00f);
161-
colors[ImGuiCol_TableBorderStrong] = ImVec4(0.31f, 0.31f, 0.35f, 1.00f);
162-
colors[ImGuiCol_TableBorderLight] = ImVec4(0.23f, 0.23f, 0.25f, 1.00f);
163-
colors[ImGuiCol_TableRowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
164-
colors[ImGuiCol_TableRowBgAlt] = ImVec4(1.00f, 1.00f, 1.00f, 0.06f);
165-
colors[ImGuiCol_TextSelectedBg] = ImVec4(0.25f, 1.00f, 0.00f, 0.48f);
166-
colors[ImGuiCol_DragDropTarget] = ImVec4(1.00f, 1.00f, 0.00f, 0.90f);
167-
colors[ImGuiCol_NavHighlight] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
168-
colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.00f, 1.00f, 1.00f, 0.70f);
169-
colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.20f);
170-
colors[ImGuiCol_ModalWindowDimBg] = ImVec4(1.00f, 0.98f, 0.95f, 0.73f);
171-
}
172-
99+
100+
m_Themes.push_back(std::make_unique<DarkTheme>());
101+
m_CurrentTheme = m_Themes.front().get();
102+
m_CurrentTheme->apply();
103+
173104
return true;
174105
}
175106

@@ -416,6 +347,19 @@ void EditorSystem::drawDefaultUI(float deltaMilliseconds)
416347
static bool styleEditor = false;
417348
if (ImGui::BeginMenu("View"))
418349
{
350+
if (ImGui::BeginMenu("Theme"))
351+
{
352+
for (auto& theme : m_Themes)
353+
{
354+
if (ImGui::MenuItem(theme->getName().c_str(), "", m_CurrentTheme == theme.get()))
355+
{
356+
m_CurrentTheme = theme.get();
357+
m_CurrentTheme->apply();
358+
}
359+
}
360+
ImGui::EndMenu();
361+
}
362+
419363
if (ImGui::Checkbox("Wireframe Mode", &m_WireframeMode))
420364
{
421365
if (m_WireframeMode)

editor/editor_system.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
#include "Tracy/Tracy.hpp"
1313

14+
#include "themes/theme.h"
15+
#include "themes/dark_theme.h"
16+
1417
ImColor ColorToImColor(Color& c);
1518

1619
class SceneDock;
@@ -82,6 +85,9 @@ class EditorSystem : public System
8285
int exportScene(const String& sceneName, const String& sceneFilePath, Atomic<int>& progress);
8386
void postExport();
8487

88+
Vector<std::unique_ptr<Theme>> m_Themes;
89+
Theme* m_CurrentTheme = nullptr;
90+
8591
public:
8692
static EditorSystem* GetSingleton();
8793

editor/themes/dark_theme.h

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
// dark_theme.cpp
2+
#pragma once
3+
4+
#include "theme.h"
5+
6+
struct DarkTheme : public Theme
7+
{
8+
public:
9+
void apply() const override
10+
{
11+
ImGui::StyleColorsDark();
12+
ImGuiStyle& style = ImGui::GetStyle();
13+
14+
// Layout
15+
style.WindowPadding = ImVec2(15, 15);
16+
style.WindowRounding = 5.0f;
17+
style.FramePadding = ImVec2(5, 5);
18+
style.FrameRounding = 4.0f;
19+
style.ItemSpacing = ImVec2(12, 6);
20+
style.ItemInnerSpacing = ImVec2(8, 4);
21+
style.IndentSpacing = 25.0f;
22+
style.ScrollbarSize = 15.0f;
23+
style.ScrollbarRounding = 9.0f;
24+
style.GrabMinSize = 5.0f;
25+
style.GrabRounding = 3.0f;
26+
27+
// Colors
28+
ImVec4* colors = style.Colors;
29+
colors[ImGuiCol_Text] = ImVec4(0.80f, 0.80f, 0.83f, 1.00f);
30+
colors[ImGuiCol_TextDisabled] = ImVec4(0.24f, 0.23f, 0.29f, 1.00f);
31+
colors[ImGuiCol_WindowBg] = ImVec4(0.05f, 0.05f, 0.07f, 1.00f);
32+
colors[ImGuiCol_ChildBg] = ImVec4(0.07f, 0.07f, 0.09f, 1.00f);
33+
colors[ImGuiCol_PopupBg] = ImVec4(0.14f, 0.14f, 0.14f, 1.00f);
34+
colors[ImGuiCol_Border] = ImVec4(0.23f, 0.23f, 0.23f, 1.00f);
35+
colors[ImGuiCol_BorderShadow] = ImVec4(0.68f, 0.63f, 0.63f, 1.00f);
36+
colors[ImGuiCol_FrameBg] = ImVec4(0.10f, 0.09f, 0.12f, 1.00f);
37+
colors[ImGuiCol_FrameBgHovered] = ImVec4(0.24f, 0.23f, 0.29f, 1.00f);
38+
colors[ImGuiCol_FrameBgActive] = ImVec4(0.56f, 0.56f, 0.58f, 1.00f);
39+
colors[ImGuiCol_TitleBg] = ImVec4(0.10f, 0.09f, 0.12f, 1.00f);
40+
colors[ImGuiCol_TitleBgActive] = ImVec4(0.07f, 0.07f, 0.09f, 1.00f);
41+
colors[ImGuiCol_TitleBgCollapsed] = ImVec4(1.00f, 0.98f, 0.95f, 0.75f);
42+
colors[ImGuiCol_MenuBarBg] = ImVec4(0.10f, 0.09f, 0.12f, 1.00f);
43+
colors[ImGuiCol_ScrollbarBg] = ImVec4(0.10f, 0.09f, 0.12f, 1.00f);
44+
colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.80f, 0.80f, 0.83f, 0.31f);
45+
colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.56f, 0.56f, 0.58f, 1.00f);
46+
colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.06f, 0.05f, 0.07f, 1.00f);
47+
colors[ImGuiCol_CheckMark] = ImVec4(0.20f, 0.68f, 0.42f, 0.83f);
48+
colors[ImGuiCol_SliderGrab] = ImVec4(0.80f, 0.80f, 0.83f, 0.31f);
49+
colors[ImGuiCol_SliderGrabActive] = ImVec4(0.06f, 0.05f, 0.07f, 1.00f);
50+
colors[ImGuiCol_Button] = ImVec4(0.12f, 0.43f, 0.33f, 0.88f);
51+
colors[ImGuiCol_ButtonHovered] = ImVec4(0.20f, 0.68f, 0.42f, 0.83f);
52+
colors[ImGuiCol_ButtonActive] = ImVec4(0.56f, 0.56f, 0.58f, 1.00f);
53+
colors[ImGuiCol_Header] = ImVec4(0.20f, 0.68f, 0.42f, 0.58f);
54+
colors[ImGuiCol_HeaderHovered] = ImVec4(0.20f, 0.68f, 0.42f, 0.83f);
55+
colors[ImGuiCol_HeaderActive] = ImVec4(0.06f, 0.05f, 0.07f, 1.00f);
56+
colors[ImGuiCol_Separator] = ImVec4(0.43f, 0.43f, 0.50f, 0.50f);
57+
colors[ImGuiCol_SeparatorHovered] = ImVec4(0.20f, 0.68f, 0.42f, 0.83f);
58+
colors[ImGuiCol_SeparatorActive] = ImVec4(0.36f, 0.75f, 0.10f, 1.00f);
59+
colors[ImGuiCol_ResizeGrip] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
60+
colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.56f, 0.56f, 0.58f, 1.00f);
61+
colors[ImGuiCol_ResizeGripActive] = ImVec4(0.06f, 0.05f, 0.07f, 1.00f);
62+
colors[ImGuiCol_Tab] = ImVec4(0.18f, 0.57f, 0.58f, 0.86f);
63+
colors[ImGuiCol_TabHovered] = ImVec4(0.20f, 0.68f, 0.42f, 0.83f);
64+
colors[ImGuiCol_TabActive] = ImVec4(0.20f, 0.68f, 0.42f, 1.00f);
65+
colors[ImGuiCol_TabUnfocused] = ImVec4(0.14f, 0.41f, 0.42f, 0.46f);
66+
colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.14f, 0.41f, 0.42f, 1.00f);
67+
colors[ImGuiCol_DockingPreview] = ImVec4(0.00f, 1.00f, 0.21f, 0.70f);
68+
colors[ImGuiCol_DockingEmptyBg] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f);
69+
colors[ImGuiCol_PlotLines] = ImVec4(0.40f, 0.39f, 0.38f, 0.63f);
70+
colors[ImGuiCol_PlotLinesHovered] = ImVec4(0.25f, 1.00f, 0.00f, 1.00f);
71+
colors[ImGuiCol_PlotHistogram] = ImVec4(0.40f, 0.39f, 0.38f, 0.63f);
72+
colors[ImGuiCol_PlotHistogramHovered] = ImVec4(0.25f, 1.00f, 0.00f, 1.00f);
73+
colors[ImGuiCol_TableHeaderBg] = ImVec4(0.19f, 0.19f, 0.20f, 1.00f);
74+
colors[ImGuiCol_TableBorderStrong] = ImVec4(0.31f, 0.31f, 0.35f, 1.00f);
75+
colors[ImGuiCol_TableBorderLight] = ImVec4(0.23f, 0.23f, 0.25f, 1.00f);
76+
colors[ImGuiCol_TableRowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
77+
colors[ImGuiCol_TableRowBgAlt] = ImVec4(1.00f, 1.00f, 1.00f, 0.06f);
78+
colors[ImGuiCol_TextSelectedBg] = ImVec4(0.25f, 1.00f, 0.00f, 0.48f);
79+
colors[ImGuiCol_DragDropTarget] = ImVec4(1.00f, 1.00f, 0.00f, 0.90f);
80+
colors[ImGuiCol_NavHighlight] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
81+
colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.00f, 1.00f, 1.00f, 0.70f);
82+
colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.20f);
83+
colors[ImGuiCol_ModalWindowDimBg] = ImVec4(1.00f, 0.98f, 0.95f, 0.73f);
84+
}
85+
86+
String getName() const override
87+
{
88+
return "Dark";
89+
}
90+
};

editor/themes/theme.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#pragma once
2+
3+
#include "common/types.h"
4+
5+
struct Theme {
6+
public:
7+
virtual void apply() const = 0;
8+
virtual String getName() const = 0;
9+
virtual ~Theme() = default;
10+
};

imgui.ini

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
[Window][Rootex Editor]
22
Pos=0,0
3-
Size=1920,991
3+
Size=1920,1009
44
Collapsed=0
55

66
[Window][Output]
7-
Pos=0,620
8-
Size=1114,371
7+
Pos=0,631
8+
Size=1114,378
99
Collapsed=0
1010
DockId=0x00000003,0
1111

@@ -33,19 +33,19 @@ Collapsed=0
3333
DockId=0x0000000D,0
3434

3535
[Window][Toolbar]
36-
Pos=1116,620
37-
Size=333,371
36+
Pos=1116,631
37+
Size=333,378
3838
Collapsed=0
3939
DockId=0x00000004,0
4040

4141
[Window][Viewport]
4242
Pos=0,28
43-
Size=1449,590
43+
Size=1449,601
4444
Collapsed=0
4545
DockId=0x00000008,0
4646

4747
[Window][Inspector]
48-
Pos=1451,409
48+
Pos=1451,427
4949
Size=469,582
5050
Collapsed=0
5151
DockId=0x00000009,0
@@ -155,7 +155,7 @@ Collapsed=0
155155

156156
[Window][Scene]
157157
Pos=1451,28
158-
Size=469,379
158+
Size=469,397
159159
Collapsed=0
160160
DockId=0x00000007,0
161161

@@ -191,7 +191,7 @@ Collapsed=0
191191

192192
[Window][File Editor]
193193
Pos=0,28
194-
Size=1449,590
194+
Size=1449,601
195195
Collapsed=0
196196
DockId=0x00000008,1
197197

@@ -201,13 +201,13 @@ Size=241,158
201201
Collapsed=0
202202

203203
[Window][Content Browser]
204-
Pos=0,620
205-
Size=1114,371
204+
Pos=0,631
205+
Size=1114,378
206206
Collapsed=0
207207
DockId=0x00000003,1
208208

209209
[Docking][Data]
210-
DockSpace ID=0x654E7FDC Window=0xDC8952A0 Pos=0,28 Size=1920,963 Split=X
210+
DockSpace ID=0x654E7FDC Window=0xDC8952A0 Pos=0,28 Size=1920,981 Split=X
211211
DockNode ID=0x00000001 Parent=0x654E7FDC SizeRef=1932,1359 Split=Y Selected=0x995B0CF8
212212
DockNode ID=0x00000008 Parent=0x00000001 SizeRef=1932,596 Selected=0x995B0CF8
213213
DockNode ID=0x0000000A Parent=0x00000001 SizeRef=1932,375 Split=X Selected=0xCB7211A8

0 commit comments

Comments
 (0)