mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-07 13:35:49 +02: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:
30
imgui.cpp
30
imgui.cpp
@ -1805,18 +1805,36 @@ void ImFormatStringToTempBuffer(const char** out_buf, const char** out_buf_end,
|
||||
ImGuiContext& g = *GImGui;
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
int buf_len = ImFormatStringV(g.TempBuffer.Data, g.TempBuffer.Size, fmt, args);
|
||||
*out_buf = g.TempBuffer.Data;
|
||||
if (out_buf_end) { *out_buf_end = g.TempBuffer.Data + buf_len; }
|
||||
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);
|
||||
*out_buf = g.TempBuffer.Data;
|
||||
if (out_buf_end) { *out_buf_end = g.TempBuffer.Data + buf_len; }
|
||||
}
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void ImFormatStringToTempBufferV(const char** out_buf, const char** out_buf_end, const char* fmt, va_list args)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
int buf_len = ImFormatStringV(g.TempBuffer.Data, g.TempBuffer.Size, fmt, args);
|
||||
*out_buf = g.TempBuffer.Data;
|
||||
if (out_buf_end) { *out_buf_end = g.TempBuffer.Data + buf_len; }
|
||||
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);
|
||||
*out_buf = g.TempBuffer.Data;
|
||||
if (out_buf_end) { *out_buf_end = g.TempBuffer.Data + buf_len; }
|
||||
}
|
||||
}
|
||||
|
||||
// CRC32 needs a 1KB lookup table (not cache friendly)
|
||||
|
Reference in New Issue
Block a user