Installation

Installing UntitledImGuiTextUtils is easy. Simply put all code into your project's code and compile them into your binary statically.

Make sure to also have a relatively up-to-date dear imgui version, and that imgui.h is in the include path, so that it can be included in the following way:

#include <imgui.h>

Finally, to include the library, simply include UImguiTextUtils.h.

Configuration

Disabling C++ strings

By default, we have additional functions that use std::string for convenience. To disable C++ strings, define the UIMGUI_TEXT_UTILS_DISABLE_STRING macro.

Using custom C++ strings

If you want to replace std::string with another std::string-compatible C++ string, simply define the UIMGUI_TEXT_UTILS_CUSTOM_STRING macro and make sure it is equal to the type of the string. Then, define the UIMGUI_TEXT_UTILS_CUSTOM_STRING_INCLUDE macro, where its value should be a string pointing to the type's header to include.

Integrating into your project

At some point after dear imgui is initialised, make sure to configure your data. All data is stored in the UImGui::TextUtilsData struct, which looks like this:

struct IMGUI_API TextUtilsData
{
    ImFont* bold;
    ImFont* italic;
    ImFont* boldItalic;
    ImFont* monospace;
    ImFont* small;

    std::function<void(const char*)> defaultLinkClickEvent = [](const char*) -> void {};
};

The ImFont* variables are pointers to dear imgui fonts, these will be used by different functions to render with specific font styles, thus, make sure that valid fonts are provided.

The last variable is the default link click event. It gets called when the user clicks on a link.

Setting the data

To set the data, simply call UImGui::TextUtils::initTextUtilsData and pass a pointer to a TextUtilsData struct as an argument. You have to store the struct yourself, so make sure it is not deallocated, until no further calls to the library are made.

Example code:

void setData()
{
    auto& io = ImGui::GetIO();

    io.Fonts->AddFontDefault();
    static UImGui::TextUtilsData data =
    {
        .bold = io.Fonts->AddFontFromFileTTF(UIMGUI_CONTENT_DIR"NotoSans-Bold.ttf", 16.0f),
        .italic = io.Fonts->AddFontFromFileTTF(UIMGUI_CONTENT_DIR"NotoSans-Italic.ttf", 16.0f),
        .boldItalic = io.Fonts->AddFontFromFileTTF(UIMGUI_CONTENT_DIR"NotoSans-BoldItalic.ttf", 16.0f),
        .monospace = io.Fonts->AddFontFromFileTTF(UIMGUI_CONTENT_DIR"JetBrainsMono-Regular.ttf", 16.0f),
        .small = io.Fonts->AddFontFromFileTTF(UIMGUI_CONTENT_DIR"NotoSans-Light.ttf", 13.0f)
    };
    UImGui::TextUtils::initTextUtilsData(&data);
}

Testing out the library

In classic dear imgui fashion, we offer a demo window that showcases all features of the library. To use it, simply call UImGui::TextUtils::ShowDemoWindow.