Преглед изворни кода

InputTextMultiline: fixed a crash when using ImGuiInputTextFlags_WordWrap and resizing the parent window while keeping the multi-line field active. (#9007, #3237)

ocornut пре 3 месеци
родитељ
комит
2a5e9a15e4
2 измењених фајлова са 10 додато и 1 уклоњено
  1. 4 0
      docs/CHANGELOG.txt
  2. 6 1
      imgui_widgets.cpp

+ 4 - 0
docs/CHANGELOG.txt

@@ -47,6 +47,10 @@ Other Changes:
   result in temporarily incorrect state, which would lead to bugs to side effects
   in various locations, e.g. GetContentRegionAvail() calls or using clipper. (#9005)
   EndTable() was mistakenly restoring a wrong current table.
+- InputTextMultiline: fixed a crash when using ImGuiInputTextFlags_WordWrap and
+  resizing the parent window while keeping the multi-line field active (which is
+  most typically achieved when resizing programmatically or via a docking layout
+  reacting to a platform window resize). (#3237, #9007) [@anton-kl, @ocornut]
 
 
 -----------------------------------------------------------------------

+ 6 - 1
imgui_widgets.cpp

@@ -5401,7 +5401,12 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
     line_index->Offsets.resize(0);
     int line_count = 1;
     if (is_multiline)
-        line_count = InputTextLineIndexBuild(flags, line_index, buf_display, buf_display_end, wrap_width, (render_cursor && state && state->CursorFollow) ? INT_MAX : line_visible_n1 + 1, buf_display_end ? NULL : &buf_display_end);
+    {
+        // If scrolling is expected to change build full index.
+        // FIXME-OPT: Could append to index when new value of line_visible_n1 becomes bigger, see second call to CalcClipRectVisibleItemsY() below.
+        bool will_scroll_y = state && ((state->CursorFollow && render_cursor) || (state->CursorCenterY && (render_cursor || render_selection)));
+        line_count = InputTextLineIndexBuild(flags, line_index, buf_display, buf_display_end, wrap_width, will_scroll_y ? INT_MAX : line_visible_n1 + 1, buf_display_end ? NULL : &buf_display_end);
+    }
     line_index->EndOffset = (int)(buf_display_end - buf_display);
     line_visible_n1 = ImMin(line_visible_n1, line_count);