Skip to content

Commit

Permalink
Misc: Most text functions also treat "%.*s" (along with "%s") special…
Browse files Browse the repository at this point in the history
…ly to avoid formatting. (#3466, #6846)
  • Loading branch information
ocornut committed Sep 25, 2023
1 parent f4790f6 commit d486920
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
1 change: 1 addition & 0 deletions docs/CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ Other changes:
- MenuBar: Fixed an issue where layouting an item in the menu-bar would erroneously
register contents size in a way that would affect the scrolling layer.
Was most often noticable when using an horizontal scrollbar. (#6789)
- Misc: Most text functions also treat "%.*s" (along with "%s") specially to avoid formatting. (#3466, #6846)
- IO: Setting io.WantSetMousePos ignores incoming MousePos events. (#6837, #228) [@bertaye]
- ImDrawList: Added AddEllipse(), AddEllipseFilled(), PathEllipticalArcTo(). (#2743) [@Doohl]
- ImVector: Added find_index() helper.
Expand Down
21 changes: 8 additions & 13 deletions imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1918,21 +1918,9 @@ int ImFormatStringV(char* buf, size_t buf_size, const char* fmt, va_list args)

void ImFormatStringToTempBuffer(const char** out_buf, const char** out_buf_end, const char* fmt, ...)
{
ImGuiContext& g = *GImGui;
va_list args;
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);
*out_buf = g.TempBuffer.Data;
if (out_buf_end) { *out_buf_end = g.TempBuffer.Data + buf_len; }
}
ImFormatStringToTempBufferV(out_buf, out_buf_end, fmt, args);
va_end(args);
}

Expand All @@ -1945,6 +1933,13 @@ void ImFormatStringToTempBufferV(const char** out_buf, const char** out_buf_end,
*out_buf = buf;
if (out_buf_end) { *out_buf_end = buf + strlen(buf); }
}
else if (fmt[0] == '%' && fmt[1] == '.' && fmt[2] == '*' && fmt[3] == 's' && fmt[4] == 0)
{
int buf_len = va_arg(args, int); // Skip formatting when using "%.*s"
const char* buf = va_arg(args, const char*);
*out_buf = buf;
*out_buf_end = buf + buf_len; // Disallow not passing 'out_buf_end' here. User is expected to use it.
}
else
{
int buf_len = ImFormatStringV(g.TempBuffer.Data, g.TempBuffer.Size, fmt, args);
Expand Down
2 changes: 1 addition & 1 deletion imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
// Library Version
// (Integer encoded as XYYZZ for use in #if preprocessor conditionals, e.g. '#if IMGUI_VERSION_NUM >= 12345')
#define IMGUI_VERSION "1.90 WIP"
#define IMGUI_VERSION_NUM 18992
#define IMGUI_VERSION_NUM 18993
#define IMGUI_HAS_TABLE

/*
Expand Down

0 comments on commit d486920

Please sign in to comment.