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:
* data = UImGui_TextUtilsData_allocate();
UImGui_CTextUtilsData... // Create fonts
(data, bold, italic, boldItalic, monospace, smallFont);
UImGui_TextUtilsData_setFonts(data);
UImGui_TextUtils_initTextUtilsData
... // Render
// Free the data
(data); UImGui_TextUtilsData_free
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_Colour colour, const char* fmt, ...);
UImGui_TextUtils_WidgetState UImGui_TextUtils_Underline_fmt// Format variant with list
(UImGui_TextUtils_Colour colour, const char* fmt, va_list args);
UImGui_TextUtils_WidgetState UImGui_TextUtils_Underline_fmtV(const char* text, const char* end, UImGui_TextUtils_Colour colour); UImGui_TextUtils_WidgetState UImGui_TextUtils_UnderlineWrapped
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:
UImGui::TextUtils::WidgetState
->UImGui_TextUtils_WidgetState
UImGui::TextUtils::Colour
->UImGui_TextUtils_Colour
The following types are C-only:
UImGui_TextUtils_LinkCallback
the function that's called when a link is clickedUImGui_CTextUtilsData
a C handle to aUImGui::TextUtilsData
object.