Skip to content

Commit 354ec0d

Browse files
committed
Update logging library, add the ability to set custom theme files and add the ability for applications to whether layouts are loaded/saved automatically
1 parent 23846eb commit 354ec0d

19 files changed

+208
-102
lines changed

Config/Core/Modules.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
undo-max-transactions: 100
1+
undo-max-transactions: 100
2+
theme-location: "default"

Config/Core/Window.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
layout-location: "DefaultLayout" # The location of the layout file ImGui writes to
2+
load-layout: true # Whether to load the layout file ImGui writes to
3+
save-layout: true # Whether to automatically save to the layout file ImGui writes to
24
icon: "example-icon.png" # The location of the window icon image
35
width: 800 # Width of the window in pixels
46
height: 600 # Height of the window in pixels
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include "CLayoutsInterface.h"
2+
#include <Interfaces/LayoutsInterface.hpp>
3+
4+
bool* UImGui_Layouts_getLoadLayout()
5+
{
6+
return &UImGui::Layouts::getLoadLayout();
7+
}
8+
9+
bool* UImGui_Layouts_getSaveLayout()
10+
{
11+
return &UImGui::Layouts::getSaveLayout();
12+
}
13+
14+
UImGui_String UImGui_Layouts_layoutLocation()
15+
{
16+
return UImGui::Layouts::layoutLocation().c_str();
17+
}
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#pragma once
2+
#include <C/CTypes.h>
3+
4+
#ifdef __cplusplus
5+
extern "C"
6+
{
7+
#endif
8+
// Event Safety - begin, style, post-begin
9+
UIMGUI_PUBLIC_API bool* UImGui_Layouts_getLoadLayout();
10+
// Event Safety - begin, style, post-begin
11+
UIMGUI_PUBLIC_API bool* UImGui_Layouts_getSaveLayout();
12+
// Event Safety - begin, style, post-begin
13+
UIMGUI_PUBLIC_API UImGui_String UImGui_Layouts_layoutLocation();
14+
#ifdef __cplusplus
15+
}
16+
#endif

Framework/C/Interfaces/CWindowInterface.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,6 @@ UImGui_String UImGui_Window_iconLocation()
6363
return UImGui::Window::iconLocation().c_str();
6464
}
6565

