You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wanted to share current solution to use ImGui as a C++20/23 module. I replaced almost all header files in my projects with modules (besides std and opencv). Its clean you know - not sure that justifies the pain of migrating but here I am ...
Attached 2 files (just remove the *.txt) can be used as replacement to #include "imgui.h", imgui_internal.h and imgui_stdlib.h.
As this started as an experiment, I manually listed all structs, functions and enums (with their values). To make this future proven, at some point I ll either make a python script or use some clang feature to automate this process.
ImGui_base.ixx
This file exports all objects of aforementioned headers - excluding their macros.
ImGui.ixx
Exposes ImGui_base.ixx and redefines (some) macros as constexpr or normal functions.
Lessons learned
import <imgui.h> -> fail (for my toolchain importing headers doesn't work anyway)
add imgui_....h to precompiled headers -> fail
just export all from imgui.h in a module -> fail. All items to be exported need to be listed (including values of unscoped enums)
these modules only expose all objects via using ::something; or using ::ImGui::something;, so automating this task later on should be straight forward
because macros don't leak from modules, I had to redefine them as functions - fortunately this only affects a few
as we don't redefine objects (excl macros), mixing imgui headers together with this module seems to works fine, and the following compiles:
module;
//<< those headers you don't need anymore, but if you forget to exclude them, your module should still compile
#include "imgui.h"
#include "imgui_internal.h"
#include "imgui_stdlib.h"
//>>
export module something;
import ImGui;
export
namespace something
{
...
}
This issue is more a showcase than a request to change anything. At a later stage maybe Ill create a PR/Fork if someone is interested.
Just one question for the dear reader: imgui_internal.h incudes some math functions, like ImPow that are declared static, see static inline float ImPow(float x, float y) { return powf(x, y); }
Is there any good reason for them be static? These ones I also had to redefine in the ImGui.ixx module.
Screenshots/Video:
No response
Minimal, Complete and Verifiable Example code:
// this is just an example of how I import ImGui as a c++ moduleexport module something;
import ImGui; // <- this module exposes most items from imgui.h, imgui_internal.h and imgui_stdlib.hexportnamespacesomething
{
ImVec2 myFunc()
{
returnImGui::something();
}
}
The text was updated successfully, but these errors were encountered:
Version/Branch of Dear ImGui:
v1.91.8 WIP / docking
Back-ends:
imgui_impl_win32.cpp + imgui_impl_dx11.cpp
Compiler, OS:
MSVC 2022 C++latest
Full config/build information:
Details:
import ImGui;
I wanted to share current solution to use ImGui as a C++20/23 module. I replaced almost all header files in my projects with modules (besides std and opencv). Its clean you know - not sure that justifies the pain of migrating but here I am ...
Attached 2 files (just remove the *.txt) can be used as replacement to #include "imgui.h", imgui_internal.h and imgui_stdlib.h.
ImGui.ixx.txt
ImGui_base.ixx.txt
As this started as an experiment, I manually listed all structs, functions and enums (with their values). To make this future proven, at some point I ll either make a python script or use some clang feature to automate this process.
ImGui_base.ixx
This file exports all objects of aforementioned headers - excluding their macros.
ImGui.ixx
Exposes ImGui_base.ixx and redefines (some) macros as constexpr or normal functions.
Lessons learned
using ::something;
orusing ::ImGui::something;
, so automating this task later on should be straight forwardThis issue is more a showcase than a request to change anything. At a later stage maybe Ill create a PR/Fork if someone is interested.
Just one question for the dear reader: imgui_internal.h incudes some math functions, like ImPow that are declared static, see
static inline float ImPow(float x, float y) { return powf(x, y); }
Is there any good reason for them be static? These ones I also had to redefine in the ImGui.ixx module.
Screenshots/Video:
No response
Minimal, Complete and Verifiable Example code:
The text was updated successfully, but these errors were encountered: