The following functions allow you to do text markup.

WidgetState

First, an introduction into the WidgetState enum is needed. The enum looks like this:

enum WidgetState
{
    UIMGUI_TEXT_UTILS_WIDGET_STATE_NONE = 0,
    UIMGUI_TEXT_UTILS_WIDGET_STATE_CLICKED = 1 << 0,
    UIMGUI_TEXT_UTILS_WIDGET_STATE_HOVERED = 1 << 1,
    UIMGUI_TEXT_UTILS_WIDGET_STATE_ALL = UIMGUI_TEXT_UTILS_WIDGET_STATE_CLICKED | UIMGUI_TEXT_UTILS_WIDGET_STATE_HOVERED,
};

Some widgets return this enum, when it is not possible to use the normal dear imgui IsItemHovered and IsMouseClicked functions. You can use bitwise operations to check whether a certain state is present.

Underlining text

There are 4 functions that can be used to underline text:

  1. Underline(ImColor colour) - this underlines the element above
  2. template<typename ...Args> WidgetState Underline(const char* fmt, ImColor colour, Args... args) - this is a wrapper on top of ImGui::Text. It uses the standard format string and the colour argument for the line. Additionally, it takes a templated variadic list of arguments that will be passed to ImGui::Text's variadic list
  3. UnderlineWrapped(const char* text, const char* end, ImColor colour) - Renders underlined text with wrapping. The last argument is the colour for the line, the first 2 are pointers to the beginning and end of the string, respectively.
  4. UnderlineWrapped(const std::string& text, ImColor) - An abstraction of the function above, using std::string instead of pointers to the beginning and end of the string

The ImColor argument in all these functions corresponds to the colour of the line, which is, by default, set to the UIMGUI_TEXT_COLOUR macro, which simply fetches the default text colour.

All functions, except the first one, return a WidgetState enum representing their state.

Strikethrough text

There are 4 functions that can be used to render strikethrough text:

  1. Strikethrough(ImColor colour) - this applies a strikethrough line to the element above
  2. template<typename ...Args> WidgetState Strikethrough(const char* fmt, ImColor colour, Args... args) - this is a wrapper on top of ImGui::Text. It uses the standard format string and the colour argument for the line. Additionally, it takes a templated variadic list of arguments that will be passed to ImGui::Text's variadic list.
  3. StrikethroughWrapped(const char* text, const char* end, ImColor colour) - Renders strikethrough text with wrapping. The last argument is the colour for the line, the first 2 are pointers to the beginning and end of the string, respectively.
  4. StrikethroughWrapped(const std::string& text, ImColor) - An abstraction of the function above, using std::string instead of pointers to the beginning and end of the string

The ImColor argument in all these functions corresponds to the colour of the line, which is, by default, set to the UIMGUI_TEXT_COLOUR macro, which simply fetches the default text colour.

All functions, except the first one, return a WidgetState enum representing their state.

Highlight

There are 4 functions that can be used to render highlighted text:

  1. Highlight(ImColor colour) - this applies highlights the element above
  2. template<typename ...Args> WidgetState Highlight(const char* fmt, ImColor colour, Args... args) - this is a wrapper on top of ImGui::Text. It uses the standard format string and the colour argument for the highlight. Additionally, it takes a templated variadic list of arguments that will be passed to ImGui::Text's variadic list.
  3. HighlightWrapped(const char* text, const char* end, ImColor colour) - Renders highlighted text with wrapping. The last argument is the colour for the highlight, the first 2 are pointers to the beginning and end of the string, respectively.
  4. HighlightWrapped(const std::string& text, ImColor) - An abstraction of the function above, using std::string instead of pointers to the beginning and end of the string

The ImColor argument in all these functions corresponds to the colour of the highlight, which is, by default, set to the UIMGUI_HIGHLIGHT_TEXT_COLOUR, which returns the following RGB colour: rgb(255, 255, 0, 64).

All functions, except the first one, return a WidgetState enum representing their state.

There are 3 functions that can be used to render links:

  1. Link(const char* text, ImColor colour, const std::function<void(const char* link)>& clicked) - Renders a link without word wrapping
  2. LinkWrapped(const char* text, const char* end, ImColor colour, const std::function<void(const char* link)>& clicked) - Renders a link with word wrapping
  3. LinkWrapped(const std::string& text, ImColor colour, const std::function<void(const char* link)>& clicked) - An abstraction on top of the above function to use std::string instead of providing begin and end pointers.

The ImColor argument in all these functions corresponds to the default unvisited colour used on most web browsers, which is, by default, set to the UIMGUI_LINK_TEXT_UNVISITED macro, which returns the following RGB colour: rgb(0, 0, 238, 255). Additionally, the UIMGUI_LINK_TEXT_VISITED macro is provided, for use when a link is visited. It returns the following RGB colour: rgb(85, 26, 139, 255)

The clicked function is the function that will be called when the link is clicked. It has a default argument that corresponds to the defaultLinkClickEvent member of the TextUtilsData struct, you have previously set. You can override it if needed.

Inline code

There are 4 functions which can be used to render inline code:

  1. CodeInline(const char* begin, const char* end, ImColor backgroundColour) - Renders inline code given pointers to the beginning and end of the string
  2. CodeInline(const std::string& text, ImColor backgroundColour) - Abstraction on top of the above function using std::string, instead of pointers to the beginning and end of the string
  3. The 2 CodeInlineWrapped functions are the same as the first 2 functions, but they render text with word wrapping enabled

Inline code is rendered with the monospaced font with a background which is provided by the backgroundColour argument. backgroundColour defaults to being set to the UIMGUI_BLOCKQUOTE_TEXT_COLOUR macro, which produces a colour with the following RGB: rgb(69, 71, 90, 255).

Inline code differs from CodeBlock as it does not fill the whole available space. Instead, the background colour is only applied to the extent of each line of text.

Code blocks

There are 2 functions which can be used to render code blocks:

  1. CodeBlock(const char* begin, const char* end, bool bWrapText, ImColor backgroundColour) - Renders a code block given a pointer to the beginning and end of the string
  2. CodeBlock(const std::string& text, bool bWrapText, ImColor backgroundColour) - Abstraction on top of the function above, using std::string instead of pointer to the beginning and end of the string

The bWrapText boolean toggles whether to apply word wrapping to the code block. The backgroundColour argument is the background colour of the code block. It defaults to being set to the UIMGUI_BLOCKQUOTE_TEXT_COLOUR macro, which produces a colour with the following RGB: rgb(69, 71, 90, 255).

Showcase

An example of normal, underlined, highlighted, strikethrough and inline code text, as well as links and code blocks with word wrapping enabled:

image