The C API is developed as an additional API on top of the existing C++ API. They don’t differ in many ways. This page lists common differences and dealing with them.
Namespaces and classes
Where a namespace or class name may appear, the C++ :: access operator is replaced by _, as C doesn’t have support
for namespaces and classes.
For example, UImGui::Window::Platform::setWindowAlwaysOnTop() will become
UImGui_Window_Platform_setWindowAlwaysOnTop() in the C API.
FVector, String and FString
The C API defines the UImGui_FVector2, UImGui_FVector and UImGui_FVector4 types. These types define geometrical
vectors of floats. The C++ API actually uses a typedef to FVector2, FVector and FVector4 from the C types,
under the UImGui namespace.
The FString type is not available in the C API, as templates are not a feature of C. Because of this, we’re forced
to only use UImGui_String for C string representations and char* for mutable character arrays. UImGui_String is
defined as String in the UImGui namespace when using the C++ API.
Classes/structs with member functions
Some classes/structs with member functions may have a custom data-only C adapter struct. This struct is then passed to the C alternatives of the same member functions to manipulate the data. Here is a C++ example:
struct doStuffWithMembers
{
size_t num1;
size_t num2;
void f();
void g();
};
This struct can then be converted to a C one like this:
struct doStuffWithMembersC
{
size_t num1;
size_t num2;
};
void doStuffWithMembersC_f(doStuffWithMembersC* data);
void doStuffWithMembersC_g(doStuffWithMembersC* data);
Now, using the struct in both the C++ and C way:
// C++
doStuffWithMembers cppStruct = { 0, 1 };
cppStruct.f();
cppStruct.g();
// C
doStuffWithMembersC cStruct = { 0, 1 };
doStuffWithMembersC_f(&cStruct);
doStuffWithMembersC_g(&cStruct);
This is a really common pattern used in places like the Texture and Monitor C APIs.
Dear imgui C API
The C API for dear imgui we use is based on dear_bindings. Differences in code formatting are listed here.
To use the dear imgui C API, include #include <cimgui/cimgui.h> in your code.
Caution
The C++ and C imgui APIs should NOT be included together, as that will cause hundreds of type redefinition compiler errors.
Dear imgui C modules API
Some dear imgui widget modules also have a C API. Refer to individual module pages for further instructions.