2
0
Эх сурвалжийг харах

InputText: allow passing an empty string with buf_size==0. (#8907)

ocornut 2 долоо хоног өмнө
parent
commit
55cbc66508

+ 5 - 1
docs/CHANGELOG.txt

@@ -51,7 +51,11 @@ Other Changes:
   disable the assumption that 1 clipper item == 1 table row, which breaks when
   disable the assumption that 1 clipper item == 1 table row, which breaks when
   e.g. using clipper with ItemsHeight=1 in order to clip in pixel units. (#8886)
   e.g. using clipper with ItemsHeight=1 in order to clip in pixel units. (#8886)
 - Fixed Bullet() fixed tesselation amount which looked out of place in very large sizes.
 - Fixed Bullet() fixed tesselation amount which looked out of place in very large sizes.
-- DrawList: Fixed CloneOutput() unnecessarily taking a copy of the ImDrawListSharedData
+- InputText: allow passing an empty string with buf_size==0. (#8907)
+  In theory the buffer size should always account for a zero-terminator, but idioms
+  such as using InputTextMultiline() with ImGuiInputTextFlags_ReadOnly to display
+  a text blob are facilitated by allowing this.
+- DrawList: fixed CloneOutput() unnecessarily taking a copy of the ImDrawListSharedData
   pointer, which could to issue when deleting the cloned list. (#8894, #1860)
   pointer, which could to issue when deleting the cloned list. (#8894, #1860)
 - Debug Tools: ID Stack Tool: fixed using fixed-size buffers preventing long identifiers
 - Debug Tools: ID Stack Tool: fixed using fixed-size buffers preventing long identifiers
   from being displayed in the tool. (#8905, #4631)
   from being displayed in the tool. (#8905, #4631)

+ 1 - 1
imgui_widgets.cpp

@@ -4653,7 +4653,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
         // Take a copy of the initial buffer value.
         // Take a copy of the initial buffer value.
         // From the moment we focused we are normally ignoring the content of 'buf' (unless we are in read-only mode)
         // From the moment we focused we are normally ignoring the content of 'buf' (unless we are in read-only mode)
         const int buf_len = (int)ImStrlen(buf);
         const int buf_len = (int)ImStrlen(buf);
-        IM_ASSERT(buf_len + 1 <= buf_size && "Is your input buffer properly zero-terminated?");
+        IM_ASSERT(((buf_len + 1 <= buf_size) || (buf_len == 0 && buf_size == 0)) && "Is your input buffer properly zero-terminated?");
         state->TextToRevertTo.resize(buf_len + 1);    // UTF-8. we use +1 to make sure that .Data is always pointing to at least an empty string.
         state->TextToRevertTo.resize(buf_len + 1);    // UTF-8. we use +1 to make sure that .Data is always pointing to at least an empty string.
         memcpy(state->TextToRevertTo.Data, buf, buf_len + 1);
         memcpy(state->TextToRevertTo.Data, buf, buf_len + 1);