In order to use this library in different languages we offer a C API for most of the functions in the library.

Note

The C API does not require you to use cimgui or to have a C header file for dear imgui!

Using the C API

The C API is located under the C folder in the CUImGuiTextUtils.h. To set up fonts and initialise it with global data, use the following code:

UImGui_CTextUtilsData* data = UImGui_TextUtilsData_allocate();
... // Create fonts
UImGui_TextUtilsData_setFonts(data, bold, italic, boldItalic, monospace, smallFont);
UImGui_TextUtils_initTextUtilsData(data);

... // Render

// Free the data
UImGui_TextUtilsData_free(data);

Conventions

All functions and types are prefixed with their namespaces and containing classes separated by _. For example, the UImGui::TextUtils::Bold function becomes UImGui_TextUtils_Bold.

In C++, functions like UImGui::TextUtils::Underline have a variant that adds an underline to an existing component, as well as a variadic list one. The variadic list variants have _fmt added to the function name. Example:

void UImGui_TextUtils_Underline(UImGui_TextUtils_Colour colour);
// Format variant
UImGui_TextUtils_WidgetState UImGui_TextUtils_Underline_fmt(UImGui_TextUtils_Colour colour, const char* fmt, ...);
// Format variant with list
UImGui_TextUtils_WidgetState UImGui_TextUtils_Underline_fmtV(UImGui_TextUtils_Colour colour, const char* fmt, va_list args);
UImGui_TextUtils_WidgetState UImGui_TextUtils_UnderlineWrapped(const char* text, const char* end, UImGui_TextUtils_Colour colour);

Note

The colour argument to variadic functions is always the first one, due to limitations of the C language.

Tip

If you want to use the default text colour, pass the UIMGUI_C_TEXT_COLOUR macro.

C types

These are the C alternatives of the following C++ types:

  1. UImGui::TextUtils::WidgetState -> UImGui_TextUtils_WidgetState
  2. UImGui::TextUtils::Colour -> UImGui_TextUtils_Colour

The following types are C-only:

  1. UImGui_TextUtils_LinkCallback the function that's called when a link is clicked
  2. UImGui_CTextUtilsData a C handle to a UImGui::TextUtilsData object.