mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-22 11:57:00 +00:00
Internals: move "%s" skip-formatting logic to ImFormatStringToTempBuffer() function, meaning Text() and all the *V() functions can also benefit from it. (#3466)
Amend645a6e0
and23a785a
.
This commit is contained in:
parent
d73e3285de
commit
27f2dd56d6
@ -54,6 +54,7 @@ All changes:
|
|||||||
- PlotHistogram, PlotLines: Passing negative sizes honor alignment like other widgets.
|
- PlotHistogram, PlotLines: Passing negative sizes honor alignment like other widgets.
|
||||||
- ImDrawList: Added missing early-out in AddPolyline() and AddConvexPolyFilled() when
|
- ImDrawList: Added missing early-out in AddPolyline() and AddConvexPolyFilled() when
|
||||||
color alpha is zero.
|
color alpha is zero.
|
||||||
|
- Misc: Most text functions treat "%s" as a shortcut to no-formatting. (#3466)
|
||||||
- Misc: Tolerate zero delta-time under Emscripten as backends are imprecise in their
|
- Misc: Tolerate zero delta-time under Emscripten as backends are imprecise in their
|
||||||
values for io.DeltaTime, and browser features such as "privacy.resistFingerprinting=true"
|
values for io.DeltaTime, and browser features such as "privacy.resistFingerprinting=true"
|
||||||
can exacerbate that. (#6114, #3644)
|
can exacerbate that. (#6114, #3644)
|
||||||
|
18
imgui.cpp
18
imgui.cpp
@ -1805,18 +1805,36 @@ void ImFormatStringToTempBuffer(const char** out_buf, const char** out_buf_end,
|
|||||||
ImGuiContext& g = *GImGui;
|
ImGuiContext& g = *GImGui;
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
|
if (fmt[0] == '%' && fmt[1] == 's' && fmt[2] == 0)
|
||||||
|
{
|
||||||
|
const char* buf = va_arg(args, const char*); // Skip formatting when using "%s"
|
||||||
|
*out_buf = buf;
|
||||||
|
if (out_buf_end) { *out_buf_end = buf + strlen(buf); }
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
int buf_len = ImFormatStringV(g.TempBuffer.Data, g.TempBuffer.Size, fmt, args);
|
int buf_len = ImFormatStringV(g.TempBuffer.Data, g.TempBuffer.Size, fmt, args);
|
||||||
*out_buf = g.TempBuffer.Data;
|
*out_buf = g.TempBuffer.Data;
|
||||||
if (out_buf_end) { *out_buf_end = g.TempBuffer.Data + buf_len; }
|
if (out_buf_end) { *out_buf_end = g.TempBuffer.Data + buf_len; }
|
||||||
|
}
|
||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImFormatStringToTempBufferV(const char** out_buf, const char** out_buf_end, const char* fmt, va_list args)
|
void ImFormatStringToTempBufferV(const char** out_buf, const char** out_buf_end, const char* fmt, va_list args)
|
||||||
{
|
{
|
||||||
ImGuiContext& g = *GImGui;
|
ImGuiContext& g = *GImGui;
|
||||||
|
if (fmt[0] == '%' && fmt[1] == 's' && fmt[2] == 0)
|
||||||
|
{
|
||||||
|
const char* buf = va_arg(args, const char*); // Skip formatting when using "%s"
|
||||||
|
*out_buf = buf;
|
||||||
|
if (out_buf_end) { *out_buf_end = buf + strlen(buf); }
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
int buf_len = ImFormatStringV(g.TempBuffer.Data, g.TempBuffer.Size, fmt, args);
|
int buf_len = ImFormatStringV(g.TempBuffer.Data, g.TempBuffer.Size, fmt, args);
|
||||||
*out_buf = g.TempBuffer.Data;
|
*out_buf = g.TempBuffer.Data;
|
||||||
if (out_buf_end) { *out_buf_end = g.TempBuffer.Data + buf_len; }
|
if (out_buf_end) { *out_buf_end = g.TempBuffer.Data + buf_len; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// CRC32 needs a 1KB lookup table (not cache friendly)
|
// CRC32 needs a 1KB lookup table (not cache friendly)
|
||||||
|
@ -274,7 +274,6 @@ void ImGui::TextV(const char* fmt, va_list args)
|
|||||||
if (window->SkipItems)
|
if (window->SkipItems)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// FIXME-OPT: Handle the %s shortcut?
|
|
||||||
const char* text, *text_end;
|
const char* text, *text_end;
|
||||||
ImFormatStringToTempBufferV(&text, &text_end, fmt, args);
|
ImFormatStringToTempBufferV(&text, &text_end, fmt, args);
|
||||||
TextEx(text, text_end, ImGuiTextFlags_NoWidthForLargeClippedText);
|
TextEx(text, text_end, ImGuiTextFlags_NoWidthForLargeClippedText);
|
||||||
@ -291,9 +290,6 @@ void ImGui::TextColored(const ImVec4& col, const char* fmt, ...)
|
|||||||
void ImGui::TextColoredV(const ImVec4& col, const char* fmt, va_list args)
|
void ImGui::TextColoredV(const ImVec4& col, const char* fmt, va_list args)
|
||||||
{
|
{
|
||||||
PushStyleColor(ImGuiCol_Text, col);
|
PushStyleColor(ImGuiCol_Text, col);
|
||||||
if (fmt[0] == '%' && fmt[1] == 's' && fmt[2] == 0)
|
|
||||||
TextEx(va_arg(args, const char*), NULL, ImGuiTextFlags_NoWidthForLargeClippedText); // Skip formatting
|
|
||||||
else
|
|
||||||
TextV(fmt, args);
|
TextV(fmt, args);
|
||||||
PopStyleColor();
|
PopStyleColor();
|
||||||
}
|
}
|
||||||
@ -310,9 +306,6 @@ void ImGui::TextDisabledV(const char* fmt, va_list args)
|
|||||||
{
|
{
|
||||||
ImGuiContext& g = *GImGui;
|
ImGuiContext& g = *GImGui;
|
||||||
PushStyleColor(ImGuiCol_Text, g.Style.Colors[ImGuiCol_TextDisabled]);
|
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);
|
TextV(fmt, args);
|
||||||
PopStyleColor();
|
PopStyleColor();
|
||||||
}
|
}
|
||||||
@ -328,12 +321,9 @@ void ImGui::TextWrapped(const char* fmt, ...)
|
|||||||
void ImGui::TextWrappedV(const char* fmt, va_list args)
|
void ImGui::TextWrappedV(const char* fmt, va_list args)
|
||||||
{
|
{
|
||||||
ImGuiContext& g = *GImGui;
|
ImGuiContext& g = *GImGui;
|
||||||
bool need_backup = (g.CurrentWindow->DC.TextWrapPos < 0.0f); // Keep existing wrap position if one is already set
|
const bool need_backup = (g.CurrentWindow->DC.TextWrapPos < 0.0f); // Keep existing wrap position if one is already set
|
||||||
if (need_backup)
|
if (need_backup)
|
||||||
PushTextWrapPos(0.0f);
|
PushTextWrapPos(0.0f);
|
||||||
if (fmt[0] == '%' && fmt[1] == 's' && fmt[2] == 0)
|
|
||||||
TextEx(va_arg(args, const char*), NULL, ImGuiTextFlags_NoWidthForLargeClippedText); // Skip formatting
|
|
||||||
else
|
|
||||||
TextV(fmt, args);
|
TextV(fmt, args);
|
||||||
if (need_backup)
|
if (need_backup)
|
||||||
PopTextWrapPos();
|
PopTextWrapPos();
|
||||||
|
Loading…
Reference in New Issue
Block a user