66-
UImGui_String UImGui_Window_layoutLocation()
67-
{
68-
return UImGui::Window::layoutLocation().c_str();
69-
}
70-
7166
void UImGui_Window_saveSettings(const bool bSaveKeybinds)
7267
{
7368
UImGui::Window::saveSettings(bSaveKeybinds);

Framework/C/Interfaces/CWindowInterface.h

-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ extern "C"
5151
UIMGUI_PUBLIC_API UImGui_String UImGui_Window_name();
5252
// Event Safety - begin, style, post-begin
5353
UIMGUI_PUBLIC_API UImGui_String UImGui_Window_iconLocation();
54-
// Event Safety - begin, style, post-begin
55-
UIMGUI_PUBLIC_API UImGui_String UImGui_Window_layoutLocation();
5654

5755
// Event Safety - begin, style, post-begin
5856
UIMGUI_PUBLIC_API void UImGui_Window_saveSettings(bool bSaveKeybinds);

Framework/C/Modules/Manager/CModulesManager.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@ extern "C"
99
/**
1010
* @brief Struct containing settings for all modules.
1111
* @var maxTransactions - Maximum number of undo/redo transactions before removing old transactions
12+
* @var themeLocation - The string location of the theme file to be loaded and saved to by the theming module. Path
13+
* is prefixed by UIMGUI_CONFIG_DIR/Theme/
1214
* @var os, dbus, uexec, theming, ufont, i18n, undo_redo, plotting, knobs, spinners, toggles, text_utils,
1315
* cli_parser, xdg, open - Boolean that marks whether the module with the given name is enabled
1416
*/
1517
typedef struct UIMGUI_PUBLIC_API UImGui_ModuleSettings
1618
{
1719
size_t maxTransactions;
20+
UImGui_String themeLocation;
1821

1922
bool os;
2023
bool dbus;
@@ -32,6 +35,7 @@ extern "C"
3235
bool xdg;
3336
bool open;
3437
} UImGui_ModuleSettings;
38+
3539
// Event safety - begin, style, post-begin
3640
UIMGUI_PUBLIC_API void UImGui_Modules_save();
3741
// Event safety - begin, style, post-begin
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include "LayoutsInterface.hpp"
2+
#include "WindowInterface.hpp"
3+
#include "imgui.h"
4+
5+
bool& UImGui::Layouts::getLoadLayout() noexcept
6+
{
7+
return Window::get().windowData.bLoadLayout;
8+
}
9+
10+
bool& UImGui::Layouts::getSaveLayout() noexcept
11+
{
12+
return Window::get().windowData.bSaveLayout;
13+
}
14+
15+
UImGui::FString& UImGui::Layouts::layoutLocation() noexcept
16+
{
17+
return Window::get().windowData.layoutLocation;
18+
}
19+
20+
void UImGui::Layouts::loadLayout(String layout) noexcept
21+
{
22+
ImGui::LoadIniSettingsFromDisk(layout);
23+
}
24+
25+
void UImGui::Layouts::saveLayout(String layout) noexcept
26+
{
27+
ImGui::SaveIniSettingsToDisk(layout);
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#pragma once
2+
#include <Core/Types.hpp>
3+
4+
namespace UImGui
5+
{
6+
class UIMGUI_PUBLIC_API Layouts
7+
{
8+
public:
9+
Layouts() noexcept = default;
10+
11+
// Event Safety - begin, style, post-begin
12+
static bool& getLoadLayout() noexcept;
13+
// Event Safety - begin, style, post-begin
14+
static bool& getSaveLayout() noexcept;
15+
// Event Safety - begin, style, post-begin
16+
static FString& layoutLocation() noexcept;
17+
18+
static void loadLayout(String layout) noexcept;
19+
static void saveLayout(String layout) noexcept;
20+
};
21+
}

Framework/Core/Interfaces/WindowInterface.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,6 @@ void UImGui::Window::setIcon(const String name) noexcept
7979
get().setIcon(name);
8080
}
8181

82-
UImGui::FString& UImGui::Window::layoutLocation() noexcept
83-
{
84-
return get().windowData.layoutLocation;
85-
}
86-
8782
void UImGui::Window::setCurrentWindowPosition(const FVector2 pos) noexcept
8883
{
8984
glfwSetWindowPos(get().windowMain, CAST(int, pos.x), CAST(int, pos.y));

Framework/Core/Interfaces/WindowInterface.hpp

-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ namespace UImGui
4242
static FString& name() noexcept;
4343
// Event Safety - begin, style, post-begin
4444
static FString& iconLocation() noexcept;
45-
// Event Safety - begin, style, post-begin
46-
static FString& layoutLocation() noexcept;
4745

4846
// Event Safety - begin, style, post-begin
4947
static void saveSettings(bool bSaveKeybinds) noexcept;

Framework/Modules/Manager/ModulesManager.cpp

+26-10
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
#define CHECK_MODULE_ENABLED(x) if (mod[#x]) \
1414
{ \
15-
Modules::data().x = mod[#x].as<bool>(); \
15+
settings.x = mod[#x].as<bool>(); \
1616
}
1717

1818
#include <Utilities.hpp>
@@ -107,27 +107,27 @@ void UImGui::ModulesManager::initModules(const FString& projectDir)
107107
CHECK_MODULE_ENABLED(cli_parser);
108108
CHECK_MODULE_ENABLED(xdg);
109109
CHECK_MODULE_ENABLED(open);
110-
110+
111111
// Fix up double forms
112112
if (mod["undo-redo"])
113-
Modules::data().undo_redo = mod["undo-redo"].as<bool>();
113+
settings.undo_redo = mod["undo-redo"].as<bool>();
114114
if (mod["text-utils"])
115-
Modules::data().text_utils = mod["text-utils"].as<bool>();
115+
settings.text_utils = mod["text-utils"].as<bool>();
116116
if (mod["cli-parser"])
117-
Modules::data().cli_parser = mod["cli-parser"].as<bool>();
117+
settings.cli_parser = mod["cli-parser"].as<bool>();
118118

119119
#ifdef UIMGUI_UNDO_MODULE_ENABLED
120-
if (Modules::data().undo_redo)
120+
if (settings.undo_redo)
121121
stateTracker.init();
122122
#endif
123123
#ifdef UIMGUI_I18N_MODULE_ENABLED
124-
if (Modules::data().i18n)
124+
if (settings.i18n)
125125
if (const auto result = translationEngine.init((Instance::get()->initInfo.configDir + "Translations").c_str()) != UI18N_INIT_RESULT_SUCCESS)
126126
Logger::log("I18N module: There was an issue with loading or processing the translations. Error code: ", ULOG_LOG_TYPE_WARNING, CAST(int, result));
127127
#endif
128128
#ifdef UIMGUI_OS_MODULE_ENABLED
129129
#ifdef UIMGUI_OPEN_SUBMODULE_ENABLED
130-
if (Modules::data().open)
130+
if (settings.open)
131131
UOpen::init();
132132
#endif
133133
#endif
@@ -145,11 +145,27 @@ void UImGui::ModulesManager::initModules(const FString& projectDir)
145145
#endif
146146
}
147147

148-
void UImGui::ModulesManager::destroy() noexcept
148+
void UImGui::ModulesManager::initialiseWithImGuiContext() const noexcept
149+
{
150+
#ifdef UIMGUI_PLOTTING_MODULE_ENABLED
151+
if (settings.plotting)
152+
ImPlot::CreateContext();
153+
#endif
154+
}
155+
156+
void UImGui::ModulesManager::applyCustomisations() const noexcept
157+
{
158+
#ifdef UIMGUI_THEME_MODULE_ENABLED
159+
if (settings.theming && (Modules::data().themeLocation != nullptr || Modules::data().themeLocation != ""))
160+
Theme::load((Instance::get()->initInfo.configDir + "Theme/" + Modules::data().themeLocation + ".theme.yaml").c_str());
161+
#endif
162+
}
163+
164+
void UImGui::ModulesManager::destroy() const noexcept
149165
{
150166
#ifdef UIMGUI_OS_MODULE_ENABLED
151167
#ifdef UIMGUI_OPEN_SUBMODULE_ENABLED
152-
if (Modules::data().open)
168+
if (settings.open)
153169
UOpen::destroy();
154170
#endif
155171
#endif

Framework/Modules/Manager/ModulesManager.hpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ namespace UImGui
6262
friend class Modules;
6363
friend class Global;
6464
friend class RendererInternal;
65+
friend class GUIRenderer;
6566

6667
friend class Locale;
6768
friend class LocaleManager;
@@ -71,6 +72,7 @@ namespace UImGui
7172
ModuleSettings settings =
7273
{
7374
.maxTransactions = 100,
75+
.themeLocation = "",
7476
.os = false,
7577
.dbus = false,
7678
.uexec = false,
@@ -97,7 +99,13 @@ namespace UImGui
9799

98100
void init(const FString& configDir);
99101
void initModules(const FString& projectDir);
100-
void destroy() noexcept;
102+
103+
// Runs directly after creating the dear imgui context
104+
void initialiseWithImGuiContext() const noexcept;
105+
// Runs after the dear imgui context is created, but after everything is set up to be used by the user
106+
void applyCustomisations() const noexcept;
107+
108+
void destroy() const noexcept;
101109

102110
void save(const FString& configDir) const noexcept;
103111
};

0 commit comments

Comments
 (0)