CARVIEW |
Navigation Menu
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Markup functions
The following functions allow you to do text markup.
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.
There are 4 functions that can be used to underline text:
-
Underline(Colour colour)
- this underlines the element above -
template<typename ...Args> WidgetState Underline(const char* fmt, Colour colour, Args... args)
- this is a wrapper on top ofImGui::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 toImGui::Text
's variadic list -
UnderlineWrapped(const char* text, const char* end, Colour 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. -
UnderlineWrapped(const std::string& text, Colour)
- An abstraction of the function above, usingstd::string
instead of pointers to the beginning and end of the string
The Colour
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. The Colour
type is the same as an ImU32
.
All functions, except the first one, return a WidgetState
enum representing their state.
There are 4 functions that can be used to render strikethrough text:
-
Strikethrough(Colour colour)
- this applies a strikethrough line to the element above -
template<typename ...Args> WidgetState Strikethrough(const char* fmt, Colour colour, Args... args)
- this is a wrapper on top ofImGui::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 toImGui::Text
's variadic list. -
StrikethroughWrapped(const char* text, const char* end, Colour 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. -
StrikethroughWrapped(const std::string& text, Colour)
- An abstraction of the function above, usingstd::string
instead of pointers to the beginning and end of the string
The Colour
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.
There are 4 functions that can be used to render highlighted text:
-
Highlight(Colour colour)
- this applies highlights the element above -
template<typename ...Args> WidgetState Highlight(const char* fmt, Colour colour, Args... args)
- this is a wrapper on top ofImGui::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 toImGui::Text
's variadic list. -
HighlightWrapped(const char* text, const char* end, Colour 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. -
HighlightWrapped(const std::string& text, Colour)
- An abstraction of the function above, usingstd::string
instead of pointers to the beginning and end of the string
The Colour
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:
-
Link(const char* text, Colour colour, const std::function<void(const char* link)>& clicked)
- Renders a link without word wrapping -
LinkWrapped(const char* text, const char* end, Colour colour, const std::function<void(const char* link)>& clicked)
- Renders a link with word wrapping -
LinkWrapped(const std::string& text, Colour colour, const std::function<void(const char* link)>& clicked)
- An abstraction on top of the above function to usestd::string
instead of providingbegin
andend
pointers.
The Colour
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.
There are 4 functions which can be used to render inline code:
-
CodeInline(const char* begin, const char* end, Colour backgroundColour)
- Renders inline code given pointers to the beginning and end of the string -
CodeInline(const std::string& text, Colour backgroundColour)
- Abstraction on top of the above function usingstd::string
, instead of pointers to the beginning and end of the string - 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.
There are 2 functions which can be used to render code blocks:
-
CodeBlock(const char* begin, const char* end, bool bWrapText, Colour backgroundColour)
- Renders a code block given a pointer to the beginning and end of the string -
CodeBlock(const std::string& text, bool bWrapText, Colour backgroundColour)
- Abstraction on top of the function above, usingstd::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)
.
An example of normal, underlined, highlighted, strikethrough and inline code text, as well as links and code blocks with word wrapping enabled:

This project is supported by all the people who joined our discord server and became beta testers. If you want to join the discord, you can click here.