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++
0, 1 };
doStuffWithMembers cppStruct = {
cppStruct.f();
cppStruct.g();
// C
0, 1 };
doStuffWithMembersC cStruct = {
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.
- Home
- Beginner content
- Install guide
- Creating and using the UI components
- The Instance
- The Init Info struct
- Additional features
- Custom type definitions
- C API development
- Config files and Folders
- Interfaces
- Internal Event safety
- Modules system
- I18N
- Plotting
- Knobs
- Spinners
- Toggles
- Text Utils
- Undo/Redo
- CLI Parser
- Theming
- OS
- Opening URLs and using file pickers
- Exec integration
- Fonts
- Unix
- DBus utilities
- XDG integration
- Collaborating with others
- Advanced content
- Loading dynamic libraries at runtime
- Understanding the library layout
- Compilation mode modifiers
- Adding plugin support to your application
- Production export and deployment
- Developer and contributor resources
- Misc