ImGuiTextBuffer: Added append() function (unformatted).
diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt
index 6b3f877..4414607 100644
--- a/docs/CHANGELOG.txt
+++ b/docs/CHANGELOG.txt
@@ -37,6 +37,7 @@
- Added .editorconfig file for text editors to standardize using spaces. (#2038) [@kudaba]
- ImDrawList: Fixed AddCircle(), AddCircleFilled() angle step being off, which was visible when drawing a "circle"
with a small number of segments (e.g. an hexagon). (#2287) [@baktery]
+- ImGuiTextBuffer: Added append() function (unformatted).
- ImFontAtlas: Added 0x2000-0x206F general punctuation range to default ChineseFull/ChineseSimplifiedCommon ranges. (#2093)
- ImFontAtlas: FreeType: Added support for imgui allocators + custom FreeType only SetAllocatorFunctions. (#2285) [@Vuhdo]
- Examples: Win32: Using GetForegroundWindow()+IsChild() instead of GetActiveWindow() to be compatible with windows created
diff --git a/imgui.cpp b/imgui.cpp
index abd29ee..d00f46d 100644
--- a/imgui.cpp
+++ b/imgui.cpp
@@ -2097,6 +2097,32 @@
char ImGuiTextBuffer::EmptyString[1] = { 0 };
+void ImGuiTextBuffer::append(const char* str, const char* str_end)
+{
+ int len = str_end ? (int)(str_end - str) : (int)strlen(str);
+
+ // Add zero-terminator the first time
+ const int write_off = (Buf.Size != 0) ? Buf.Size : 1;
+ const int needed_sz = write_off + len;
+ if (write_off + len >= Buf.Capacity)
+ {
+ int new_capacity = Buf.Capacity * 2;
+ Buf.reserve(needed_sz > new_capacity ? needed_sz : new_capacity);
+ }
+
+ Buf.resize(needed_sz);
+ memcpy(&Buf[write_off - 1], str, (size_t)len);
+ Buf[write_off - 1 + len] = 0;
+}
+
+void ImGuiTextBuffer::appendf(const char* fmt, ...)
+{
+ va_list args;
+ va_start(args, fmt);
+ appendfv(fmt, args);
+ va_end(args);
+}
+
// Helper: Text buffer for logging/accumulating text
void ImGuiTextBuffer::appendfv(const char* fmt, va_list args)
{
@@ -2115,8 +2141,8 @@
const int needed_sz = write_off + len;
if (write_off + len >= Buf.Capacity)
{
- int double_capacity = Buf.Capacity * 2;
- Buf.reserve(needed_sz > double_capacity ? needed_sz : double_capacity);
+ int new_capacity = Buf.Capacity * 2;
+ Buf.reserve(needed_sz > new_capacity ? needed_sz : new_capacity);
}
Buf.resize(needed_sz);
@@ -2124,14 +2150,6 @@
va_end(args_copy);
}
-void ImGuiTextBuffer::appendf(const char* fmt, ...)
-{
- va_list args;
- va_start(args, fmt);
- appendfv(fmt, args);
- va_end(args);
-}
-
//-----------------------------------------------------------------------------
// [SECTION] ImGuiListClipper
// This is currently not as flexible/powerful as it should be, needs some rework (see TODO)
diff --git a/imgui.h b/imgui.h
index 81a6260..2d0c646 100644
--- a/imgui.h
+++ b/imgui.h
@@ -1586,6 +1586,7 @@
void clear() { Buf.clear(); }
void reserve(int capacity) { Buf.reserve(capacity); }
const char* c_str() const { return Buf.Data ? Buf.Data : EmptyString; }
+ IMGUI_API void append(const char* str, const char* str_end = NULL);
IMGUI_API void appendf(const char* fmt, ...) IM_FMTARGS(2);
IMGUI_API void appendfv(const char* fmt, va_list args) IM_FMTLIST(2);
};