Skip to content

Commit

Permalink
Bypass unnecessary formatting when using the TextColored()/TextWrappe…
Browse files Browse the repository at this point in the history
…d()/TextDisabled() helpers with a "%s" format string. (#3466)
  • Loading branch information
ocornut committed Sep 16, 2020
1 parent d2939ce commit 645a6e0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
2 changes: 2 additions & 0 deletions docs/CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ Other Changes:
where v_min == v_max. (#3361)
- SliderInt, SliderScalar: Fixed reaching of maximum value with inverted integer min/max ranges, both
with signed and unsigned types. Added reverse Sliders to Demo. (#3432, #3449) [@rokups]
- Text: Bypass unnecessary formatting when using the TextColored()/TextWrapped()/TextDisabled() helpers
with a "%s" format string. (#3466)
- BeginMenuBar: Fixed minor bug where CursorPosMax gets pushed to CursorPos prior to calling BeginMenuBar(),
so e.g. calling the function at the end of a window would often add +ItemSpacing.y to scrolling range.
- TreeNode, CollapsingHeader: Made clicking on arrow toggle toggle the open state on the Mouse Down event
Expand Down
22 changes: 16 additions & 6 deletions imgui_widgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,10 @@ void ImGui::TextColored(const ImVec4& col, const char* fmt, ...)
void ImGui::TextColoredV(const ImVec4& col, const char* fmt, va_list args)
{
PushStyleColor(ImGuiCol_Text, col);
TextV(fmt, args);
if (fmt[0] == '%' && fmt[1] == 's' && fmt[2] == 0)
TextEx(va_arg(args, const char*), NULL, ImGuiTextFlags_NoWidthForLargeClippedText); // Skip formatting
else
TextV(fmt, args);
PopStyleColor();
}

Expand All @@ -288,8 +291,12 @@ void ImGui::TextDisabled(const char* fmt, ...)

void ImGui::TextDisabledV(const char* fmt, va_list args)
{
PushStyleColor(ImGuiCol_Text, GImGui->Style.Colors[ImGuiCol_TextDisabled]);
TextV(fmt, args);
ImGuiContext& g = *GImGui;
PushStyleColor(ImGuiCol_Text, g.Style.Colors[ImGuiCol_TextDisabled]);
if (fmt[0] == '%' && fmt[1] == 's' && fmt[2] == 0)
TextEx(va_arg(args, const char*), NULL, ImGuiTextFlags_NoWidthForLargeClippedText); // Skip formatting
else
TextV(fmt, args);
PopStyleColor();
}

Expand All @@ -303,11 +310,14 @@ void ImGui::TextWrapped(const char* fmt, ...)

void ImGui::TextWrappedV(const char* fmt, va_list args)
{
ImGuiWindow* window = GetCurrentWindow();
bool need_backup = (window->DC.TextWrapPos < 0.0f); // Keep existing wrap position if one is already set
ImGuiContext& g = *GImGui;
bool need_backup = (g.CurrentWindow->DC.TextWrapPos < 0.0f); // Keep existing wrap position if one is already set
if (need_backup)
PushTextWrapPos(0.0f);
TextV(fmt, args);
if (fmt[0] == '%' && fmt[1] == 's' && fmt[2] == 0)
TextEx(va_arg(args, const char*), NULL, ImGuiTextFlags_NoWidthForLargeClippedText); // Skip formatting
else
TextV(fmt, args);
if (need_backup)
PopTextWrapPos();
}
Expand Down

0 comments on commit 645a6e0

Please sign in to comment.