ImGuiTextBuffer: Added append() function (unformatted).

docking
omar 6 years ago
parent 259f3c78a2
commit 00ffdb9fa9

@ -37,6 +37,7 @@ Other Changes:
- Added .editorconfig file for text editors to standardize using spaces. (#2038) [@kudaba] - 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" - 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] 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: 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] - 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 - Examples: Win32: Using GetForegroundWindow()+IsChild() instead of GetActiveWindow() to be compatible with windows created

@ -2097,6 +2097,32 @@ bool ImGuiTextFilter::PassFilter(const char* text, const char* text_end) const
char ImGuiTextBuffer::EmptyString[1] = { 0 }; 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 // Helper: Text buffer for logging/accumulating text
void ImGuiTextBuffer::appendfv(const char* fmt, va_list args) void ImGuiTextBuffer::appendfv(const char* fmt, va_list args)
{ {
@ -2115,8 +2141,8 @@ void ImGuiTextBuffer::appendfv(const char* fmt, va_list args)
const int needed_sz = write_off + len; const int needed_sz = write_off + len;
if (write_off + len >= Buf.Capacity) if (write_off + len >= Buf.Capacity)
{ {
int double_capacity = Buf.Capacity * 2; int new_capacity = Buf.Capacity * 2;
Buf.reserve(needed_sz > double_capacity ? needed_sz : double_capacity); Buf.reserve(needed_sz > new_capacity ? needed_sz : new_capacity);
} }
Buf.resize(needed_sz); Buf.resize(needed_sz);
@ -2124,14 +2150,6 @@ void ImGuiTextBuffer::appendfv(const char* fmt, va_list args)
va_end(args_copy); 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 // [SECTION] ImGuiListClipper
// This is currently not as flexible/powerful as it should be, needs some rework (see TODO) // This is currently not as flexible/powerful as it should be, needs some rework (see TODO)

@ -1586,6 +1586,7 @@ struct ImGuiTextBuffer
void clear() { Buf.clear(); } void clear() { Buf.clear(); }
void reserve(int capacity) { Buf.reserve(capacity); } void reserve(int capacity) { Buf.reserve(capacity); }
const char* c_str() const { return Buf.Data ? Buf.Data : EmptyString; } 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 appendf(const char* fmt, ...) IM_FMTARGS(2);
IMGUI_API void appendfv(const char* fmt, va_list args) IM_FMTLIST(2); IMGUI_API void appendfv(const char* fmt, va_list args) IM_FMTLIST(2);
}; };

Loading…
Cancel
Save