Helper: Text buffer for logging/accumulating text
| 2098 | |
| 2099 | // Helper: Text buffer for logging/accumulating text |
| 2100 | void ImGuiTextBuffer::appendfv(const char* fmt, va_list args) |
| 2101 | { |
| 2102 | va_list args_copy; |
| 2103 | va_copy(args_copy, args); |
| 2104 | |
| 2105 | int len = ImFormatStringV(NULL, 0, fmt, args); // FIXME-OPT: could do a first pass write attempt, likely successful on first pass. |
| 2106 | if (len <= 0) |
| 2107 | { |
| 2108 | va_end(args_copy); |
| 2109 | return; |
| 2110 | } |
| 2111 | |
| 2112 | // Add zero-terminator the first time |
| 2113 | const int write_off = (Buf.Size != 0) ? Buf.Size : 1; |
| 2114 | const int needed_sz = write_off + len; |
| 2115 | if (write_off + len >= Buf.Capacity) |
| 2116 | { |
| 2117 | int new_capacity = Buf.Capacity * 2; |
| 2118 | Buf.reserve(needed_sz > new_capacity ? needed_sz : new_capacity); |
| 2119 | } |
| 2120 | |
| 2121 | Buf.resize(needed_sz); |
| 2122 | ImFormatStringV(&Buf[write_off - 1], (size_t)len + 1, fmt, args_copy); |
| 2123 | va_end(args_copy); |
| 2124 | } |
| 2125 | |
| 2126 | //----------------------------------------------------------------------------- |
| 2127 | // [SECTION] ImGuiListClipper |
no test coverage detected