Here, we will document important internal classes.
Core/Defines.hpp
The Defines.hpp
header contains the following
definitions:
- Defines the
std_filesystem
macro, to make working with older compilers that supportstd::filesystem
as part ofstd::experimental::filesystem
possible - Defines the
IMGUI_START
macro that is called as the first thing in the entry point. - Defines the
CAST
macro that does astatic_cast
to go around some linter warnings. - Defines the
FCAST
macro that does a C-style cast to go around some linter and compiler warning. TheF
stands for "force". - Creates C++ type definitions for
ComponentType
andComponentState
.
The C alternative, CDefines.h
, defines the
following:
- Defines
__declspec(dllimport)
/__declspec(dllexport)
when compiling for Windows - The
UNUSED
macro that can be used to removeUNUSED
warnings for functions whose return types are marked as[[nodiscard]]
- The
CARRAY_SIZE
macro that returns the size of a static C-style array - The C implementation of
UImGui_ComponentType
andUImGui_ComponentState
.
It also defines the following strings that can be used to set the semantic type of window in X11(more info on the Window Interface page). They look like this:
#define X11_WINDOW_TYPE_DESKTOP "_NET_WM_WINDOW_TYPE_DESKTOP"
#define X11_WINDOW_TYPE_DOCK "_NET_WM_WINDOW_TYPE_DOCK"
#define X11_WINDOW_TYPE_TOOLBAR "_NET_WM_WINDOW_TYPE_TOOLBAR"
#define X11_WINDOW_TYPE_MENU "_NET_WM_WINDOW_TYPE_MENU"
#define X11_WINDOW_TYPE_UTILITY "_NET_WM_WINDOW_TYPE_UTILITY"
#define X11_WINDOW_TYPE_SPLASH "_NET_WM_WINDOW_TYPE_SPLASH"
#define X11_WINDOW_TYPE_DIALOG "_NET_WM_WINDOW_TYPE_DIALOG"
#define X11_WINDOW_TYPE_NORMAL "_NET_WM_WINDOW_TYPE_NORMAL"
Core/Global
This class defines the Global
class, which stores global
data used internally. It has the following members:
- Pointer to the current
Instance
- Pointer to the current
RendererInternal
class, which represents the renderer - A single instance of
WindowInternal
- A single instance of
ModulesManager
- A single instance of the
CDeallocationStruct
- More information here
It also has the init
member function, which is
equivalent to the Begin
event listed on the Internal
Event Safety page.
Core/Types.hpp
It defines the following types:
// Redefine for C++
typedef UImGui_FVector2 FVector2;
typedef UImGui_FVector FVector;
typedef UImGui_FVector4 FVector4;
typedef UImGui_String String;
typedef std::string FString;
::Emitter& operator<<(YAML::Emitter& out, const FVector4& vect) noexcept;
YAML::Emitter& operator<<(YAML::Emitter& out, const FVector& vect) noexcept;
YAML::Emitter& operator<<(YAML::Emitter& out, const FVector2& vect) noexcept; YAML
and also calls using namespace UVKLog;
to remove the
UVKLog
namespace when logging.
The above type definitions are imported from the C API at
CTypes.h
, which looks like this:
struct UIMGUI_PUBLIC_API UImGui_FVector2_I
{
float x;
float y;
};
struct UIMGUI_PUBLIC_API UImGui_FVector_I
{
float x;
float y;
float z;
};
struct UIMGUI_PUBLIC_API UImGui_FVector4_I
{
float x;
float y;
float z;
float w;
};
typedef const char* UImGui_String;
typedef struct UImGui_FVector2_I UImGui_FVector2;
typedef struct UImGui_FVector_I UImGui_FVector;
typedef struct UImGui_FVector4_I UImGui_FVector4;
The 3 operator<<
overrides allow our vector types
to easily be output to YAML. Additionally, the following class
definitions allow us to easily load YAML into those types:
namespace YAML
{
template<>
struct convert<UImGui::FVector4>
{
static Node encode(const UImGui::FVector4& rhs) noexcept
{
;
Node node.push_back(rhs.x);
node.push_back(rhs.y);
node.push_back(rhs.z);
node.push_back(rhs.w);
node.SetStyle(EmitterStyle::Flow);
nodereturn node;
}
static bool decode(const Node& node, UImGui::FVector4& rhs) noexcept
{
if (!node.IsSequence() || node.size() != 4)
return false;
.x = node[0].as<float>();
rhs.y = node[1].as<float>();
rhs.z = node[2].as<float>();
rhs.w = node[3].as<float>();
rhsreturn true;
}
};
template<>
struct convert<UImGui::FVector>
{
static Node encode(const UImGui::FVector& rhs) noexcept
{
;
Node node.push_back(rhs.x);
node.push_back(rhs.y);
node.push_back(rhs.z);
node.SetStyle(EmitterStyle::Flow);
nodereturn node;
}
static bool decode(const Node& node, UImGui::FVector& rhs) noexcept
{
if (!node.IsSequence() || node.size() != 3)
return false;
.x = node[0].as<float>();
rhs.y = node[1].as<float>();
rhs.z = node[2].as<float>();
rhsreturn true;
}
};
template<>
struct convert<UImGui::FVector2>
{
static Node encode(const UImGui::FVector2& rhs) noexcept
{
;
Node node.push_back(rhs.x);
node.push_back(rhs.y);
node.SetStyle(EmitterStyle::Flow);
nodereturn node;
}
static bool decode(const Node& node, UImGui::FVector2& rhs) noexcept
{
if (!node.IsSequence() || node.size() != 2)
return false;
.x = node[0].as<float>();
rhs.y = node[1].as<float>();
rhsreturn true;
}
};
}
Core/CDeallocation.hpp
This file contains a struct that stores some intermediate data for the C API. The max memory complexity is estimated at somewhere below 100% more memory. THe struct currently looks like this:
struct UIMGUI_PUBLIC_API CDeallocationStruct
{
std::vector<FString> keyStrings; // Stores temporary strings
std::vector<UImGui_CMonitorData> monitors; // Stores temporary C monitor structs
};
Modules/Manager/ModulesManager
This file defines the internal ModulesManager
class, the
Modules
interface and the ModuleSettings
struct.
The ModulesManager
class manages module settings, which
module is enabled at runtime and at compile time, and managing the
modules' lifetime.
It looks like this:
class ModulesManager
{
private:
;
ModuleSettings settings#ifdef UIMGUI_LOCALE_MODULE_ENABLED
{};
LocaleManager localeManager#endif
#ifdef UIMGUI_UNDO_MODULE_ENABLED
{};
StateTracker stateTracker#endif
void init(const FString& configDir);
void initModules(const FString& projectDir);
void save(const FString& configDir) const noexcept;
};
Reference:
init
- Loads module settingsinitModules
- Initializes modules with the settingssave
- saves settings toModules.yaml
Renderer/GenericRenderer
The GenericRenderer
folder implements generic base
classes that our different renderer abstractions implement. It currently
contains the following:
GenericRenderer
- Implements interfaces for interfacing with both the graphics API, and with the rendering layer of dear imguiGenericTexture
- Implements a generic texture interface
The GenericRenderer
class
The GenericRenderer
class looks like this:
class GenericInternalRenderer
{
public:
() noexcept = default;
GenericInternalRenderer
virtual void init(RendererInternal& renderer) noexcept = 0;
virtual void renderStart(double deltaTime) noexcept = 0;
virtual void renderEnd(double deltaTime) noexcept = 0;
virtual void destroy() noexcept = 0;
virtual void ImGuiNewFrame() noexcept = 0;
virtual void ImGuiShutdown() noexcept = 0;
virtual void ImGuiInit() noexcept = 0;
virtual void ImGuiRenderData() noexcept = 0;
virtual void waitOnGPU() noexcept = 0; // This is only used for Vulkan, because there we have to wait on everything to render before freeing resources
virtual ~GenericInternalRenderer() noexcept = default;
};
The GenericTexture
class
The GenericTexture
class looks like this:
class GenericTexture
{
public:
() noexcept = default;
GenericTexture
virtual void init(String location, bool bFiltered) noexcept = 0;
virtual void* get() noexcept = 0;
virtual void load(void* data, FVector2 size, uint32_t depth, bool bFreeImageData,
const std::function<void(void*)>& freeFunc) noexcept = 0;
template<TextureFormat format>
bool saveToFile(const String location, const TextureFormat fmt = format, const uint8_t jpegQuality = 100) noexcept;
// Set a function for saving custom image file formats
// Event Safety - All initiated
void setCustomSaveFunction(CustomSaveFunction f) noexcept;
// Returns the size of the image
// Event Safety - Any time
[[nodiscard]] const FVector2& size() const noexcept;
// Cleans up the image data
// Event Safety - All initiated
virtual void clear() noexcept = 0;
virtual ~GenericTexture() noexcept = default;
protected:
void beginLoad(void** data, FVector2& size) noexcept;
void endLoad(void* data, FVector2 size, bool bFreeImageData, const std::function<void(void*)>& freeFunc) noexcept;
void defaultInit(String location) noexcept;
void defaultClear() noexcept;
{};
TextureData dt};
The functions under the protected
visibility label are
utility common functions that are used by child classes to reduce code
duplication.
Renderer/Renderer
The internal Renderer
class looks like this:
class UIMGUI_PUBLIC_API RendererInternal
{
public:
void start() noexcept;
void stop() noexcept;
private:
;
FString vendorString;
FString apiVersion;
FString driverVersion;
FString gpuName
void loadConfig();
void saveConfig() const noexcept;
{};
RendererData data};
Reference:
start
- Initializes and starts the rendererstop
- Destroys the renderer and deallocates all renderer data- The 4 strings - GPU information that can be fetched using the renderer interface
loadConfig
- Loads the renderer config file,Renderer.yaml
saveConfig
- Saves the renderer data stored in thedata
field toRenderer.yaml
Renderer/ImGui/ImGui
The GUIRenderer
class contains internal functions that
set up dear imgui through the different stages of the render loop. It
looks like this:
class GUIRenderer
{
public:
static void init(GLFWwindow* glfwwindow, const FString& ini);
static void beginUI(float deltaTime);
static void beginFrame();
static void shutdown(const FString& ini);
};
Reference:
init
- Creates an imgui context, sets up themes and style, calls thebegin
events of the components and the instancebeginUI
- Called at the beginning of every render loop iterationbeginFrame
- Starts a new imgui frameshutdown
- Cleans up imgui resources + save the layout to the specified location in theWindow.yaml
config file
Renderer/Window
Internal monitor C and C++ API bridge
The Monitor
class contains the
CInternalGetMonitorClassDoNotTouch
member class, which
looks like this:
class CInternalGetMonitorClassDoNotTouch
{
public:
static UImGui_CMonitorData UImGui_Window_getWindowMonitor();
static void pushGlobalMonitorCallbackFun(UImGui::Monitor& monitor, UImGui::MonitorState state,
);
UImGui_Window_pushGlobalMonitorCallbackFun fstatic void UImGui_Monitor_pushEvent(UImGui_CMonitorData* data, UImGui_Monitor_EventsFun f);
static void UImGui_Monitor_setWindowMonitor(UImGui_CMonitorData* monitor);
static UImGui_CMonitorData* UImGui_Window_getMonitors(size_t* size);
};
It is here, mostly because of our header file design, which prevents
us from using friend functions for accessing the private
GLFWmonitor*
. This class exists to store these functions,
which will have access to the private GLFWmonitor*
. These
will then be called from the implementation of the C API functions.
Internal window
The internal Window
class looks like this:
class WindowInternal
{
public:
[[nodiscard]] GLFWwindow* data() const noexcept;
bool& resized() noexcept;
void close() noexcept;
// For consumption by the C API
std::vector<std::function<void(const char**, size_t size)>> dragDropPathCCallbackList;
private:
void updateKeyState() noexcept;
= { 800.0f, 600.0f };
FVector2 windowSize ;
FVector2 windowSizeInScreenCoords
std::array<uint16_t, 350> keys{};
std::vector<InputAction> inputActionList{};
void saveConfig(bool bSaveKeybindings) noexcept;
void openConfig();
void setTitle(String title) noexcept;
void setIcon(String name) noexcept;
() noexcept;
FVector2 getMousePositionChange() noexcept;
FVector2 getScroll
void createWindow() noexcept;
void destroyWindow() noexcept;
void configureCallbacks() noexcept;
static void framebufferSizeCallback(GLFWwindow* window, int width, int height) noexcept;
static void keyboardInputCallback(GLFWwindow* window, int key, int scanCode, int action, int mods) noexcept;
static void mouseKeyInputCallback(GLFWwindow* window, int button, int action, int mods) noexcept;
static void mouseCursorPositionCallback(GLFWwindow* window, double xpos, double ypos) noexcept;
static void scrollInputCallback(GLFWwindow* window, double xoffset, double yoffset) noexcept;
static void windowPositionCallback(GLFWwindow* window, int xpos, int ypos) noexcept;
static void windowSizeCallback(GLFWwindow* window, int width, int height) noexcept;
static void windowCloseCallback(GLFWwindow* window) noexcept;
static void windowFocusCallback(GLFWwindow* window, int focused) noexcept;
static void windowIconifyCallback(GLFWwindow* window, int iconified) noexcept;
static void windowContentScaleCallback(GLFWwindow* window, float x, float y) noexcept;
static void windowRefreshCallback(GLFWwindow* window) noexcept;
static void windowMaximisedCallback(GLFWwindow* window, int maximised) noexcept;
static void monitorCallback(GLFWmonitor* monitor, int event) noexcept;
static void windowOSDragDropCallback(GLFWwindow* window, int count, const char** paths) noexcept;
static void windowErrorCallback(int code, const char* description) noexcept;
void setWindowAlwaysOnTop() noexcept;
void setWindowAlwaysBelow() noexcept;
void disableWindowMoving() noexcept;
void setShowWindowInPager(bool bShowInPagerr) noexcept;
void setShowWindowOnTaskbar(bool bShowOnTaskbarr) noexcept;
void setWindowType(const char* type) noexcept;
size_t getWindowID() noexcept;
bool bShowOnPager = true;
bool bShowOnTaskbar = true;
std::vector<std::function<void(int, int)>> windowResizeCallbackList;
std::vector<std::function<void(int, int)>> windowResizeInScreenCoordCallbackList;
std::vector<std::function<void(void)>> windowCloseCallbackList;
std::vector<std::function<void(bool)>> windowFocusCallbackList;
std::vector<std::function<void(bool)>> windowIconifiedCallbackList;
std::vector<std::function<void(FVector2)>> windowPositionChangeCallbackList;
std::vector<std::function<void(FVector2)>> windowContentScaleChangeCallbackList;
std::vector<std::function<void(void)>> windowRefreshCallbackList;
std::vector<std::function<void(bool)>> windowMaximisedCallbackList;
std::vector<std::function<void(Monitor&, MonitorState)>> windowMonitorCallbackList;
std::vector<std::function<void(std::vector<FString>&)>> dragDropPathCallbackList;
std::vector<std::function<void(int, const char*)>> windowErrorCallbackList;
std::vector<FString> dragDropPaths;
std::vector<Monitor> monitors;
* windowMain = nullptr;
GLFWwindow;
WindowData windowData
bool bFirstMove = true;
bool bResized = false;
= { 0.0f, 0.0f };
FVector2 mousePos = { 0.0f, 0.0f };
FVector2 mouseLastPos = { 0.0f, 0.0f };
FVector2 mouseOffset
;
FVector2 scroll
= { 0.0f, 0.0f };
FVector2 windowLastPos = { 0.0f, 0.0f };
FVector2 windowCurrentPos };
Functions:
data
- Returns the internal GLFW window contextresized
- Resized a boolean reference to check if the window was resizedclose
- Close the windowupdateKeyState
- Updates the state ofInputAction
s after all keys' state is known, i.e. afterglfwPollEvents
saveConfig
- Saves window settingsopenConfig
- Loads window settingssetTitle
- Sets the title of the windowsetIcon
- Sets the window icongetMousePositionChange
- Returns the difference between the last and current mouse positiongetScroll
- Returns the current scroll value as aFVector2
createWindow
,destroyWindow
- Creates/destroys the window contextconfigureCallbacks
- Sets up the callbackssetWindowAlwaysOnTop
- Backend version of the same function in theWindow
interface. Makes the window appear as the top most window.setWindowAlwaysBelow
- Backend version of the same function in theWindow
interface. Makes the window appear as the root or bottom-most window.disableWindowMoving
- Backend version of the same function in theWindow
interface. Completely disable movement of the window by the usersetShowWindowInPager
- Backend version of the same function in theWindow
interface. Toggles display of the window in the pagersetShowWindowOnTaskbar
- Backend version of the same function in theWindow
interface. Toggles display of the window in the taskbarsetWindowType
- Backend version of the same function in theWindow
interface. Given a C string, sets the given X11 semantic window type as defined by the X11 documentation.getWindowID
- Backend version of the same function in theWindow
interface. Returns the ID of the current Window.- The rest - Callbacks for window events.
Variables:
windowSize
- The size of the window as aFVector2
windowSizeInScreenCoords
- The size of the window in screen coordinates as anFVector2
keys
- An array of events on a given key codeinputActionList
- The internal list of input actionsdragDropPaths
- A list of all paths that were acquired by the window on OS file drag and drop into itbShowOnPager
- The internal bool that is used to check whether the window is shown on the pagerbShowOnTaskbar
- The internal bool that is used to check whether the window is shown on the taskbarmonitors
- The internal monitors arraywindowMain
- The internal GLFW window contextwindowData
- The internal instance of theWindowData
structbResized
- To check whether the window was resizedmousePos
,mouseLastPos
,mouseOffset
- Mouse positions asFVector2
scroll
- Current scroll valuewindowCurrentPos
,windowLastPos
- Window positions asFVector2
- The rest -
std::vector<std::function<void(T)>>
style variables which store the callbacks pushed by theWindow
interface bypushWindow*Callback
functions
- Home
- Beginner content
- Install guide
- Creating and using the UI components
- The Instance
- The Init Info struct
- Textures
- Logging
- Unicode support
- Additional features
- Client-side bar
- Custom type definitions
- Memory management
- C API development
- Config files and Folders
- Interfaces
- Internal Event safety
- Customising the build system
- Modules system
- Collaborating with others
- Advanced content
- Developer and contributor resources
- Misc