To use the dear imgui console widget, do the following:

  1. Define the ULOG_IMGUI macro
  2. Make sure that imgui.h is in your include path
  3. Include the ULogImGui.hpp or C/CULogImGui.h headers

C++ API

To use the console widget, create an instance of the ULog::ImGuiConsole class. It looks like this:

class ImGuiConsole
{
public:
    void displayFull(bool& bOpen, bool* bInteractingWithTextbox) const noexcept;
    void display(bool* bInteractingWithTextbox) const noexcept;

    static void addToMessageLog(const std::string& msg, LogType type) noexcept;
    static void addCommand(const CommandType& cmd) noexcept;

    void setLogColour(ImVec4 colour, LogType type) noexcept;
};

Display functions

There are 2 functions which can be used to render the widget:

  1. display - renders the widget inline. Takes an optional boolean, that if not set to nullptr, can be used to check if the user is currently interacting with a text box
  2. displayFull - renders the widget inside a dear imgui window. Takes a boolean reference for checking, whether the window is open, and an optional boolean, that if not set to nullptr, can be used to check if the user is currently interacting with a text box

Messages and commands

The remaining functions deal with adding custom commands and controlling the formatting of messages:

  1. addToMessageLog - Adds a coloured message without the formatting thats prepended to all messages
  2. addCommand - Adds a custom console command
  3. setLogColour - Changes the colour for a log type

The addCommand function takes an instance of CommandType, which looks like this:

struct CommandType
{
    std::string cmd; // name of the command
    std::string cmdHint; // command description when one uses the `help` command
    std::function<void(const std::string&)> func; // A callback that gets called when the command is called
};

C API

The C API looks like this:

ULog_CImGuiConsole ULog_ImGuiConsole_init();
void ULog_ImGuiConsole_displayFull(ULog_CImGuiConsole* self, bool* bOpen, bool* bInteractingWithTextbox);
void ULog_ImGuiConsole_display(ULog_CImGuiConsole* self, bool* bInteractingWithTextbox);

void ULog_addMessageToLow(const char* message, ULog_LogType type);
void ULog_addCommand(const char* cmd, const char* cmdHint, ULog_ImGuiConsole_CommandFunc func);

void ULog_setLogColour(ULog_CImGuiConsole* self, ULog_Vec4 colour, ULog_LogType type);

As you can see the functions are the same, except that they take a reference to ULog_CImGuiConsole. To get an instance of it, call ULog_ImGuiConsole_init.

Another difference is that, addCommand uses the members of CommandType directly as function arguments, instead of using a ported version of the CommandType struct.